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

Using formulas with meter names? Is it possible?

Get help with installing and using Rainmeter.
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am
Contact:

Using formulas with meter names? Is it possible?

Post by Krainz »

Example:

Let's say I have squares S01, S02, S03 and S04

When clicking square S02, square S01 (metername-1) is hidden

The idea is more or less as follows:

Code: Select all

[Style]
Meter=Image
Solidcolor=0,0,0,255
H=100
W=100
X=150R
LeftMouseUpAction=[!ToggleMeter "S0[-1]"]

[S01]
Meter=Image
MeterStyle=Style

[S02]
Meter=Image
MeterStyle=Style

[S03]
Meter=Image
MeterStyle=Style

[S04]
Meter=Image
MeterStyle=Style
The question is: is it possible to make one unique formula that will always subtract the current meter's ID number by one?

Or do I have to put in a formula for every square that's going to hide the previous one? I.e:

Code: Select all

[Style]
Meter=Image
Solidcolor=0,0,0,255
H=100
W=100
X=150R


[S01]
Meter=Image
MeterStyle=Style

[S02]
Meter=Image
MeterStyle=Style
LeftMouseUpAction=[!ToggleMeter "S01"]

[S03]
Meter=Image
MeterStyle=Style
LeftMouseUpAction=[!ToggleMeter "S02"]

[S04]
Meter=Image
MeterStyle=Style
LeftMouseUpAction=[!ToggleMeter "S03"]
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

Post by balala »

Krainz wrote: October 14th, 2019, 5:40 pm The question is: is it possible to make one unique formula that will always subtract the current meter's ID number by one?
No, it's not, however a kind of approach still exists.
First you have to add a String measure, which converts the name of the clicked meter to a simple number:

Code: Select all

[MeasureOrd]
Measure=String
String=#Ord#
RegExpSubstitute=1
Substitute="S0(\d{1})":"\1"
DynamicVariables=1
Now modify the LeftMouseUpAction of the [Style] section (which I believe it's not a meter, as stated by its Meter=Image option, but I style applied to all Image meters, so it shouldn't have to have the mentioned Meter=Image option), using the following option instead of the existing one: LeftMouseUpAction=[!SetVariable Ord "#CURRENTSECTION#"][!UpdateMeasure "MeasureOrd"][!ToggleMeter "S0[MeasureOrd]"][!Redraw]. See that when clicked, the Ord variable gets the name of the clicked meter, this is converted by the [MeasureOrd] measure to a number, then finally the !ToggleMeter bang of the LeftMouseUpAction hides this meter. Note that in this case using the !ToggleMeter bangs is useless, because a meter once hidden (on the first click), it never can be shown again, because you can't click a hidden meter, to get it back.
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am
Contact:

Re: Using formulas with meter names? Is it possible?

Post by Krainz »

Thank you!
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

Post by balala »

:thumbup:
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am
Contact:

Re: Using formulas with meter names? Is it possible?

Post by Krainz »

Hey I must be doing something wrong

Here's the measure I'm using:

Code: Select all

[CurrentIcon]
Measure=String
String=#IACT#
RegExpSubstitute=1
Substitute="mIndex(\d{1})":"\1"
DynamicVariables=1
And here's the hotkey measure:

Code: Select all

[Enter]
Measure=Plugin
Plugin=HotKey
HotKey=ENTER
KeyDownAction=[!SetVariable IACT "#CURRENTSECTION#"][!CommandMeasure "mIndex[CurrentIcon]" "Open"]
DynamicVariables=1
It works if I put [!CommandMeasure mIndex1 "Open"]. But if I tried it with all of the following and it didn't work:

KeyDownAction=[!CommandMeasure "[CurrentIcon]" "Open"]
KeyDownAction=[!CommandMeasure "mIndex[CurrentIcon]" "Open"]
KeyDownAction=[!CommandMeasure """mIndex[CurrentIcon]""" "Open"]

What am I supposed to do?


What I'm trying to do: enter opens the currently highlighted fileview icon through CommandMeasure. left and right keyboard arrows change the currently highlighted item. mouseover will also internally set the highlighted item to the one being hovered, but that's mostly for hotkey interactions.

The reason I'm trying to use formulas with these hotkey measures is so that I don't end up needing three hotkey measures for every single fileview item.

EDIT: nevermind, I found a way to resolve it. Your post made me realize I could reference a meter alongside a measure within quotes and Rainmeter will understand it as a meter.

The solution:

Code: Select all

[CurrentN]
Measure=Calc
Formula=1
UpdateDivider=-1
IfCondition=CurrentN < 1
IfTrueAction=[!SetOption CurrentN Formula "1"][!UpdateMeasure CurrentN]

