It is currently April 25th, 2024, 3:08 pm

Dynamic Color Battery Bar

Get help with creating, editing & fixing problems with skins
EmDash00
Posts: 2
Joined: December 31st, 2018, 7:41 pm

Dynamic Color Battery Bar

Post by EmDash00 »

I'm trying to perform an edit to UI White so that the battery bar shows colors corresponding to the state. I'm using the below code but the bar simply refuses to change color. Am I doing something wrong?

Code: Select all

[Rainmeter]
Update=1000

[powerColor]
Measure=Calc
Formula=([MeasurePower] = 100 ? 1 : ([MeasurePower] > 49 ? 2 : ([MeasurePower] > 10 ? 3 : 4)))
Substitute=".0":"", "2":"0,255,0,255", "3":"255,255,0,255", "4":"255,0,0,255", "1":"0,0,255,255"
DynamicVariables=1

[Metadata]
Author=DD.921 (Rasylver)
Version=1.3f
Description=[EN]Displays the percentage of the battery / [FR]Affiche le pourcentage de la batterie / [ES]Muestra el porcentaje de la batería
Instructions=/!\ The skin is a modified version of the original skin that is Rasylver

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BATTERY MEASURE

[MeasurePower]
Measure=Plugin
PlugIn=PlugIns\PowerPlugin.dll
PowerState=PERCENT
UpdateDivider=10

----------------------------------
BATTERY METER

[MeterPercent]
Meter=STRING
MeasureName=MeasurePower
X=193
Y=6
StringAlign=RIGHT
FontColor=255,255,255,255
FontSize=12
FontFace=Press Start 2P
AntiAlias=1
Text="%1%"
Percentual=1
AutoScale=1

[MeterPWRLabel]
Meter=STRING
Text="PWR"
X=7
Y=6
FontColor=255,255,255,255
FontSize=12
FontFace=8BIT WONDER
AntiAlias=1

[MeterBar]
MeasureName=MeasurePower
Meter=BAR
X=10
Y=25
W=180
H=5
BarOrientation=HORIZONTAL
BarColor=[powerColor]

[BarLine]
Meter=IMAGE
X=10
Y=30
W=180
H=5
SolidColor=255,255,255,50
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Dynamic Color Battery Bar

Post by balala »

EmDash00 wrote: December 31st, 2018, 7:48 pm Am I doing something wrong?
Yep, you've forgot to add a DynamicVariables=1 option to the [MeterBar] Bar meter. Add it and refresh your skin.
And one more: there is no need to use the [MeasurePower] as a section variable into the Formula option of [powerColor] measure. Replace this option with the following one: Formula=(( MeasurePower = 100 ) ? 1 : (( MeasurePower > 49 ) ? 2 : (( MeasurePower > 10 ) ? 3 : 4))). This also makes useless the DynamicVariables=1 option of the measure. Remove it.
Note that the ".0":"" section of the Substitute option of the same [powerColor] measure is also not needed. Remove it as well: Substitute="2":"0,255,0,255","3":"255,255,0,255","4":"255,0,0,255","1":"0,0,255,255".
EmDash00
Posts: 2
Joined: December 31st, 2018, 7:41 pm

Re: Dynamic Color Battery Bar

Post by EmDash00 »

balala wrote: December 31st, 2018, 8:15 pm Yep, you've forgot to add a DynamicVariables=1 option to the [MeterBar] Bar meter. Add it and refresh your skin.
And one more: there is no need to use the [MeasurePower] as a section variable into the Formula option of [powerColor] measure. Replace this option with the following one: Formula=(( MeasurePower = 100 ) ? 1 : (( MeasurePower > 49 ) ? 2 : (( MeasurePower > 10 ) ? 3 : 4))). This also makes useless the DynamicVariables=1 option of the measure. Remove it.
Note that the ".0":"" section of the Substitute option of the same [powerColor] measure is also not needed. Remove it as well: Substitute="2":"0,255,0,255","3":"255,255,0,255","4":"255,0,0,255","1":"0,0,255,255".
THANK YOU SO MUCH. I spent hours trying to figure this out as a new user to rainmeter.
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Dynamic Color Battery Bar

Post by balala »

EmDash00 wrote: December 31st, 2018, 8:40 pm THANK YOU SO MUCH. I spent hours trying to figure this out as a new user to rainmeter.
You're welcome.
Forgetting the DynamicVariables=1 option is a common mistake, many times. New users many times have such problems. But if you'll keep working, you'll get used to it.
This time for example the [powerColor] is used as a section variable in the BarColor option of the [MeterBar] meter and section variables are always requiring to set the dynamic variables. That's why that option is needed.