Toggle two colors on a meter with a click.

Tips and Tricks from the Rainmeter Community
User avatar

Toggle two colors on a meter with a click.

February 17th, 2017, 1:54 am
jsmorley
Developer   [15236 posts]

It can be tricky to toggle two colors (say "on" and "off") on a meter with a single left click, as you have to use numeric values as a variable, and a formula to toggle between say "0" and "1". Then it's tricky how you use that numeric value to set a FontColor (for instance).

Just thought I would show one way to do it, that I find pleasing.

SKIN:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureToggleColor]
Measure=Script
ScriptFile=ToggleColor.lua
UpdateDivider=-1

[MeterToToggle]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Hello World
LeftMouseUpAction=[!CommandMeasure MeasureToggleColor "ToggleColor('#CURRENTSECTION#', '255,255,255,255','255,0,0,255')"]


LUA:

Code: Select all

function ToggleColor(meterName,color1,color2)

   myMeter = SKIN:GetMeter(meterName)
   currentColor = myMeter:GetOption('FontColor')
   
   if currentColor == color1 then
      newColor = color2
   else
      newColor = color1
   end
   
   SKIN:Bang('!SetOption', meterName, 'FontColor', newColor)
   SKIN:Bang('!UpdateMeter', '*')
   SKIN:Bang('!Redraw')
   
end


So you just pass the name of the meter (#CURRENTSECTION#) and the two colors you want to toggle between to the Lua ToggleColor() function.

It gets the current value of FontColor from the meter, and tests if it is color1 or color2. It then switches them, and sends a !SetOption bang back to the meter to change it.

Quite simple, and can be used in as many meters in the skin as you need, since it is not specific to any particular meter, or sets of colors. It's all defined in the !CommandMeasure call to the script function.

Nothing says this has to be just FontColor, it would work just as well for any meter option you want to toggle. FontSize, StringStyle, pretty much anything.

ToggleColor_1.0.rmskin
(1.16 KiB) Downloaded 8 times
User avatar

Re: Toggle two colors on a meter with a click.

February 17th, 2017, 10:24 am
ikarus1969
   [192 posts]

just a remark: in the LUA-code i guess instead of

Code: Select all

SKIN:Bang('!UpdateMeter', '*')
you can write

Code: Select all

SKIN:Bang('!UpdateMeter', meterName)
so only the affected meter is updated ;-)
User avatar

Re: Toggle two colors on a meter with a click.

February 18th, 2017, 1:33 pm
jsmorley
Developer   [15236 posts]

ikarus1969 wrote:just a remark: in the LUA-code i guess instead of

Code: Select all

SKIN:Bang('!UpdateMeter', '*')
you can write

Code: Select all

SKIN:Bang('!UpdateMeter', meterName)
so only the affected meter is updated ;-)


Certainly, and the decision to use [!UpdateMeter "MeterName"] or [!UpdateMeterGroup "GroupName"] or [!UpdateMeter "*"] is entirely dependent on the skin. I generally lean toward updating all meters when I take some action that impacts a single meter, since I don't want to have to think about issues with relative positioning and such, but if you have a lot of meters in a skin, it can be marginally more efficient to update just one meter or group of meters.

Return to “Community Tips and Tricks”



Who is online

Users browsing this forum: No registered users and 2 guests