[PressLeftCounter]
Measure=Calc
Formula=PressLeftCounter + 1
Disabled=1
UpdateDivider=-1
OnUpdateAction=[!SetOption CurrentN Formula "([CurrentN] - 1)"][!UpdateMeasure CurrentN][!Redraw]

[PressRightCounter]
Measure=Calc
Formula=PressRightCounter + 1
Disabled=1
UpdateDivider=-1
OnUpdateAction=[!SetOption CurrentN Formula "([CurrentN] + 1)"][!UpdateMeasure CurrentN][!Redraw]

[LeftKeyboard]
Measure=Plugin
Plugin=HotKey
HotKey=LEFT
KeyDownAction=[!HideMeter "btn[CurrentN]"][!EnableMeasure PressLeftCounter][!UpdateMeasure PressLeftCounter][!ShowMeter "btn[CurrentN]"][!Redraw]

[RightKeyboard]
Measure=Plugin
Plugin=HotKey
HotKey=RIGHT
KeyDownAction=[!HideMeter "btn[CurrentN]"][!EnableMeasure PressRightCounter][!UpdateMeasure PressRightCounter][!ShowMeter "btn[CurrentN]"][!Redraw]

[Enter]
Measure=Plugin
Plugin=HotKey
HotKey=ENTER
KeyDownAction=[!CommandMeasure "mIndex[CurrentN]" "Open"]
If anyone is interested or curious, btn1 btn2 btn3 etc are the highlight meters.


Now what I'm having trouble with is the following (and I believe it needs regExp):

I want MouseOverAction to make [CurrentN] the number of the current btn being hovered by the mouse.

Example: mouse hovers over btn5. It does a [!HideMeter "btn[CurrentN]"] and then makes [CurrentN] 5.

Mouse hovers over btn7. It does a [!HideMeter "btn[CurrentN]"] and then makes [CurrentN] 7.

What I tried doing was:

Code: Select all

