Active Colors wrote: ↑February 18th, 2022, 2:47 pmI am wondering if there is a possible way to optimize this and have only 1 measure that could be used to calculate any desired amount of meter's widths?
Is there a way to make one calc measure that could understand how many meters it needs to sum and it would sum them?
(I know that it would be simple if all the meters had the same width and I could use simply Formula=(#W#*#N#) but unfortunately that's not the case.)
[...]
I am still looking for a way to have only one measure instead of having numerous of them.
Yes, yes, yes, and here it is - it doesn't even need a measure, just a variable, a meter where you initialize the said variable to 0 (could have been the 1st icon meter as well, by the way), some MeterStyle to avoid copy pasting, and a synchronous updating of the icon meters which I assume you already have (the rest in the code - including the measure, the max or the hide/show toggling - is entirely optional, just to beautify and make the whole thing a bit dynamic via mouse scroll):
Code: Select all
[Variables]
N=9
MAXN=9
TW=0
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
DefaultUpdateDivider=-1
---Measures---
[TW]
Measure=Calc
Formula=(#TW#)
DynamicVariables=1
---Styles---
[SumStyle]
SolidColor=255,0,0,255
Y=15r
H=10
DynamicVariables=1
OnUpdateAction=[!SetVariable TW (#TW#+[#CURRENTSECTION#:W])][!UpdateMeasure TW]
---Meters---
[Background]
Meter=Shape
Shape=Rectangle 0,0,100,160 | Fill Color 0,0,0,255 | StrokeWidth 0
OnUpdateAction=[!SetVariable TW 0]
MouseScrollUpAction=[!SetVariable N (Clamp(#N#+1,1,#MAXN#))][!ShowMeter Icon#N#][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable N (Clamp(#N#-1,1,#MAXN#))][!HideMeter Icon#N#][!UpdateMeter *][!Redraw]
DynamicVariables=1
[Icon1]
Meter=Image
MeterStyle=SumStyle
W=20
[Icon2]
Meter=Image
MeterStyle=SumStyle
W=10
[Icon3]
Meter=Image
MeterStyle=SumStyle
W=12
[Icon4]
Meter=Image
MeterStyle=SumStyle
W=31
[Icon5]
Meter=Image
MeterStyle=SumStyle
W=1
[Icon6]
Meter=Image
MeterStyle=SumStyle
W=7
[Icon7]
Meter=Image
MeterStyle=SumStyle
W=19
[Icon8]
Meter=Image
MeterStyle=SumStyle
W=43
[Icon9]
Meter=Image
MeterStyle=SumStyle
W=36
Sum.jpg
Basically, all you need to do is add the currently updated meter's width to the already existing sum value, and of course, reset it that sum to 0 in the beginning. You can even count those meters like that, by the way, by adding 1 to the sum instead of the meter's width.
P.S. If you want to be able to update individual icon meters without messing up with the resulting sum via duplicate additions, you can create, say, a
#NeedSum# variable that you can set or toggle according to your needs (1 to add meter width to the sum, 0 to not do that), and only reset the sum to 0 or add widths to the
#TW# (total width) "on demand", by doing something similar to:
Code: Select all
[!SetVariable TW (#NeedSum#=1?#TW#+[#CURRENTSECTION#:W]:#TW#)]
P.S.S. This does not depend on the name of the meters, it can be used with any meter that you use the style (or better said, the OnUpdateAction bangs) on, and it doesn't choke if self updating a measure for a couple of hundreds or thousands of meters (assuming you'd have that in your skin, that is). It simply attaches itself to the natural Rainmeter updating process and only requires a bit of attention when you update meters, so as to not yield an incorrect result, that's all.
EDIT: Played a bit with the code to make it compute the widths sum properly when individually updating meters - again, this is entirely optional, since I have no idea what is the context where you want this to be applied on:
Code: Select all
[Variables]
N=9
MAXN=9
TW=0
MAXW=100
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
DefaultUpdateDivider=-1
---Measures---
[TW]
Measure=Calc
Formula=([#TW])
DynamicVariables=1
---Styles---
[SumStyle]
SolidColor=255,0,0,255
Y=15r
H=10
OnUpdateAction=[!SetVariable TW ([#TW]+[#CURRENTSECTION#:W])][!UpdateMeasure TW]
MouseScrollUpAction=[!SetVariable TW ([#TW]-[#CURRENTSECTION#:W])][!UpdateMeasure TW][!SetOption #CURRENTSECTION# W (Clamp([#CURRENTSECTION#:W]+1,1,#MAXW#))][!UpdateMeter #CURRENTSECTION#][!Redraw]
MouseScrollDownAction=[!SetVariable TW ([#TW]-[#CURRENTSECTION#:W])][!UpdateMeasure TW][!SetOption #CURRENTSECTION# W (Clamp([#CURRENTSECTION#:W]-1,1,#MAXW#))][!UpdateMeter #CURRENTSECTION#][!Redraw]
DynamicVariables=1
---Meters---
[Background]
Meter=Shape
Shape=Rectangle 0,0,100,160 | Fill Color 0,0,0,255 | StrokeWidth 0
OnUpdateAction=[!SetVariable TW 0]
MouseScrollUpAction=[!SetVariable N (Clamp(#N#+1,1,#MAXN#))][!ShowMeter Icon#N#][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable N (Clamp(#N#-1,1,#MAXN#))][!HideMeter Icon#N#][!UpdateMeter *][!Redraw]
DynamicVariables=1
[Icon1]
Meter=Image
MeterStyle=SumStyle
W=20
[Icon2]
Meter=Image
MeterStyle=SumStyle
W=10
[Icon3]
Meter=Image
MeterStyle=SumStyle
W=12
[Icon4]
Meter=Image
MeterStyle=SumStyle
W=31
[Icon5]
Meter=Image
MeterStyle=SumStyle
W=1
[Icon6]
Meter=Image
MeterStyle=SumStyle
W=7
[Icon7]
Meter=Image
MeterStyle=SumStyle
W=19
[Icon8]
Meter=Image
MeterStyle=SumStyle
W=43
[Icon9]
Meter=Image
MeterStyle=SumStyle
W=36
What happens here is that besides scrolling on the blank background to simulate changing the number of icon meters, I added scrolling on individual meters to simulate such meters dynamically changing their width (updating individually, in this case, for the sake of argument). The changes to the code are switching to the nested syntax for
[#TW] (total width) in order to get its current value without having to update the respective meter, and subtracting the meter width value from the sum before dynamically changing it, followed by individually updating the meter as usual (which will add back its newly modified width to the sum) after the dynamic adjustment. Even with such (potential) code changes, the idea remains that the key to the process is a simple
[!SetVariable TW ([#TW]+[#CURRENTSECTION#:W])] on update.
You do not have the required permissions to view the files attached to this post.