It is currently March 28th, 2024, 7:58 pm

[Suggestion] Assigning a number to a meter

Report bugs with the Rainmeter application and suggest features.
User avatar
Cariboudjan
Posts: 264
Joined: May 12th, 2019, 8:55 am

[Suggestion] Assigning a number to a meter

Post by Cariboudjan »

I would love, love, love if authors could assign a number to a meter. I see a lot of skins using [1] [2] [3] as Section Names to facilitate this with #CURRENTSECTION#, but it would be easier and more versatile if the section name did not did need to be a number to accomplish this.

For example, instead of...

Code: Select all

[1]

[2]

[3]

[MeasureName1]

[MeasureName2]

[MeasureName3]
We could start seeing...

Code: Select all

[MeterName1]
AssignedValue=1

[MeterName2]
AssignedValue=2

[MeterName3]
AssignedValue=3


[MeasureName1]
AssignedValue=1

[MeasureName2]
AssignedValue=2

[MeasureName3]
AssignedValue=3
And then instead of using #CURRENTSECTION# to get the number, maybe a variable like #CURRENTVALUE# that would be equal to that section's "AssignedValue" instead of its section name...

If this were an option I could use styles to cut the work for some of my skins in half, and probably reduce the number of lines in some configs by upwards of 80% using styles and nested variables.
Screenshot 2021-02-08 235542.png
You do not have the required permissions to view the files attached to this post.
User avatar
Jeff
Posts: 326
Joined: September 3rd, 2018, 11:18 am

Re: [Suggestion] Assigning a number to a meter

Post by Jeff »

I feel like at the moment this problem could be solved with Lua, you just need a little bit of

Code: Select all

function PullOption(section, name, key)
	if section = 'Meter' then m = SKIN:GetMeter(name)
	elseif section = 'Measure' then m = SKIN:GetMeasure(name)
	else print("We're both stupid or you did something wrong")
	end
	return m:GetOption(key, '0')
end
and because Rainmeter STILL doesn't allow for user defined options, you can use Group instead, pull out the Inline Lua and [&Script:PullOption('Measure', 'TheStringMeasure', 'Group')] (you also have a good advantage with this cause you can use #CurrentSection#)
User avatar
Jeff
Posts: 326
Joined: September 3rd, 2018, 11:18 am

Re: [Suggestion] Assigning a number to a meter

Post by Jeff »

Updating this, Macro mod already has the feature you're asking for
User avatar
Cariboudjan
Posts: 264
Joined: May 12th, 2019, 8:55 am

Re: [Suggestion] Assigning a number to a meter

Post by Cariboudjan »

I'm surprised I never get any response from the devs when I suggest this. This would be such a helpful tool for Rainmeter to have.

But thanks for the response Jeff.
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: [Suggestion] Assigning a number to a meter

Post by Active Colors »

There were already several suggestions for somewhat similar feature. I am not sure but I suppose devs agreed to look at it sometime later.
User avatar
Cariboudjan
Posts: 264
Joined: May 12th, 2019, 8:55 am

Re: [Suggestion] Assigning a number to a meter

Post by Cariboudjan »

Yeah. Also in addition, another problem with the current method of using #CURRENTSECTION#, is that you can only use this method once per config, as section names can't be repeated.

So if I have 2 columns of strings, each with an associated icon, I can only use something like this once, so the second column would be much uglier and time consuming with repetitive copy-paste bangs that can't use styles as clean as this.

Code: Select all

[Variables]
Text1=A
Text2=B
Text3=C

