Change the text colour in a text label trait

Just wondering. Is there a way to have the colour of text from a text label trait to automatically change depending on what layer level is active? I appreciate that one can use html in the text to display area or by using the standard text colour function.
I have a small counter that ‘records’ the date stamp, based on the game turn month and year, for when a particular action is chosen. The text is set to black, bold. The background colour is set, by right click context or a hotkey, via the layer trait. The colours are yellow (default), grey (Germany) or red (Japan). Black does not contrast that well with the grey (I would probably use white there) or the red (I would probably use yellow there).
As I said, more in hope than in anything else.

I’ve done this kind of thing by computing the text value (field will accept Beanshell or you could calculate the value into a property and display that). For your requirement, you would be calculating this according to the (layer)_Active property. I assume by “layer” you refer to the Layer trait rather than Game Piece Layers.

In my case, I used multiple text label traits - the ones not displaying would have a computed text value of null. It occurs to me that, if you are embedding HTML in the text value, you could calculate the colours in there.

1 Like

Sort of answered my own question by playing around. This actually works:

optionaxis==“Default”?“html>b>|$month$”:“html>b>font color=yellow>$month$”

Using a DP to get a property I called ‘textcolour’. Then in the Text Label trait I used $textcolour$.
I went for yellow for both the grey and red backgrounds. If I wanted to have different text colours for each different background colour then this also works:

optionaxis==“GE/IT”?“html>b>font color=red>$month$”:optionaxis==“JA”?“html>b>font color=yellow>$month$”:"|$month$"

Please note that I had to remove the first < for the html stuff as the post was parsing the code directly and thus hiding the html stuff

Enclose your literal text in back ticks (`) to prevent html tags from being processed:

optionaxis=="Default"?"<html><b>|$month$":"<html><b><font color=yellow>$month$"

(and also prevent your quotes from being replaced with “smart quotes”).