It is currently August 8th, 2020, 11:23 pm

Bugs with stringalign?

Report bugs with the Rainmeter application and suggest features.
soyelrafa
Posts: 96
Joined: March 1st, 2017, 3:09 pm

Bugs with stringalign?

Post by soyelrafa »

Hello, I made this simple skin to test aligns and I think there is a bug with StringAlign:

Code: Select all

[MeterShape]
Meter=Shape
Shape=Rectangle 0,0,250,50

[MeterShape2]
Meter=Shape
Shape=Rectangle 0,100,250,50

[MeterShape3]
Meter=Shape
Shape=Rectangle 0,200,250,50

[MeterString]
Meter=String
X=0
Y=0
W=250
H=50
FontColor=0,0,0,255
FontFace=Segoe UI
FontSize=17
StringEffect=Shadow
StringAlign=Left
FontEffectColor=0,0,0,255
AntiAlias=1
Text=Left

[MeterString2]
Meter=String
X=0
Y=100
W=250
H=50
FontColor=0,0,0,255
FontFace=Segoe UI
FontSize=17
StringEffect=Shadow
StringAlign=Center
FontEffectColor=0,0,0,255
AntiAlias=1
Text=Center

[MeterString3]
Meter=String
X=0
Y=200
W=250
H=50
FontColor=0,0,0,255
FontFace=Segoe UI
FontSize=17
StringEffect=Shadow
StringAlign=Right
FontEffectColor=0,0,0,255
AntiAlias=1
Text=Right
Behaviour:
StringAlign.png
Maybe I'm doing something wrong, but I think the "center" should be on the center and the "right" should appear on the right, like this:
StringAlign2.png
Because I set the same X,Y, H and W as the shape meter I think that should be the proper functioning. I am doing something wrong or this is a bug?

Rainmeter info:
Rainmeter 4.4.0.3348 beta (64-bit)
Language: Spanish (3082)
Build time: 2020-04-17 9:39:05
Commit Hash: 7756da65
Windows 10 Pro 1909 64-bit (build 18363) - Spanish (3082)
Path: C:\Program Files\Rainmeter\
SkinPath: C:\Users\User\Documents\Rainmeter\Skins\
SettingsPath: C:\Users\User\AppData\Roaming\Rainmeter\
IniFile: C:\Users\User\AppData\Roaming\Rainmeter\Rainmeter.ini
Regards.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 21218
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bugs with stringalign?

Post by jsmorley »

The entire concept of StringAlign follows these reasonably simple rules...

A string is always aligned based on the value of X you put on the meter. That is where the string begins its work.

StringAlign=Left (the default by the way)
The string starts at X, and is drawn from there out to the right.
The result is that the string begins at X, and ends where it ends based on the length of the string.
X ==========>

StringAlign=Center
The string starts at X, and is drawn 1/2 back to the left, and 1/2 out to the right.
The result is that the string is centered on X. It begins where it begins and ends where it ends based on the length of the string.
<=====X=====>

StringAlignt=Right
The string starts at X, and is drawn from there back to the left.
The result is that the string ends at X, and begins where it begins based on the length of the string.
<==========X

The only important thing to remember to use StringAlign is that it is always based on the value of X. The String meter with StringAlign is the one case where X doesn't really mean "starts at", but rather means "is anchored at".

So all I have to do is correctly set the value for X on your String meters, and Bob's Your Uncle...

Code: Select all

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

[Variables]

[MeterShape]
Meter=Shape
Shape=Rectangle 0,0,250,50

[MeterShape2]
Meter=Shape
Shape=Rectangle 0,100,250,50

[MeterShape3]
Meter=Shape
Shape=Rectangle 0,200,250,50

[MeterString]
Meter=String
X=5
Y=0
W=250
H=50
FontColor=0,0,0,255
FontFace=Segoe UI
FontSize=17
StringEffect=Shadow
StringAlign=Left
FontEffectColor=0,0,0,255
AntiAlias=1
Text=Left

