It is currently March 28th, 2024, 11:10 am

Section Variables

Changes made during the Rainmeter 2.5 beta cycle and earlier.
Post Reply
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am
Contact:

Section Variables

Post by Kaelri »

We have added a new way to get information about meters and measures by using dynamic variable syntax. We call these section variables. Get the latest Rainmeter beta to try them out!

You already know how to use a measure's string value as a dynamic variable:

Code: Select all

[MyMeter]
Meter=String
DynamicVariables=1
Text=The string value of MyMeasure is [MyMeasure].
Section variables are an expansion of this feature, adding new options for both meters and measures.

Meters

First, you can now get any meter's real-time X/Y/W/H value as a dynamic variable, which can be used in options and formulas throughout the skin.

[MeterName:X]
[MeterName:Y]
[MeterName:W]
[MeterName:H]

It's now easy to base one meter's size or position on any other meter's. If you've ever wished you could use relative positions like X=10r or Y=-5R on any meter, instead of just the previous one, then this is for you. Cases like the following are now possible:

Code: Select all

X=[MeterName:X]
X=([MeterName:X] + 10)
X=([MeterName1:X] + [MeterName2:W] / [MeterName3:Y] * [MeterName4:H] - 10)
Measures

As for measures, you can now use the number value of a measure, instead of the string. Before now, number values were only used in certain measures and meter options, so in order to use a number value anywhere else, you would have to "pass it through" a Calc measure. Now, you can just use this:

[MeasureName:]

You can also modify the number value in a few ways. You can choose the number of decimal places:

[MeasureName:n]

Scale it:

[MeasureName:/n]

Or use it as a percentage:

[MeasureName:%]

You can even combine more than one modifier:

[MeasureName:/1024, 5]
[MeasureName:%, 4]

This makes it possible to (for example) show the same value several different ways, all within the same meter. DSVs are not bound by meter options such as Scale, AutoScale, Percentual or NumOfDecimals.

Code: Select all

Text=My number value is [MyMeasure:].
ToolTipText=My percentual value is [MyMeasure:%].
Or:

Code: Select all

Text=[MeasureBytes:] B is equal to [MeasureBytes:/1024] KB is equal to [MeasureBytes:/1048576] MB.
Lua

Finally, if you use Lua, the ReplaceVariables() function has been expanded to support these new variables.

Code: Select all

MyString = SKIN:ReplaceVariables('The scaled value of MyMeasure is [MyMeasure:/1000].')
Usage

Section variables can be used wherever regular dynamic variables can today, including formulas and bangs. As always, remember to use DynamicVariables=1 in order to get the real-time value of meter/measure properties.

There's also a new manual page for this feature, which will be revised and expanded over time.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Section Variables

Post by jsmorley »

For instance, here is a little skin demonstrating how you might use [Meter:X] and [Meter:W] to position meters in a "relative" way without worrying about the order in the skin's .ini file.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeterBlue]
Meter=Image
X=5
Y=0
W=40
H=40
SolidColor=194,201,255

[MeterGreen]
Meter=Image
X=110
Y=0
W=40
H=40
SolidColor=199,255,194

[MeterOrange]
Meter=Image
X=([MeterBlue:X] + [MeterBlue:W] + 5)
Y=0
W=40
H=40
SolidColor=255,228,194
DynamicVariables=1
8-5-2012 12-11-55 PM.jpg
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Section Variables

Post by jsmorley »

Or another simple example of using the [Meter:] functionality to have one meter (a background in this case) size in response to an unknown/variable size of another meter:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeterBack]
Meter=Image
SolidColor=20,20,20,150
W=([MeterText:W] + 10)
H=([MeterText:H] + 10)
DynamicVariables=1

[MeterText]
Meter=String
X=5
Y=5
FontSize=13
FontColor=255,255,255,255
AntiAlias=1
Text=Now is the time for all good men#CRLF#to come to the aid of their country
8-5-2012 5-59-16 PM.jpg
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Section Variables

Post by MerlinTheRed »

This is a really great addition. I like the direction you are going with this. I hope similar functionality will continue to be added.

Does the scale parameter accept floating point values? For example if I want to upscale a value instead of downscale it, will this work: [Measure:/0.5]?
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm
Contact:

Re: Section Variables

Post by poiru »

MerlinTheRed wrote:Does the scale parameter accept floating point values? For example if I want to upscale a value instead of downscale it, will this work: [Measure:/0.5]?
It will next week :)
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: Section Variables

Post by AlC »

Great addition !!!
User avatar
killall-q
Posts: 305
Joined: August 14th, 2009, 8:04 am

Re: Section Variables

Post by killall-q »

I love this, it provides one solution to the problem of designing skins around text elements of unknown or varying size. Now it's possible to give a block of text a soft shadow.
User avatar
thatsIch
Posts: 446
Joined: August 7th, 2012, 9:18 pm

Re: Section Variables

Post by thatsIch »

killall-q wrote:I love this, it provides one solution to the problem of designing skins around text elements of unknown or varying size. Now it's possible to give a block of text a soft shadow.
though I have experienced it doesnt work for auto-scale meters
that would be really cool for float text =)
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am
Contact:

Re: Section Variables

Post by Kaelri »

thatsIch wrote:though I have experienced it doesnt work for auto-scale meters
that would be really cool for float text =)
We decided against allowing AutoScale as an option for section variables because it didn't make sense to mix "numbers" and "strings". The current behavior means that any [MeasureName:option] can be used in a Calc measure or formula as a valid number.

If you want to auto-scale multiple values in the same meter, you can always use multiple "MeasureName" bindings:

Code: Select all

MeasureName=FirstMeasure
MeasureName2=SecondMeasure
MeasureName3=ThirdMeasure
Text=%1 %2 %3
Post Reply