It is currently April 16th, 2024, 11:37 pm

Color text

Get help with creating, editing & fixing problems with skins
User avatar
Xdominanta
Posts: 16
Joined: January 31st, 2021, 3:38 pm

Color text

Post by Xdominanta »

Please tell me how it is correct to display text on one line so that letters are of different colors?
For example: Hello
H- green
e - yellow
l - red
o - blue
Is it possible to do this with a string variable?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Color text

Post by jsmorley »

Xdominanta wrote: February 13th, 2021, 8:27 am Please tell me how it is correct to display text on one line so that letters are of different colors?
For example: Hello
H- green
e - yellow
l - red
o - blue
Is it possible to do this with a string variable?
https://docs.rainmeter.net/manual/meters/string/inline/

Code: Select all

[MeterExample]
Meter=String
FontSize=30
FontWeight=400
InlineSetting=Color | 127,255,128,255
InlinePattern=H
InlineSetting2=Color | 254,253,87,255
InlinePattern2=e
InlineSetting3=Color | 255,81,80,255
InlinePattern3=l
InlineSetting4=Color | 149,214,255,255
InlinePattern4=o
SolidColor=0,0,0,255
Padding=5,5,5,5
AntiAlias=1
Text=Hello

1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Color text

Post by balala »

As an addition to jsmorley's code, let's note that it can be slighly modified, in a way to get colored each letter of the string with different color. For instance the above code color the appropriate letters, but if you modify the text placed into the Text option, you have to modify the letters into the InlinePattern options as well. The following code colors each letter with different colors (the third and fourth l have different colors this time), but doesn't matter which those five letters are. Obviously the code can easily be modified to work with more letters:

Code: Select all

[MeterExample]
Meter=String
FontSize=30
FontWeight=400
InlineSetting=Color | 127,255,128,255
InlinePattern=^.{0}(.{1}).*$
InlineSetting2=Color | 254,253,87,255
InlinePattern2=^.{1}(.{1}).*$
InlineSetting3=Color | 255,81,80,255
InlinePattern3=^.{2}(.{1}).*$
InlineSetting4=Color | 149,214,255,255
InlinePattern4=^.{3}(.{1}).*$
InlineSetting5=Color | 249,24,222,255
InlinePattern5=^.{4}(.{1}).*$
SolidColor=0,0,0,255
Padding=5,5,5,5
AntiAlias=1
Text=Hello
See how the InlinePattern options have been created: each is related to one letter.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Color text

Post by jsmorley »

Or perhaps just a tad easier to follow...

Code: Select all

[MeterExample]
Meter=String
FontSize=30
FontWeight=400
FontColor=255,255,255,255
InlineSetting=Color | 127,255,128,255
InlinePattern=(H)ello
InlineSetting2=Color | 254,253,87,255
InlinePattern2=H(e)llo
InlineSetting3=Color | 255,81,80,255
InlinePattern3=He(l)lo
InlineSetting4=Color | 149,214,255,255
InlinePattern4=Hel(l)o
InlineSetting5=Color | 255,129,255,255
InlinePattern5=Hell(o)
SolidColor=0,0,0,255
Padding=5,5,5,5
AntiAlias=1
Text=He said Hello to me

1.jpg

My goal with regular expression in InlinePattern(n) is to create the pattern that uniquely and precisely targets the text you want to impact, while using the minimum amount and most simple that is possible. Having said that, there are just endless ways to attack this, and since it is just an example, and the use in the real world may be a bit more complicated, you have to take a minute to analyze what your input string is likely to be, and what it will take to isolate the text you want to impact.
You do not have the required permissions to view the files attached to this post.
User avatar
Xdominanta
Posts: 16
Joined: January 31st, 2021, 3:38 pm

Re: Color text

Post by Xdominanta »

Thanks for making my world colorful! :) !

But now I have another difficulty :(
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
MyText=Thank!
MyText2=Thank!
MyText3=Thank!

[MeterExample]
Meter=String
FontSize=30
FontWeight=400
FontColor=255,255,255,255

InlineSetting=Color | 127,255,128,255
InlinePattern=#Mytext#
InlineSetting2=Color | 254,253,87,255
InlinePattern2=#Mytext2#
InlineSetting3=Color | 255,0,0,255
InlinePattern3=#Mytext3#


SolidColor=0,0,0,255
Padding=5,5,5,5
AntiAlias=1
Text=#MyText# #MyText2# #MyText3#
DynamicVariables=1

Tell me how to turn this into a colorful variety.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Color text

Post by jsmorley »

Code: Select all

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

[Variables]
MyText=Thank!
MyText2=Thank!
MyText3=Thank!

[MeterExample]
Meter=String
FontSize=30
FontWeight=400
FontColor=255,255,255,255

InlineSetting=Color | 127,255,128,255
InlinePattern=(#MyText#) #MyText2# #MyText3#
InlineSetting2=Color | 254,253,87,255
InlinePattern2=#MyText# (#MyText2#) #MyText3#
InlineSetting3=Color | 255,0,0,255
InlinePattern3=#MyText# #MyText2# (#MyText3#)


SolidColor=0,0,0,255
Padding=5,5,5,5
AntiAlias=1
Text=#MyText# #MyText2# #MyText3#
DynamicVariables=1

1.jpg


So the trick, since all of the string variables are the same, is to do these things "in context", so you (capture) what you want based on their position in the string.
You do not have the required permissions to view the files attached to this post.
User avatar
Xdominanta
Posts: 16
Joined: January 31st, 2021, 3:38 pm

Re: Color text

Post by Xdominanta »

Fine! Nice solution! :bow:

Another off-topic question:
Is it possible to comment out the code without commenting out a piece of the line separately using;?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Color text

Post by jsmorley »

Xdominanta wrote: February 13th, 2021, 4:48 pm Fine! Nice solution! :bow:

Another off-topic question:
Is it possible to comment out the code without commenting out a piece of the line separately using;?
No. The ; comment character can only be used at the beginning of a line, and then the entire line is a comment. Any ; character after that on a line is treated as a normal character, for good or ill. It is not in any way treated as a comment character.
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Color text

Post by balala »

jsmorley wrote: February 13th, 2021, 10:02 pm No. The ; comment character can only be used at the beginning of a line, and then the entire line is a comment. Any ; character after that on a line is treated as a normal character, for good or ill. It is not in any way treated as a comment character.
Especially that there are options which are using the semicolon into their code (TransformationMatrix for instance), so there is not possible to have treat this character as a comment character inside of an option, right?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Color text

Post by jsmorley »

balala wrote: February 14th, 2021, 11:09 am Especially that there are options which are using the semicolon into their code (TransformationMatrix for instance), so there is not possible to have treat this character as a comment character inside of an option, right?
Correct. A ; semicolon is also a perfectly valid character in color gradient definitions in the Shape and String meters, as well as in the Text and ToolTip options of a String meter, the String option of a String measure, and in any regular expression. There is simply no reliable way to parse an option containing a ; semicolon other than at the beginning of the line and treat is a comment character.