[MeterString2]
Meter=String
X=125
Y=100
W=250
H=50
FontColor=0,0,0,255
FontFace=Segoe UI
FontSize=17
StringEffect=Shadow
StringAlign=Center
FontEffectColor=0,0,0,255
AntiAlias=1
Text=Center

[MeterString3]
Meter=String
X=245
Y=200
W=250
H=50
FontColor=0,0,0,255
FontFace=Segoe UI
FontSize=17
StringEffect=Shadow
StringAlign=Right
FontEffectColor=0,0,0,255
AntiAlias=1
Text=Right


1.jpg
You do not have the required permissions to view the files attached to this post.
soyelrafa
Posts: 96
Joined: March 1st, 2017, 3:09 pm

Re: Bugs with stringalign?

Post by soyelrafa »

Okay, I understand now, but I don't understand why it's better that way that the way I thought. Anyway thanks for the answer.
User avatar
jsmorley
Developer
Posts: 21218
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bugs with stringalign?

Post by jsmorley »

soyelrafa wrote:
May 8th, 2020, 2:18 pm
Okay, I understand now, but I don't understand why it's better that way that the way I thought. Anyway thanks for the answer.
Glad to help. It's this way since it is not desirable to force the alignment, for instance "center", to be in any way dependent on an explicit width of the meter. You can't always know the width of a String meter with dynamic text, and yet you still want it "centered". It has to know "centered on what?". Thus X...

As you can see in the way I corrected your code, I didn't set X using the full size of the Shape meters, as I wanted a little elbow room on the left and right. Only the way we do this can support that. If we were to somehow automatically say "ok, how wide is this meter, let's just use that", then StringAlign=Right would just jam the string all the way to the right, which in almost all cases is going to look weird.

There are no doubt other ways we could have come at this, but we are pretty happy with how this works, and the amount of control and flexibility it gives the skin author.
soyelrafa
Posts: 96
Joined: March 1st, 2017, 3:09 pm

Re: Bugs with stringalign?

Post by soyelrafa »

jsmorley wrote:
May 8th, 2020, 2:22 pm
Glad to help. It's this way since it is not desirable to force the alignment, for instance "center", to be in any way dependent on an explicit width of the meter. You can't always know the width of a String meter with dynamic text, and yet you still want it "centered". It has to know "centered on what?". Thus X...

As you can see in the way I corrected your code, I didn't set X using the full size of the Shape meters, as I wanted a little elbow room on the left and right. Only the way we do this can support that. If we were to somehow automatically say "ok, how wide is this meter, let's just use that", then StringAlign=Right would just jam the string all the way to the right, which in almost all cases is going to look weird.
Aaah, okay, now I get it. Thanks again for your explanation :)
User avatar
jsmorley
Developer
Posts: 21218
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bugs with stringalign?

Post by jsmorley »

soyelrafa wrote:
May 8th, 2020, 2:29 pm
Aaah, okay, now I get it. Thanks again for your explanation :)
Always happy to help. It's a good discussion really, and I took the opportunity to add some clarification to the documentation. So thank you for bringing it up. String alignment has a long, sordid history of confusing a lot of folks.

https://docs.rainmeter.net/manual/meters/string/#StringAlign
User avatar
balala
Rainmeter Sage
Posts: 11181
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Bugs with stringalign?

Post by balala »

jsmorley wrote:
May 8th, 2020, 2:34 pm
Always happy to help. It's a good discussion really, and I took the opportunity to add some clarification to the documentation. So thank you for bringing it up. String alignment has a long, sordid history of confusing a lot of folks.

https://docs.rainmeter.net/manual/meters/string/#StringAlign
I think some similar explanation should be posted for the vertical alignment as well. Or is it obvious if someone reads the explanation of horizontal alignment?
User avatar
jsmorley
Developer
Posts: 21218
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bugs with stringalign?

Post by jsmorley »