[StringStyle]
Text=[#Text[#CURRENTSECTION]]
MouseOverAction=[!SetOption Icon#CURRENTSECTION# ImageTint "255,255,255"]
MouseLeaveAction=[!SetOption Icon#CURRENTSECTION# ImageTint "0,0,0"]

[1]
Meter=String
MeterStyle=StringStyle

[2]
Meter=String
MeterStyle=StringStyle

[3]
Meter=String
MeterStyle=StringStyle

[Icon1]
Meter=Image

[Icon2]
Meter=Image

[Icon3]
Meter=Image
Plus there's just the problem of having to name your meters numbers at all, instead of being able to give them an actual name, like "Meter1", "Meter2", "Meter3", etc.

In review:

Without this suggestion, you can't:

1. Have names for your meters/measures
2. Use the method more than once per config
3. Have bi-directional meter/measure referencing
4. Have clean code
User avatar
Cariboudjan
Posts: 264
Joined: May 12th, 2019, 8:55 am

Re: [Suggestion] Assigning a number to a meter

Post by Cariboudjan »

Found a temporary solution? Kind of? Assign numbers to variables of the same name as the meters, and use [!SetVariable MeterValue [##CURRENTSECTION#]].

Works. Confirmed.
GIF 3-30-2021 10-47-49 AM.gif

Code: Select all

[Rainmeter]
MiddleMouseDownAction=[!Refresh]

[Variables]
MeterValue=0

String1=1
String2=2
String3=3
String4=4
String5=5
String6=6

String1Text=One
String2Text=Two
String3Text=Three
String4Text=Four
String5Text=Five
String6Text=Six

Icon1Color=255,0,0
Icon2Color=0,255,0
Icon3Color=0,0,255
Icon4Color=255,0,255
Icon5Color=0,255,255
Icon6Color=255,255,0

;-----------------------------------

[StringStyle]
SolidColor=0,0,0
Text=[##CURRENTSECTION#Text]
FontColor=255,255,255
FontSize=15
MouseOverAction=[!SetVariable MeterValue [##CURRENTSECTION#]][!SetOption Icon[##CURRENTSECTION#] SolidColor "255,255,255"][!UpdateMeter Icon[##CURRENTSECTION#]][!Redraw]
MouseLeaveAction=[!SetOption Icon[##CURRENTSECTION#] SolidColor ""][!UpdateMeter Icon[##CURRENTSECTION#]][!Redraw]
Padding=25,0,0,0
W=100
H=25
Y=R

[IconStyle]
SolidColor=[##CURRENTSECTION#Color]
W=25
H=25
Y=R

;-----------------------------------

[String1]
Meter=String
MeterStyle=StringStyle
Y=0

[String2]
Meter=String
MeterStyle=StringStyle

[String3]
Meter=String
MeterStyle=StringStyle

[String4]
Meter=String
MeterStyle=StringStyle

[String5]
Meter=String
MeterStyle=StringStyle

[String6]
Meter=String
MeterStyle=StringStyle

;-----------------------------------

[Icon1]
Meter=Image
MeterStyle=IconStyle
Y=0

[Icon2]
Meter=Image
MeterStyle=IconStyle

[Icon3]
Meter=Image
MeterStyle=IconStyle

[Icon4]
Meter=Image
MeterStyle=IconStyle

[Icon5]
Meter=Image
MeterStyle=IconStyle

[Icon6]
Meter=Image
MeterStyle=IconStyle
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [Suggestion] Assigning a number to a meter

Post by Yincognito »

Jeff wrote: February 10th, 2021, 7:47 pm I feel like at the moment this problem could be solved with Lua, you just need a little bit of

Code: Select all

function PullOption(section, name, key)
	if section = 'Meter' then m = SKIN:GetMeter(name)
	elseif section = 'Measure' then m = SKIN:GetMeasure(name)
	else print("We're both stupid or you did something wrong")
	end
	return m:GetOption(key, '0')
end
and because Rainmeter STILL doesn't allow for user defined options, you can use Group instead, pull out the Inline Lua and [&Script:PullOption('Measure', 'TheStringMeasure', 'Group')] (you also have a good advantage with this cause you can use #CurrentSection#)
Excellent point, Jeff! :thumbup:

Using my newly acquired Lua knowledge (had to happen some day, LOL) and taking advantage that the OR operator in Lua can be used to "choose" something else than a FALSE value (or the equivalent NIL value, like the SKIN:GetMeasure('MeasureName') and SKIN:GetMeter('MeterName') values when Lua doesn't find the respective sections), your Lua code can be shortened further to a one liner by pasting this into a hypothetical Script.lua file, created in the @Resources folder of the current skin:

Code: Select all

function GetOption(section, key)
  return (SKIN:GetMeasure(section) or SKIN:GetMeter(section)):GetOption(key, '0')
end
or even an actual one liner:

Code: Select all

function GetOption(section, key) return (SKIN:GetMeasure(section) or SKIN:GetMeter(section)):GetOption(key, '0') end
and used like [&Script:GetOption('SomeSection','SomeOption')] (careful with spaces after commas in native Rainmeter, got an error when trying out your sample until I removed them), where [Script] is a simple measure like:

Code: Select all

[Script]
Measure=Script
ScriptFile=#@#Script.lua
UpdateDivider=-1
in the skin.

Indeed, it can be used with the #CURRENTSECTION# variable (or, as recommended, its nested syntax) as well and even included in a MeterStyle:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[Script]
Measure=Script
ScriptFile=#@#Script.lua
UpdateDivider=-1

---Styles---

[TextStyle]
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MouseOverAction=[!Log "#CURRENTSECTION# hovered, AssignedValue = [&Script:GetOption('[#CURRENTSECTION]','AssignedValue')]"]
MouseLeaveAction=[!Log "#CURRENTSECTION# leaved, AssignedValue = [&Script:GetOption('[#CURRENTSECTION]','AssignedValue')]"]

---Meters---

[Meter1]
Meter=String
MeterStyle=TextStyle
AssignedValue=1
Text="#CURRENTSECTION#"
;Text="Meter [&Script:GetOption('[#CURRENTSECTION]','AssignedValue')]"
DynamicVariables=1

[Meter2]
Meter=String
MeterStyle=TextStyle
AssignedValue=2
Text="#CURRENTSECTION#"
;Text="Meter [&Script:GetOption('[#CURRENTSECTION]','AssignedValue')]"
DynamicVariables=1
AssignedValue above is a custom / user option and can be retrieved using Lua, being displayed in the Log when hovering or leaving the meters. There is one problem though, or maybe I'm missing something here: when uncommenting the 2nd Text options and commenting the 1st ones in the meters, the font and its size is reset. Does anyone have a clue as to why that happens? Too much self reference, maybe? :???:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: [Suggestion] Assigning a number to a meter

Post by Active Colors »

Me and, I believe, the other gentlemen in this topic would be extremely happy if the devs team could get back to this again sometime and think about some sort of #CURRENTSECTIONINDEX# variable to obtain the N of a section. Considering that this feature has been asked many times throughout the past years and the rising interest in simplifying the repetitive parts, this would be a great gift to all of us who make a bit more thought out skins. It is extremely useful for any repetitive bits of a skin which appear quite often in any skins, not just only some launchers.


I am really sorry for reminding about this again, and I understand this is something not as easy as it may look. Specifically, it sounds easy that the hypothetical #CurrentSectionIndex# supposedly would obtain a number of the section name (e.g. 12 from [SectionName12]). However, I predict there could be some debates about how it is supposed to work. Some sort of rules to implement. Some of which I think are:

— in order to make this variable work, there should be some rule about how #CurrentSectionIndex# detects an index in the section name. Should the number always be in the end of a section (e.g. [SectionName12]), or it could be just anywhere in the section name (e.g. [Section12Name])?

— another popular thing among users about section names are double indexes (e.g. [Section5Name12]). Should there be #CurrentSectionIndexFirst# and #CurrentSectionIndexLast#, or there always will always be only one index in the section name and, no matter what, only the last number will be treated as an index? Could this be potentially solved by making users follow some strict rules for naming their sections names where they would want to use these variables in order to make everything work smooth?


I would be happy to chime in by testing speculative test builds and providing feedback if this feature gets some attention.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [Suggestion] Assigning a number to a meter

Post by Yincognito »

Active Colors wrote: April 15th, 2021, 12:45 pmMe and, I believe, the other gentlemen in this topic would be extremely happy if the devs team could get back to this again sometime and think about some sort of #CURRENTSECTIONINDEX# variable to obtain the N of a section...
Yep, indeed. In the meantime:

Script.lua (placed in the @Resources folder, in this case; called using [&Script:SectionIndex('SomeSection',SomeOccurrence)]):

Code: Select all

function SectionIndex(section, occurrence)
  local indexes = {}
  for index in section:gmatch('%d+') do table.insert(indexes, index) end
  if occurrence == 'first' then occurrence = 1 elseif occurrence == 'last' then occurrence = #indexes end
  return indexes[tonumber(occurrence)] or '0'
end
Test.ini (i.e. the test skin; you can iterate through the indexes of the section by scrolling, just for test purposes):

Code: Select all

[Variables]
Occurrence=1

[Rainmeter][Variables]
Occurrence=1

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[Script]
Measure=Script
ScriptFile=#@#Script.lua
UpdateDivider=-1

[MeasureTest3Test56Test13Test2]
Measure=Calc
Formula="[&Script:SectionIndex('[#CURRENTSECTION]',[#Occurrence])]"
UpdateDivider=-1
DynamicVariables=1

---Meters---

[MeterTest]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=MeasureTest3Test56Test13Test2
Text="SectionName = MeasureTest3Test56Test13Test2#CRLF#SectionIndex (the occurrence number)    = [#Occurrence]#CRLF#SectionIndex (from the current section) = %1#CRLF#SectionIndex (from the related meter)   = [&Script:SectionIndex('MeasureTest3Test56Test13Test2',[#Occurrence])]#CRLF#SectionIndex (of the first occurrence)  = [&Script:SectionIndex('MeasureTest3Test56Test13Test2','first')]#CRLF#SectionIndex (of the last occurrence)   = [&Script:SectionIndex('MeasureTest3Test56Test13Test2','last')]"
MouseScrollUpAction=[!SetVariable Occurrence (#Occurrence#-1)][!UpdateMeasure *][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable Occurrence (#Occurrence#+1)][!UpdateMeasure *][!UpdateMeter *][!Redraw]
DynamicVariables=1
Preview:
SectionIndex.jpg
(this shows the 3rd occurrence of an "index" in the chosen "section name", as well as the "first" and the "last" occurrence of such an "index")

Some "features":
- it works with whatever section one wants, not just #CURRENTSECTION#, or better said, the dynamic [#CURRENTSECTION]
- it works even if the section doesn't exist (it's all about strings), so this would probably work for grabbing the n-th element from a list like, say, "15,6,29,1,7"
- it works even if the 2nd parameter is a string like 'first' or 'last'
- it fails to '0' if there are some "errors" or some "nil" values

Moral of the story: if folks don't listen to you, take the matter into your own hands. ;-)
Active Colors wrote: April 15th, 2021, 12:45 pmI would be happy to chime in by testing speculative test builds and providing feedback if this feature gets some attention.
Test my code instead... :sly:
You do not have the required permissions to view the files attached to this post.
Last edited by Yincognito on April 16th, 2021, 5:35 pm, edited 1 time in total.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth