Many of you will also likely agree that !SetVariable is, quite frankly, ugly in many (if not most) cases.
Take a look at the following code.
Code: Select all
[Variables]
size=10
[SomeMeter]
Meter=STRING
...
FontSize=#size#
DynamicVariables=1
MouseOverAction=!SetVariable "size" "12"
MouseLeaveAction=!SetVariable "size" "10"
Code: Select all
[SomeMeter]
Meter=STRING
...
FontSize=10
MouseOverAction=!SetOption "SomeMeter" "FontSize" "12"
MouseLeaveAction=!SetOption "SomeMeter" "FontSize" "10"
What is !SetOption?
In essence, it allows you to set an option (FontSize, Text, ImageName, ...) of a meter or measure on-the-fly.
!SetOption cannot change..Manual wrote:!SetOption [Meter] [Option] [Value] (Config)
!SetOption [Measure] [Option] [Value] (Config)
!SetOptionGroup [Group] [Option] [Value] (Config)
- anything in [Rainmeter]
- anything in [Variables] (!SetVariable can though)
- anything in [Metadata] (but who cares)
- anything in a [MeterStyle] (unless it is also a meter or measure)
- anything in a Plugin measure
- the "type" of a meter or measure. (ie: Meter=String)
- the MeasureName setting of a meter
- the X or Y of a meter (use !MoveMeter)
Always prefer dedicated bangs (e.g. !DisableMeasure, !HideMeter, etc.) to changing the option (e.g. Disabled=1, Hidden=1) with !SetOption.
Examples:
Code: Select all
!SetOption "StringMeter" "Text" "Hello, world!"
!SetOption "CalcMeasure" "Formula" "40+2"
!SetOption "LineMeter" "LineWidth" "3"
!SetOption "ImageMeter" "ImageName" "image.png"
!SetOption "TimeMeasure" "Format" "%Y"
!SetOptionGroup "SomeGroup" "SolidColor" "255,255,255,255"
- Under-the-hood !SetOption force-enables DynamicVariables for the meter/measure/group in question for one update cycle after which DynamicVariables reverts to the original setting.
Due to this design, Text and FontSize will be updated in the example below each time you hover over the meter.Code: Select all
[SomeMeter] Meter=STRING ... FontSize=#size# Text="Hello!" MouseOverAction=!Execute [!SetVariable "size" "20"][!SetOption "SomeMeter" "Text" "Get off me!"]
- The #CURRENTSECTION# variable is handy, especially when used with styles.
Code: Select all
[SomeStyle] LeftMouseUpAction=!SetOption "#CURRENTSECTION#" "SolidColor" "255,255,255" [SomeMeter] Meter=STRING MeterStyle=SomeStyle
- When using a variable as the value, the actual value of the variable is assigned. Consider the following case:
FontSize is set to the actual value of #bigSize# (i.e. 15) when the cursor is over [SomeMeter] and back to the actual value of #normSize# (i.e. 10) when the cursor leaves.
Code: Select all
[Variables] normSize=10 bigSize=15 ... [SomeMeter] Meter=STRING FontSize=#normSize# MouseOverAction=!SetOption "SomeMeter" "FontSize" "#bigSize#" MouseLeaveAction=!SetOption "SomeMeter" "FontSize" "#normSize#"
This won't matter in most cases. If you use both !SetVariable and !SetOption on a given option, the following won't work:When you hover over the meter, FontSize is set to the actual value of #bigSize#. Then, when you click on the meter, you change #bigSize# to 25. This won't have any effect on SomeMeter (unless you leave and enter) as FontSize is not set to #bigSize# but 25.Code: Select all
[SomeMeter] Meter=STRING FontSize=#normSize# MouseOverAction=!SetOption "SomeMeter" "FontSize" "#bigSize#" LeftMouseUpAction=!SetVariable "bigSize" "25" DynamicVariables=1
To get around this, we've allowed escaping variables and measures ([*EscapedMeasure*] and #*EscapedVariable*#).The chunk above, on the other hand, will set FontSize to the literal #bigSize# (as compared to the value of it) and allow the LeftMouseUpAction to work (without leaving and re-entering the meter).Code: Select all
MouseOverAction=!SetOption "SomeMeter" "FontSize" "#*bigSize*#" LeftMouseUpAction=!SetVariable "bigSize" "25"
Of course, the easier way out is to avoid using a combination of !SetVariable/!SetOption on a given option. - Using !SetOption with an empty (i.e. "") value results in the default value for the option. The following, for example, results in FontColor being set to 0,0,0,255 (which is the default value for FontColor):
Code: Select all
!SetOption "SomeMeter" "FontColor" ""