[btnstyle]
MouseOverAction=[!HideMeter "btn[CurrentN]"][!SetVariable BTNORD #CURRENTSECTION#][!UpdateMeasure "CurrentNstring"][!SetOption CurrentN Formula "[CurrentNstring]"][!UpdateMeasure CurrentN]

[CurrentNstring]
Measure=String
String=#BTNORD#
RegExpSubstitute=1
Substitute="btn(\d{1})":"\1"
DynamicVariables=1
But it doesn't seem to work. What should I do?
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

Post by balala »

Krainz wrote: December 13th, 2019, 5:51 am But it doesn't seem to work. What should I do?
:confused:
Have no idea and probably no one will have, because if you're posting just some small pieces of your code, not the entire one, we can't replicate what you have there / the issue. For instance in the above case the substitution of the [CurrentNstring] measure will properly work only if the [btnstyle] section is used onto meters named [btnX] (where X must be a digit). Don't know if it is properly used. Additionally it is extremely hard for us to re-create the whole code, based on the posted sections, especially that probably more sections are not posted at all. To be honest doesn't worth for anyone to work too much just to can replicate the issue. It would be your duty to help us to help you: https://forum.rainmeter.net/viewtopic.php?f=5&t=28421#p148358
Post complete code please, or if resources are needed, pack the config and upload the package. You probably will get help if we can easily replicate the skin and it causes the same problem here as on your side. Otherwise...
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am
Contact:

Re: Using formulas with meter names? Is it possible?

Post by Krainz »

Yeah, I think I should just give up. The btn is this blue frame behind the image panel, and I'd end up having to code around not only hovering the btn but also the image panel.

I gave it a try by setting one of those string meters to tell me the current value of CurrentN and it was always being set to 2 whenever any meter was hovered and when my mouse left the boundaries of any meter it reset back to 1. Crazy.

Maybe lua could do it but I don't have a clue how to code lua
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

Post by balala »

Krainz wrote: December 13th, 2019, 8:32 pm Yeah, I think I should just give up. The btn is this blue frame behind the image panel, and I'd end up having to code around not only hovering the btn but also the image panel.

I gave it a try by setting one of those string meters to tell me the current value of CurrentN and it was always being set to 2 whenever any meter was hovered and when my mouse left the boundaries of any meter it reset back to 1. Crazy.

Maybe lua could do it but I don't have a clue how to code lua
Don't directly run into lua. As said it is extremely hard for anyone to help you if we can't simply replicate the issue. That's why I asked you to post a complete code or pack and upload the config (if some resources are involved). Would be much easier to help.
User avatar
Yamajac
Posts: 134
Joined: June 30th, 2014, 8:44 am

Re: Using formulas with meter names? Is it possible?

Post by Yamajac »

Use 1 instead of s01.
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am
Contact:

Re: Using formulas with meter names? Is it possible?

Post by Krainz »

balala wrote: December 13th, 2019, 9:21 pm Don't directly run into lua. As said it is extremely hard for anyone to help you if we can't simply replicate the issue. That's why I asked you to post a complete code or pack and upload the config (if some resources are involved). Would be much easier to help.
Hey I saw that you got my package to work (one of the reasons I was slightly afraid of packaging it)
balala wrote: December 15th, 2019, 6:14 pm Ok, now I got working the scrolling. Now what is the issue with it? Is it fixed? Because:
Would you mind helping me on this matter?

I want that, when an icon of GameScreen1-Tiles.ini is hovered, that CurrentN is updated to its value.

The intended interaction is:

If I hover the icon 4, if I press left on my keyboard or gamepad the selector should move left, now highlighting item 3
If I hover the icon 4 and press right, it should highlight the icon on the right, which should be item 5

This is my approach, but it didn't seem to work:

Between [overlay0small] and [btn1] I added the following calc measures:

Code: Select all

[btnHoverControl1]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 1
IfFalseAction=[!SetOption CurrentN Formula "1"][!Update CurrentN]

[btnHoverControl2]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 2
IfFalseAction=[!SetOption CurrentN Formula "2"][!Update CurrentN]

[btnHoverControl3]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 3
IfFalseAction=[!SetOption CurrentN Formula "3"][!Update CurrentN]

[btnHoverControl4]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 4
IfFalseAction=[!SetOption CurrentN Formula "4"][!Update CurrentN]

[btnHoverControl5]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 5
IfFalseAction=[!SetOption CurrentN Formula "5"][!Update CurrentN]

[btnHoverControl6]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 6
IfFalseAction=[!SetOption CurrentN Formula "6"][!Update CurrentN]

[btnHoverControl7]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 7
IfFalseAction=[!SetOption CurrentN Formula "7"][!Update CurrentN]

[btnHoverControl8]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 8
IfFalseAction=[!SetOption CurrentN Formula "8"][!Update CurrentN]

[btnHoverControl9]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 9
IfFalseAction=[!SetOption CurrentN Formula "9"][!Update CurrentN]

[btnHoverControl10]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 10
IfFalseAction=[!SetOption CurrentN Formula "10"][!Update CurrentN]

[btnHoverControl11]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 11
IfFalseAction=[!SetOption CurrentN Formula "11"][!Update CurrentN]

[btnHoverControl12]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 12
IfFalseAction=[!SetOption CurrentN Formula "12"][!Update CurrentN]

[btnHoverControl13]
Measure=Calc
Formula=CurrentN
UpdateDivider=-1
DynamicVariables=1
IfCondition=CurrentN = 13
IfFalseAction=[!SetOption CurrentN Formula "13"][!Update CurrentN]
I also edited the [btn1] to [btn13] meters to include interaction with the new measures

Code: Select all

[btn1]
Meter=Image
MeterStyle=btn1st
X=(#NumberOfItems# < 7 ? 11 : (#ATX#+11))
Y=((183*((Clamp((#screenareawidth#),1366,1600))/1440))+#Ysh#)
DynamicVariables=1
Hidden=0
MouseOverAction=[!UpdateMeasure btnHoverControl1]

[btn2]
Meter=Image
MeterStyle=btn1st
DynamicVariables=1
X=(#WidthBig#+5)R
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl2]

[btn3]
Meter=Image
MeterStyle=btn1st
X=(#WidthBig#+5)R
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl3]

[btn4]
Meter=Image
MeterStyle=btn1small
X=(#WidthBig#+5)R
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl4]

[btn5]
Meter=Image
MeterStyle=btn1small
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl5]

[btn6]
Meter=Image
MeterStyle=btn1small
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl6]

[btn7]
Meter=Image
MeterStyle=btn1st
X=(#WidthSmall#+5)R
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl7]

[btn8]
Meter=Image
MeterStyle=btn1st
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl8]

[btn9]
Meter=Image
MeterStyle=btn1st
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl9]

[btn10]
Meter=Image
MeterStyle=btn1small
X=(#WidthBig#+5)R
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl10]

[btn11]
Meter=Image
MeterStyle=btn1small
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl11]

[btn12]
Meter=Image
MeterStyle=btn1small
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl12]

[btn13]
Meter=Image
MeterStyle=btn1st
X=(#WidthSmall#+5)R
Y=r
MouseOverAction=[!UpdateMeasure btnHoverControl13]
However, these new measures seem to make CurrentN go haywire and start at an unintended value.

Also, the reason I wrote an IfCondition (is currentN the same one being hovered?) IfFalseAction (if no, then make it) was because I was having some odd interactions whenever the mouse stopped hovering the meter.

I also tried your method with RegExp. There are two meterstyles ([btn1st] [btn1small]), because there are two kinds of btn and I could very well just put a generic MouseOverAction there to make CurrentN's formula the same number as the currently hovered btn, but I couldn't possibly make that work
Post Reply