balala wrote:
May 8th, 2020, 4:15 pm
I think some similar explanation should be posted for the vertical alignment as well. Or is it obvious if someone reads the explanation of horizontal alignment?
Hopefully, the same thing applies with Y as it does with X.
User avatar
balala
Rainmeter Sage
Posts: 11181
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Bugs with stringalign?

Post by balala »

jsmorley wrote:
May 8th, 2020, 4:21 pm
Hopefully, the same thing applies with Y as it does with X.
Certainly. Question is if this is obvious for everyone.
User avatar
Yincognito
Posts: 2200
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Bugs with stringalign?

Post by Yincognito »

jsmorley wrote:
May 8th, 2020, 2:34 pm
Always happy to help. It's a good discussion really, and I took the opportunity to add some clarification to the documentation. So thank you for bringing it up. String alignment has a long, sordid history of confusing a lot of folks.

https://docs.rainmeter.net/manual/meters/string/#StringAlign
I'll take the opportunity of this thread to point out to a slightly incorrect behavior in a StringAlign=Center scenario. I noticed this while working on my color wheel transition skin (left click to start it, middle click to pause it):

Code: Select all

[Variables]
FastUpdate=25
SlowUpdate=1000
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
Increment=4
Direction=1
StartColor=0
Quantifier=#StartColor#
Alternator=0

[Rainmeter]
Update=#FastUpdate#
DynamicWindowSize=1
AccurateText=1

---Measures---

[Transition]
Disabled=1
Measure=Calc
Formula=((#CURRENTSECTION#+#Increment#)%256)
RegExpSubstitute=1
Substitute="^(.*)$":"(255*(1*(1+(#Direction#))/2+#Alternator#*(1-(#Direction#))/2)-((#Direction#)*(\1)*((1-(#Direction#))/2+(#Direction#)*#Alternator#))),0,(255*(1*(1-(#Direction#))/2+#Alternator#*(1+(#Direction#))/2)+((#Direction#)*(\1)*((1+(#Direction#))/2-(#Direction#)*#Alternator#))),255","^((?:[^,]*,){#Quantifier#})((?:[^,]*,)*)(.*)$":"\2\1\3","\\\d":""
IfCondition=((#CURRENTSECTION#+#Increment#)>=256)
IfTrueAction=[!SetVariable Alternator (1-#Alternator#)][!SetVariable Quantifier ((3+#Quantifier#+#Direction#*#Alternator#*1)%3)]
IfConditionMode=1
DynamicVariables=1

---Meters---

[Image]
Meter=Image
W=1100
H=100
SolidColor=[Transition]
LeftMouseUpAction=[!UnpauseMeasure Transition][!ToggleMeasure Transition][!SetVariable Quantifier #StartColor#][!SetVariable Alternator 0][!UpdateMeasure Transition][!UpdateMeter *][!Redraw]
MiddleMouseUpAction=[!TogglePauseMeasure Transition]
DynamicVariables=1

[Text]
Meter=STRING
X=([Image:W]/2)r
Y=([Image:H]/2)r
FontFace=Tahoma
FontColor=255,255,255,255
FontSize=10
FontWeight=700
AntiAlias=1
StringAlign=CenterCenter
StringEffect=Shadow
StringEffectColor=0,0,0,255
Text="TRANSITION: Color Wheel#CRLF#DIRECTION: #Direction##CRLF#START COLOR: #StartColor##CRLF#INCREMENT: #Increment##CRLF#FORMULA: [Transition]"
DynamicVariables=1
I only made it 1000 px wide so that the entire "string formula" on the last line to fit the meter / skin. The "slightly incorrect behavior" is the fact that while everything is centered, during the transition (and displaying the multiline string on the screen), the horizontal position of the whole thing "fluctuates" left and right by some small margin (1px, if I'm not mistaken). What could be the cause of that? Some rounding thing maybe? Is this the expected behavior? If not, could it be fixed or it's just something that I missed and everything should behave correctly otherwise?