It is currently March 28th, 2024, 9:51 am

[Help] creating a new rectangle with every for loop

Get help with creating, editing & fixing problems with skins
Kea
Posts: 7
Joined: October 1st, 2021, 9:10 pm

[Help] creating a new rectangle with every for loop

Post by Kea »

How can I create multiple rectangles below each other based on a variable amount?

Here's what I tried so far:

Lua:

Code: Select all

function Initialize()
	  background = SKIN:GetMeter("RenderRectangle")
			RectangleLoc = 20
  end

function Update()
	for i = 3,1,-1
do
SKIN:Bang("!SetVariable RecHeight " .. i*90)
end
	end
Skin:

Code: Select all

[GetData]
Measure = Script
ScriptFile = "#CURRENTPATH#main_back.lua"

[Variables]
RecHeight = 20

[RenderRectangle]
Meter = Shape
Shape = Rectangle 1750,#RecHeight#,150,70,10
DynamicVariables = 1
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: [Help] creating a new rectangle with every for loop

Post by eclectic-tech »

You don't have to use Lua, it can be done with a Loop measure.

Code: Select all

[MeasureLoop]
Measure=Loop
StartValue=1
EndValue=3
Increment=1
LoopCount=0
InvertMeasure=1

[RenderRectangle]
Meter = Shape
Shape = Rectangle 1750,([MeasureLoop]*90),150,70,10
DynamicVariables = 1
rect3.gif
Kea
Posts: 7
Joined: October 1st, 2021, 9:10 pm

Re: [Help] creating a new rectangle with every for loop

Post by Kea »

eclectic-tech wrote: October 2nd, 2021, 2:10 am You don't have to use Lua, it can be done with a Loop measure.

Code: Select all

[MeasureLoop]
Measure=Loop
StartValue=1
EndValue=3
Increment=1
LoopCount=0
InvertMeasure=1

[RenderRectangle]
Meter = Shape
Shape = Rectangle 1750,([MeasureLoop]*90),150,70,10
DynamicVariables = 1
rect3.gif
Thank you for your help but im trying to create multiple rectangles. It might seem like im trying to move one but I thought I could call a "Meter" like a function multiple times with diffrent values to create multiple rectangles with diffrent heights (example below)

Image

So... can I even do something like that in Rainmeter? Out of desperation I tried the ugly option, hiding and unhiding after manually creating multiple rectangles per lua but I can't even get that working. Any way can I hide/unhide multiple rectangles already existing as a meter in the .ini file depenting on a specific amount of something?
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: [Help] creating a new rectangle with every for loop

Post by CodeCode »

You are over-complicating things.

You can create a skin - of any size. Fill it with rectangles, and hide them according to a value or other comparison. The contents of each rectangel can be managed the same with meter groups. There are even measure pause and unpause options.

So to create several meters of the same size, you can use Styles. That is to say the dimensions and attributes can be determined by a single attibute meter:

Code: Select all

[MeterStyleRectangles]
Shape=rectangle ...
X=can be relative to the previous meter (r) or meter boundary (R)
Y=the same way if need be.

[MeterTextStyle]
Font=Calibri
FontSize=14
FontColor=25,25,200,255
etc.
Use the styles like so:

Code: Select all

[MeterRectangleOne]
Meter=Shape
MeterStyle=MeterStyleRectangles
X=34
Y=34

[MeterRectangleOneText]
Meter=String
MeterStyle=MeterTextStyle
X=50
Y=50
Show or hide them using something like this:

Code: Select all

[MeterToggleStuff]
Meter=Something relevant (string or image etc)
LeftMouseUpAction=[!SetOption MeterRectangleOneText Hidden  "0"][!Update]
You can do all of this with lua, but doing it 'the rainmeter way' is much gentler on the bloodpressure.

So lots of meters going everywhere is actually quite the norm in rainmeter. Doing things with lua is less repetitive, but harder to make subtle changes between iterations.

Comparisons can be textual or numerical, or even the return value of a measure. Check out the manual here: https://docs.rainmeter.net/manual/measures/general-options/
Kea
Posts: 7
Joined: October 1st, 2021, 9:10 pm

Re: [Help] creating a new rectangle with every for loop

Post by Kea »

CodeCode wrote: October 2nd, 2021, 2:32 pm You are over-complicating things.

You can create a skin - of any size. Fill it with rectangles, and hide them according to a value or other comparison. The contents of each rectangel can be managed the same with meter groups. There are even measure pause and unpause options.

So to create several meters of the same size, you can use Styles. That is to say the dimensions and attributes can be determined by a single attibute meter:

Code: Select all

[MeterStyleRectangles]
Shape=rectangle ...
X=can be relative to the previous meter (r) or meter boundary (R)
Y=the same way if need be.

[MeterTextStyle]
Font=Calibri
FontSize=14
FontColor=25,25,200,255
etc.
Use the styles like so:

Code: Select all

[MeterRectangleOne]
Meter=Shape
MeterStyle=MeterStyleRectangles
X=34
Y=34

[MeterRectangleOneText]
Meter=String
MeterStyle=MeterTextStyle
X=50
Y=50
Show or hide them using something like this:

Code: Select all

[MeterToggleStuff]
Meter=Something relevant (string or image etc)
LeftMouseUpAction=[!SetOption MeterRectangleOneText Hidden  "0"][!Update]
You can do all of this with lua, but doing it 'the rainmeter way' is much gentler on the bloodpressure.

