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?
It is currently April 20th, 2024, 5:41 am
Color text
-
- Posts: 16
- Joined: January 31st, 2021, 3:38 pm
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Color text
https://docs.rainmeter.net/manual/meters/string/inline/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?
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
You do not have the required permissions to view the files attached to this post.
-
- Rainmeter Sage
- Posts: 16147
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Color text
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:
See how the InlinePattern options have been created: each is related to one letter.
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
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Color text
Or perhaps just a tad easier to follow...
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.
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
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.
-
- Posts: 16
- Joined: January 31st, 2021, 3:38 pm
Re: Color text
Thanks for making my world colorful! !
But now I have another difficulty
Tell me how to turn this into a colorful variety.
But now I have another difficulty
Tell me how to turn this into a colorful variety.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Color text
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
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.
-
- Posts: 16
- Joined: January 31st, 2021, 3:38 pm
Re: Color text
Fine! Nice solution!
Another off-topic question:
Is it possible to comment out the code without commenting out a piece of the line separately using;?
Another off-topic question:
Is it possible to comment out the code without commenting out a piece of the line separately using;?
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Color text
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.Xdominanta wrote: ↑February 13th, 2021, 4:48 pm Fine! Nice solution!
Another off-topic question:
Is it possible to comment out the code without commenting out a piece of the line separately using;?
-
- Rainmeter Sage
- Posts: 16147
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Color text
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?
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Color text
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.