It is currently August 8th, 2020, 5:39 am

Simplify repeating meters with current section index [trick]

Tips and Tricks from the Rainmeter Community
User avatar
Active Colors
Moderator
Posts: 605
Joined: February 16th, 2012, 3:32 am

Simplify repeating meters with current section index [trick]

Post by Active Colors »

About:

This trick simplifies the way you make your skins allowing to quickly edit, update, scale, and fix without copy/pasting the same code and chaning an incremental value over all the meters.

(There is another approach if you need to create similar looking set of meters and measures on the go using the template generation method.)

This trick is good for somewhat complex skins, which I call component based – you already have your various repetative meters where the difference is only a number (also possible with words or letters, depending on your case, but using numbers allow more flexibility), and you just keep 100% of everything else in the correspodning MeterStyles.

This method deals with cases like:

Code: Select all

[Meter1]
Meter=Image

[Meter2]
Meter=Image

[AnotherMeter1]
Meter=String
X=[Meter1:X]
DynamicVariables=1

[AnotherMeter2]
Meter=String
X=[Meter2:X]
DynamicVariables=1
The logic is that you have to refer to the same meter name "Meter" but within a current section INDEX, which are 1, 2, 3, etc. So you basically want to tell it "take X from the meter Meter but the N is from the current section.

And it also works with stuff like:

Code: Select all

[Text1]
Meter=String

[Text2]
Meter=String

[Image1]
Meter=Image
X=[Text1:X]
DynamicVariables=1

[Image2]
Meter=Image
X=[Text2:X]
DynamicVariables=1
The main part here is the number domain for all the repeating meters.

It is good to remind again that while I provide simplistic examples where any tricks are not very necessary, this simplification method is good for more complex structures where you really want to to use MeterStyles by 100% to simplify your coding process and make everything consistent.


How it works:
– By using Variables and Nested Variables we can omit any part of the section name enclosed in varibles.
– The section names above will be called as [#Meter#1] and [#Meter#2].
– When we use nested format of the built-in variable [#CURRENTSECTION] we will retrive the section names as #Meter#1 and #Meter#2.
– But if we already have established #Meter# variable in [Variables] section and set it to have nothing (Meter=), by calling [#CURRENTSECTION] we will be left with the current section index, which is just the number 1, 2, etc.
– So, we left only with including a desired meter category using Nested Variables, like [#*SomeMeter*#[#CURRENTSECTION]]. By enclosing SomeMeter in asterisk signs we tell it not to be changed because in Variables we have already established the variable to be substituted with nothing. If you need to refer to such meter in general you would need to do this using [#*SomeMeter*#index] form.
– If you really don't want to include a desired category name and want strictly to use current section then you just simply use #CURRENTSECTION#, but if you refer to another meter within the same index domain then you need to use Nested Variable like explained before.


Example:

Code: Select all

[Variables]
Text=
Image=


[#Text#1]
Meter=String

[#Text#2]
Meter=String


[StyleMyimage]
X=([#*Text*#[#CURRENTSECTION]:X])

[#Image#1]
Meter=Image
MeterStyle=StyleMyimage

[#Image#2]
Meter=Image
MeterStyle=StyleMyimage

Example skin:
Capture.PNG
Code:

Code: Select all

[Rainmeter]
Update=-1

[Variables]

; IMPORTANT PART FOR SECTION VARIABLES
Text=
Icon=

; SETTINGS
Image1=#@#Firefox.png
Image2=#@#Ps.png
Image3=#@#Music.png

Name1=Firefox
Name2=Photoshop
Name3=Music


; BACKGROUND
[Back]
Meter=Image
SolidColor=0,0,0
X=0
Y=0
W=425
H=235
UpdateDivider=-1
DynamicVariables=1


; ICONS
[StyleIcon]
X=20
Y=40R
W=32
H=32
ImageName=[#Image[#CURRENTSECTION]]
UpdateDivider=-1
DynamicVariables=1
MouseOverAction=[!SetOption #*Text*#[#CURRENTSECTION] Text "#*Text*#[#CURRENTSECTION]"][!UpdateMeterGroup ICON][!Redraw]

[#Icon#1]
Meter=Image
MeterStyle=StyleIcon
Y=30

[#Icon#2]
Meter=Image
MeterStyle=StyleIcon

[#Icon#3]
Meter=Image
MeterStyle=StyleIcon


; TEXTS
[StyleText]
X=([#*Icon*#[#CURRENTSECTION]:XW]+5)
Y=([#*Icon*#[#CURRENTSECTION]:Y]-([#CURRENTSECTION#:H]/2)+([#*Icon*#[#CURRENTSECTION]:H]/2))
FontFace=Arial
FontSize=10
FontColor=255,255,255
StringStyle=Normal
AntiAlias=1
ClipString=0
Text=Label: [#Name[#CURRENTSECTION]] #CRLF#Current section index: [#CURRENTSECTION]#CRLF#Y value of the current section: [#*Text*#[#CURRENTSECTION]:Y]#CRLF#Y value of the icon within the current section index: [#*Icon*#[#CURRENTSECTION]:Y]
UpdateDivider=-1
DynamicVariables=1
Group=ICON

[#Text#1]
Meter=String
MeterStyle=StyleText
[#Text#2]
Meter=String
MeterStyle=StyleText
[#Text#3]
Meter=String
MeterStyle=StyleText

I am open to any questions regarding further simplification that you are interested in.
I will be also adding more cases when I encounter them.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 11172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simplify repeating meters with current section index [trick]

Post by balala »

A DynamicVariables=1 option is missing on meters using section variables (for instance [AnotherMeter1] and [AnotherMeter2] on first example code, [Image1] and [Image2] on the second code and so on). I know you know it is needed, especially that on the uploaded example it has been added, but I suggest to edit the posted examples as well, not to mislead the less experimented users.
User avatar
Active Colors
Moderator
Posts: 605
Joined: February 16th, 2012, 3:32 am

Re: Simplify repeating meters with current section index [trick]

Post by Active Colors »

balala wrote:
July 19th, 2020, 8:34 pm
A DynamicVariables=1 option is missing on meters using section variables (for instance [AnotherMeter1] and [AnotherMeter2] on first example code, [Image1] and [Image2] on the second code and so on). I know you know it is needed, especially that on the uploaded example it has been added, but I suggest to edit the posted examples as well, not to mislead the less experimented users.
Thank you. I aggree. I indicated them in the examples.