You guys give up too easily!
Just kidding.
The example below shows how you can create a scrollbar with some simple math. Of course it does have some pitfalls (which I will explain later).
Below is an updated version of my test skin (originally located
here). It uses a little Lua to help catch some "out of bounds" conditions. Also, I am particularly proud the scroll bar's height because it is not a fixed, meaning it grows/shrinks depending on the amount of items in your list (just like a real scrollbar).
Here is the .ini file:
Code: Select all
[Rainmeter]
MouseScrollUpAction=[!CommandMeasure ScrollbarScript UpdateCurrentPos(-1)][!CommandMeasure mPath "IndexUp"][!UpdateMeasure mPath]
MouseScrollDownAction=[!CommandMeasure ScrollbarScript UpdateCurrentPos(1)][!CommandMeasure mPath "IndexDown"][!UpdateMeasure mPath]
[Variables]
IconSize=Large
Count=8
;----------------------------------------------------
; Styles
;----------------------------------------------------
[TextStyle]
FontColor=255,255,255,255
AntiAlias=1
[TextHighlight]
FontColor=150,150,255,255
[IconStyle]
X=5
Y=r
AntiAlias=1
[HighlightStyle]
SolidColor=0,0,0,1
X=5
Y=5R
W=365
H=([Index1Icon:H] > [Index1Info:H] ? [Index1Icon:H] : [Index1Info:H])
DynamicVariables=1
MouseOverAction=[!SetOption #CURRENTSECTION# SolidColor "50,50,255,150"][!UpdateMeter #CURRENTSECTION#][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# SolidColor ""][!UpdateMeter #CURRENTSECTION#][!Redraw]
[InfoStyle]
X=5R
Y=r
Text="%1 #CRLF#%2 #CRLF#%3 "
AutoScale=1
AntiAlias=1
;----------------------------------------------------
; Measures
;----------------------------------------------------
[mPath]
Measure=Plugin
Plugin=FileView
Path="C:\"
ShowDotDot=0
Count=#Count#
FinishAction=[!UpdateMeasureGroup Children][!UpdateMeasureGroup Scrollbar][!UpdateMeter *][!Redraw]
[mFolderCount]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FolderCount
Group=Children
[mFileCount]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileCount
Group=Children
[mFolderSize]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FolderSize
Group=Children
;----------------------------------------------------
; Index 1
[mIndex1Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=1
Group=Children
[mIndex1Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=1
Group=Children
[mIndex1Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=1
Group=Children
[mIndex1Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=1
Group=Children
;----------------------------------------------------
; Index 2
[mIndex2Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=2
Group=Children
[mIndex2Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=2
Group=Children
[mIndex2Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=2
Group=Children
[mIndex2Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=2
Group=Children
;----------------------------------------------------
; Index 3
[mIndex3Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=3
Group=Children
[mIndex3Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=3
Group=Children
[mIndex3Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=3
Group=Children
[mIndex3Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=3
Group=Children
;----------------------------------------------------
; Index 4
[mIndex4Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=4
Group=Children
[mIndex4Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=4
Group=Children
[mIndex4Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=4
Group=Children
[mIndex4Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=4
Group=Children
;----------------------------------------------------
; Index 5
[mIndex5Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=5
Group=Children
[mIndex5Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=5
Group=Children
[mIndex5Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=5
Group=Children
[mIndex5Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=5
Group=Children
;----------------------------------------------------
; Index 6
[mIndex6Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=6
Group=Children
[mIndex6Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=6
Group=Children
[mIndex6Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=6
Group=Children
[mIndex6Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=6
Group=Children
;----------------------------------------------------
; Index 7
[mIndex7Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=7
Group=Children
[mIndex7Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=7
Group=Children
[mIndex7Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=7
Group=Children
[mIndex7Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=7
Group=Children
;----------------------------------------------------
; Index 8
[mIndex8Name]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileName
Index=8
Group=Children
[mIndex8Size]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileSize
Index=8
Group=Children
[mIndex8Date]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=FileDate
Index=8
Group=Children
[mIndex8Icon]
Measure=Plugin
Plugin=FileView
Path=[mPath]
Type=Icon
IconSize=#IconSize#
Index=8
Group=Children
;----------------------------------------------------
; Meters
;----------------------------------------------------
[Background]
Meter=Image
SolidColor=0,0,0,200
W=400
H=500
[PathTitle]
Meter=String
MeterStyle=TextStyle
Text=Path:
[Path]
Meter=String
MeasureName=mPath
MeterStyle=TextStyle | TextHighlight
Text="%1 "
X=R
[FolderCountTitle]
Meter=String
MeterStyle=TextStyle
X=0
Y=R
Text=Folders:
[FolderCount]
Meter=String
MeasureName=mFolderCount
MeterStyle=TextStyle | TextHighlight
X=R
Y=r
[FileCountTitle]
Meter=String
MeterStyle=TextStyle
X=10R
Y=r
Text=Files:
[FileCount]
Meter=String
MeasureName=mFileCount
MeterStyle=TextStyle | TextHighlight
X=R
Y=r
[FolderSizeTitle]
Meter=String
MeterStyle=TextStyle
X=10R
Y=r
Text=Size:
[FolderSize]
Meter=String
MeasureName=mFolderSize
MeterStyle=TextStyle | TextHighlight
X=R
Y=r
AutoScale=1
[Index1]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex1Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index1Icon]
Meter=Image
MeasureName=mIndex1Icon
MeterStyle=IconStyle
[Index1Info]
Meter=String
MeasureName=mIndex1Name
MeasureName2=mIndex1Size
MeasureName3=mIndex1Date
MeterStyle=TextStyle | InfoStyle
[Index2]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex2Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index2Icon]
Meter=Image
MeasureName=mIndex2Icon
MeterStyle=IconStyle
[Index2Info]
Meter=String
MeasureName=mIndex2Name
MeasureName2=mIndex2Size
MeasureName3=mIndex2Date
MeterStyle=TextStyle | InfoStyle
[Index3]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex3Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index3Icon]
Meter=Image
MeasureName=mIndex3Icon
MeterStyle=IconStyle
[Index3Info]
Meter=String
MeasureName=mIndex3Name
MeasureName2=mIndex3Size
MeasureName3=mIndex3Date
MeterStyle=TextStyle | InfoStyle
[Index4]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex4Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index4Icon]
Meter=Image
MeasureName=mIndex4Icon
MeterStyle=IconStyle
[Index4Info]
Meter=String
MeasureName=mIndex4Name
MeasureName2=mIndex4Size
MeasureName3=mIndex4Date
MeterStyle=TextStyle | InfoStyle
[Index5]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex5Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index5Icon]
Meter=Image
MeasureName=mIndex5Icon
MeterStyle=IconStyle
[Index5Info]
Meter=String
MeasureName=mIndex5Name
MeasureName2=mIndex5Size
MeasureName3=mIndex5Date
MeterStyle=TextStyle | InfoStyle
[Index6]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex6Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index6Icon]
Meter=Image
MeasureName=mIndex6Icon
MeterStyle=IconStyle
[Index6Info]
Meter=String
MeasureName=mIndex6Name
MeasureName2=mIndex6Size
MeasureName3=mIndex6Date
MeterStyle=TextStyle | InfoStyle
[Index7]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex7Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index7Icon]
Meter=Image
MeasureName=mIndex7Icon
MeterStyle=IconStyle
[Index7Info]
Meter=String
MeasureName=mIndex7Name
MeasureName2=mIndex7Size
MeasureName3=mIndex7Date
MeterStyle=TextStyle | InfoStyle
[Index8]
Meter=Image
MeterStyle=HighlightStyle
LeftMouseDoubleClickAction=[!CommandMeasure mIndex8Name "FollowPath"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
[Index8Icon]
Meter=Image
MeasureName=mIndex8Icon
MeterStyle=IconStyle
[Index8Info]
Meter=String
MeasureName=mIndex8Name
MeasureName2=mIndex8Size
MeasureName3=mIndex8Date
MeterStyle=TextStyle | InfoStyle
[PreviousFolder]
Meter=String
MeterStyle=TextStyle
FontSize=15
X=5
Y=10R
Text=Previous Folder
LeftMouseDoubleClickAction=[!CommandMeasure mPath "PreviousFolder"][!UpdateMeasure mPath][!CommandMeasure ScrollbarScript ResetPosition()]
MouseOverAction=[!SetOption #CURRENTSECTION# SolidColor "50,50,255,150"][!UpdateMeter #CURRENTSECTION#][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# SolidColor ""][!UpdateMeter #CURRENTSECTION#][!Redraw]
[NumberItems]
Measure=Calc
Formula=mFolderCount + mFileCount
IfBelowValue=#Count#
IfBelowAction=[!HideMeterGroup Scrollbar][!UpdateMeterGroup Scrollbar][!Redraw]
IfAboveValue=#Count#
IfAboveAction=[!ShowMeterGroup Scrollbar][!UpdateMeterGroup Scrollbar][!Redraw]
Group=Scrollbar
[Size]
Measure=Calc
Formula=([Index1:H] * #Count#) - 2
DynamicVariables=1
Group=Scrollbar
[ScrollH]
Measure=Calc
Formula=Size * (#Count# / (NumberItems = 0 ? 1 : NumberItems))
Group=Scrollbar
[ScrollbarScript]
Measure=Script
ScriptFile=Scrollbar.lua
[IndexUp]
Meter=String
SolidColor=168,168,168,200
X=([Index1:X] + [Index1:W])
Y=[Index1:Y]
W=15
H=15
FontFace=Webdings
Text=5
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure ScrollbarScript UpdateCurrentPos(-1)][!CommandMeasure mPath "IndexUp"][!UpdateMeasure mPath]
Group=ScrollBar
[CurrentPos]
Meter=Image
SolidColor=168,168,168
X=r
Y=R
W=15
H=[ScrollH]
DynamicVariables=1
Group=ScrollBar
[IndexDown]
Meter=String
SolidColor=168,168,168,200
X=r
Y=([Index8:Y] + [Index8:H] - 15)
W=15
H=15
FontFace=Webdings
Text=6
LeftMouseUpAction=[!CommandMeasure ScrollbarScript UpdateCurrentPos(1)][!CommandMeasure mPath "IndexDown"][!UpdateMeasure mPath]
DynamicVariables=1
Group=ScrollBar
[PageUp]
Meter=Image
SolidColor=168,168,168,150
X=r
Y=([IndexUp:Y] + [IndexUp:H])
W=15
H=([CurrentPos:Y] - [PageUp:Y])
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure ScrollbarScript UpdateCurrentPos(-#Count#)][!CommandMeasure mPath "PageUp"][!UpdateMeasure mPath]
Group=ScrollBar
[PageDown]
Meter=Image
SolidColor=168,168,168,150
X=r
Y=([CurrentPos:Y] + [CurrentPos:H])
W=15
H=([IndexDown:Y] - [PageDown:Y])
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure ScrollbarScript UpdateCurrentPos(#Count#)][!CommandMeasure mPath "PageDown"][!UpdateMeasure mPath]
Group=ScrollBar
And the .lua file:
Code: Select all
function Initialize()
currentPos = 0
end
function ResetPosition()
currentPos = 0
UpdateCurrentPos(0)
end
function UpdateCurrentPos(amount)
currentPos = currentPos + amount
if currentPos < 0 then
currentPos = 0
end
count = SKIN:GetVariable('Count')
maxItems = SKIN:GetMeasure('NumberItems'):GetValue()
if currentPos ~= 0 and currentPos > (maxItems - count) then
currentPos = maxItems - count
end
size = SKIN:GetMeasure('Size'):GetValue()
SKIN:Bang('!SetOption', 'CurrentPos', 'Y', currentPos * (size / maxItems) ..'R')
end
First, I want to talk a little bit about this scrollbar. The scrollbar consists of 5 meters - 2 String meters that run the IndexUp/Down commands, 1 Image meter that represents the current "position" in the list, and 2 Image meters that represent the PageUp/Down commands (they are the dark grey meters in between the "position" meter and the IndexUp/Down meters.
Second, there are a couple of "helper" measures that calculate the size of the "position" meter and the overall size of the scrollbar scroll area.
Measure
NumberItems just represents the amount of items that are in the list. Note: I placed "ShowDotDot=0" in my parent FileView plugin measure. The reason is because the ".." folder is not counted as a folder. If you are displaying this folder in your list, add 1 to the formula in this measure.
Measure
[Size] represents the overall size of the scrollbar minus the height of the "arrow" String meters. I used a Calc because I did want to manually figure out the height I want since my test skin can change size depending on the size of the icon you want.
Measure
ScrollH determines the height of the position meter. I think the formula is fairly easy to follow. Basically you take the number items you are
displaying in your list divided by the number of items that
are in the list then multiplying by the size of scrollbar. The conditional operator is just assure that there is no divide by 0 error.
Next is the Lua script. The function that does all the work is the
UpdateCurrentPos function. This function makes sure the current position is not "out of bounds", then calculates and updates the
[CurrentPos] meter using relative positioning.
Now, when you click on a meter that runs the IndexUp/Down or PageUp/Down commands, you should update the position of the scrollbar by calling the
UpdateCurrentPos function. Likewise, when you navigate to another folder, you should reset the position of the scrollbar back to the top by calling the
ResetPosition function.
Pretty easy huh!?
There is one problem that I cannot solve at this time. When navigating a list that contains both files and folders, there is no way to tell if you are navigating to a new folder, or just trying to open a file. Since we are resetting the position of the scrollbar when double clicking on an item, the scrollbar resets. If you clicked on a folder, then all is well, but if you clicked on a file, then the scrollbar position does not represent the real position. I have no solution for this at this time.
-Brian