So lots of meters going everywhere is actually quite the norm in rainmeter. Doing things with lua is less repetitive, but harder to make subtle changes between iterations.

Comparisons can be textual or numerical, or even the return value of a measure. Check out the manual here: https://docs.rainmeter.net/manual/measures/general-options/
Thank you, I'll try it out but I think Im going to do most of the stuff in lua since Im way more familiar with it's structure.
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: [Help] creating a new rectangle with every for loop

Post by CodeCode »

Kea wrote: October 2nd, 2021, 9:18 pm Thank you, I'll try it out but I think Im going to do most of the stuff in lua since Im way more familiar with it's structure.
You still need to know how rainmeter works, for lua to be any use.

Be sure to look at the multitude of lua skins, those, along with the manual, will give you much needed usage help - more than posting every hurdle, since many lua chiefs hereabouts wi;l need more info than you're giving. So you would need to know a bit more about rainmeter to ask the right questions to get the most help per post.

Also, don't be shy, start multiple threads, that way different users can key into what you are asking and your posts will not be crowded with different approaches - unless that helps you of course.
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: [Help] creating a new rectangle with every for loop

Post by CodeCode »

CodeCode wrote: October 3rd, 2021, 10:04 am You still need to know how rainmeter works, for lua to be any use.

Be sure to look at the multitude of lua skins, those, along with the manual, will give you much needed usage help - more than posting every hurdle, since many lua chiefs hereabouts will need more info than you're giving. So you would need to know a bit more about rainmeter to ask the right questions to get the most help per post.

Also, don't be shy, start multiple threads, that way different users can key into what you are asking and your posts will not be crowded with different approaches - unless that helps you of course.
sorry about the extra post, was just correcting typos and clicked the wrong button :oops:
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [Help] creating a new rectangle with every for loop

Post by balala »

Kea wrote: October 2nd, 2021, 1:53 pm It might seem like im trying to move one but I thought I could call a "Meter" like a function multiple times with diffrent values to create multiple rectangles with diffrent heights (example below)
Unfortunately this is very hard (or practically impossible) to be done in Rainmeter.
Kea wrote: October 2nd, 2021, 9:18 pm Thank you, I'll try it out but I think Im going to do most of the stuff in lua since Im way more familiar with it's structure.
I don't think it does worth to work with lua in this case, however it is possible.
First, beside CodeCode's example, take a look at the following sample:

Code: Select all

[Rainmeter]
DynamicWindowSize=1
Update=1000
BackgroundMode=2
SolidColor=250,250,250,1

[RectangleStyle]
X=2
Shape=Rectangle 0,0,100,50,10 | Extend MyModifiers1
MyModifiers1=Fill Color 94,75,125 | StrokeWidth 0 | Stroke Color 0,0,0,0
DynamicVariables=1

[MeasureShow]
Measure=Calc
Formula=( COUNTER % 10 )

[MeterRectangle1]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<0)

[MeterRectangle2]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<1)

[MeterRectangle3]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<2)

[MeterRectangle4]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<3)

[MeterRectangle5]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<4)

[MeterRectangle6]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<5)

[MeterRectangle7]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<6)

[MeterRectangle8]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<7)

[MeterRectangle9]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<8)

[MeterRectangle10]
Meter=Shape
MeterStyle=RectangleStyle
Y=5R
Hidden=([MeasureShow]<9)
Here are ten rectangles and the skin shows them up one by one. Is this looking as what do you expect?
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm
Contact:

Re: [Help] creating a new rectangle with every for loop

Post by death.crafter »

balala wrote: October 3rd, 2021, 3:23 pm Unfortunately this is very hard (or practically impossible) to be done in Rainmeter.

I don't think it does worth to work with lua in this case, however it is possible.
Are you sure?
Kea wrote: October 2nd, 2021, 9:18 pm Thank you, I'll try it out but I think Im going to do most of the stuff in lua since Im way more familiar with it's structure.
Late to the party but here is the script:

Code: Select all

function AddRectangle(meter)
	i = 1
	while SKIN:GetMeter(meter):GetOption('Shape'.. (i == 1 and '' or i)) ~= '' do
		i=i+1
	end
	SKIN:Bang('!SetOption', meter, 'Shape'.. (i==1 and '' or i), 'Rectangle x, y, w, h, r1, r2 | Attributes')
	SKIN:Bang('!UpdateMeter', meter)
	SKIN:Bang('!Redraw')
end

function RemoveRectangle(meter)
	i = 2
	while SKIN:GetMeter(meter):GetOption('Shape'.. (i == 1 and '' or i)) ~= '' do
		i=i+1
	end
	i = i-1
	SKIN:Bang('!SetOption', meter, 'Shape'.. (i == 1 and '' or i), '')
	SKIN:Bang('!UpdateMeter', meter)
	SKIN:Bang('!Redraw')
end

Code: Select all

[MeterShape]
Meter=Shape
Shape=Rectangle x,y,w,h,r1,r2 | Attributes
LeftMouseUpAction=[!CommandMeasure Lua "AddRectangle('#CURRENTSECTION#')"]
RightMouseUpAction=[!CommandMeasure Lua "RemoveRectangle('#CURRENTSECTION#')"]
Well, it's just bare bones. But you seem familiar, so you can modify it at will. ;-)
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [Help] creating a new rectangle with every for loop

Post by balala »

death.crafter wrote: October 3rd, 2021, 5:21 pm Are you sure?
You quoted two sentences. Which one are you asking about if I am sure?
Post Reply