Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Metadata]
Name=ToggleCheckBox
Author=JSMorley
Information=Demonstration of toggling a variable between 0 and 1, and using Unicode characters in a skin.||Note that the skin .ini file must be encoded as UTF-16 Little Endian / Unicode.
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Version=Jan 30, 2015
[Variables]
State=0
UnChecked=☐
Checked=☑
[MeasureState]
Measure=Calc
Formula=#State#
DynamicVariables=1
IfEqualValue=0
IfEqualAction=[!SetOption MeterCheckBox Text "#UnChecked#"][!SetOption MeterState Text "Box Clear"][!SetOption MeterState FontColor "200,200,200,255"][!UpdateMeter *][!Redraw]
IfAboveValue=0
IfAboveAction=[!SetOption MeterCheckBox Text "#Checked#"][!SetOption MeterState Text "Box Checked"][!SetOption MeterState FontColor "215,252,217,255"][!UpdateMeter *][!Redraw]
[MeterToggle]
Meter=String
FontSize=50
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Toggle
[MeterCheckBox]
Meter=String
X=R
FontSize=43
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[MeasureState]
DynamicVariables=1
LeftMouseUpAction=[Play "#@#Sounds\Click.wav"][!WriteKeyValue Variables State "(1-#State#)"][!SetVariable State "(1-#State#)"][!UpdateMeasure MeasureState]
[MeterState]
Meter=String
X=([MeterCheckBox:X]+[MeterCheckBox:W])
Y=R
FontSize=20
FontColor=255,255,255,255
SolidColor=0,0,0,1
Padding=5,5,5,5
StringAlign=Right
AntiAlias=1
DynamicVariables=1
[!SetVariable State "(1-#State#)"]
What that does is subtract the current value of the variable #State# from 1. If #State# is "0", then "1-0" is "1". So the variable value will change to "1". If #State# is "1", then "1-1" is "0", so the variable value will change to "0". It simply toggles between "0" and "1", or in a sense, "off" and "on".
We can then check the value of the #State# variable in a Calc measure, and using IfAction or IfConditon options, take any actions we want based on the current "state" of the selection.
We also use !WriteKeyValue at the same time, so the state is "saved" with the skin and will be remembered.
Note that to use those Unicode checkbox "glyphs", we need to encode the skin .ini file as Unicode, which is:
Unicode (Windows Notepad.exe)
UCS-2 Little Endian (Notepad++)
UTF-16 LE (Sublime Text)
Encode the skin and save it before you paste in any Unicode characters.