It is currently April 20th, 2024, 12:08 pm

How to use relative position within a ternary check (in order to design a grid with customizable column count)

Get help with creating, editing & fixing problems with skins
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by MetalTxus »

I'm working on a grid system, which depends on a column count. Each time we have n columns on a row, we move on to the next row. However, Rainmeter doesn't understand the code. This is what I have (irrelevant pieces of code have been removed to avoid noise):

Code: Select all

[Variables]
meterWidth = 1920
colCount = 5
coverWidth = (#meterWidth# / #colCount#)
coverHeight = (#coverWidth# * 215 / 460)

[1]
X = 0
Y = 0

[2]
X = (1 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(1 / #colCount#)) * #coverHeight#

[3]
X = (2 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(2 / #colCount#)) * #coverHeight#

[4]
X = (3 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(3 / #colCount#)) * #coverHeight#

[5]
X = (4 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(4 / #colCount#)) * #coverHeight#

[6]
X = (5 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(5 / #colCount#)) * #coverHeight#

[7]
X = (6 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(6 / #colCount#)) * #coverHeight#

[8]
X = (7 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(7 / #colCount#)) * #coverHeight#

[9]
X = (8 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(8 / #colCount#)) * #coverHeight#

[10]
X = (9 % #colCount# = 0 ? 0 : #coverWidth#r)
Y = (Floor(9 / #colCount#)) * #coverHeight#
...but the log always complains it doesn't know the value for "r" in "(n % #colCount# = 0 ? 0 : #coverWidth#r)"

Any idea how to deal with this?
This is the approach with which I got furthest with but I'm open to alternatives too.
Last edited by MetalTxus on July 25th, 2017, 6:47 pm, edited 2 times in total.
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by jsmorley »

Mathematical formulas can ONLY consist of numbers, operators and mathematical functions. No result of a math formula, nor any component of a math formula can be a string like "r".

So try moving the "r" outside the parentheses.

X = (1 % #colCount# = 0 ? 0 : #coverWidth#)r

Make sure all the "math" is inside parentheses, and any "r" or "R" is outside.

Code: Select all

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

[MeterOne]
Meter=String
X=0
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=One

[MeterTwo]
Meter=String
X=(10+5)R
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Two
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by balala »

EDIT: jsmorly, probably you know what I want to mention here...

Normally, because r must be preceded by one single number.
Move the r after the parenthesis. Eg for meter [2] use: X=(1%#colCount#=0?0:#coverWidth#)r
Here I also removed the unnecessary spaces.
Last edited by balala on July 25th, 2017, 6:11 pm, edited 1 time in total.
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by MetalTxus »

jsmorley wrote:Try moving the "r" outside the parentheses.
X = (1 % #colCount# = 0 ? 0 : #coverWidth#)r
But that would replace the "X = 0" with "X = 0r" when n = 5 and the new line wouldn't start at the beginning.
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by jsmorley »

MetalTxus wrote:But that would replace the "X = 0" with "X = 0r" when n = 5 and the new line wouldn't start at the beginning.
I don't understand.

No matter what, a ternary condition is going to end up resolving to one number.

X = (1 % #colCount# = 0 ? 0 : #coverWidth#)r

So that is going to resolve to:

X=(0)r

or

X=(nn)r
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by MetalTxus »

Maybe it's clearer with a picture:
Image
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by jsmorley »

If what you are saying is that in:

X = (1 % #colCount# = 0 ? 0 : #coverWidth#)r

if the answer is "0", then you don't want the "r" at all, but just want X to be X=0, then you won't be able to use relative positioning with "r" and "R". You simply can't include a string in a formula.

You would need to instead include [SectionVariables:W] [SectionVariables:X] in the formulas to use the positions and sizes of other meters in your definition of the X.

So something like:

X = (1 % #colCount# = 0 ? 0 : [PreviousMeterName:X]+#coverWidth#)
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by balala »

MetalTxus wrote:But that would replace the "X = 0" with "X = 0r" when n = 5 and the new line wouldn't start at the beginning.
If I understood well what you want, I think you should use absolute positioning, instead of relative one. Simply remove the r: X=(1%#colCount#=0?0:#coverWidth#).
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by MetalTxus »

Maybe I could use (#meterWidth# / (#colCount# - 1)) to compensate for the current position but it feels like a dirty hack:/
balala wrote:If I understood well what you want, I think you should use absolute positioning, instead of relative one. Simply remove the r: X=(1%#colCount#=0?0:#coverWidth#).
The idea was for it to be absolute when n % #colCount# = 0 but relative otherwise.
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to use relative position within a ternary check (in order to design a grid with customizable column count)

Post by jsmorley »

X = (1 % #colCount# = 0 ? 0 : [PreviousMeterName:X]+#coverWidth#)
DynamicVariables=1