Setting Button Background Color via Command?

I've got a button that I set to only show up when flat view is enabled, and I gave it a pale red background color so it sort of stands out compared to permanent buttons:
image

But the coloring doesn't look good in dark mode:
image

I was trying to see if there was a way to change the background color via command like there seems to be with the label text using the @label modifier.

Though as a side note I haven't quite figured out how to use the @if modifiers yet, like I was testing like this but I must be doing something wrong, it only shows the 'Off' version:

@if:Set DARKMODE=on
@label "Test - Dark On"
@if:else
@label "Test - Dark Off"

In any case I'm able to get it to work by simply making two separate buttons with different colors and using @hideif (Like @hideif:Set DARKMODE=off ), but I was wondering if there's a more direct way to do it.

I don't think there is. Not my area of expertise, though :wink:

@if gets evaluated at runtime, so the second @label overwrites the first one.

Try

@label:IsEnabled("Set DARKMODE=on") ? "Test - Dark On" : "Test - Dark Off"

@label:IsEnabled("Set DARKMODE=on") ? "Test - Dark On" : "Test - Dark Off"

Hm that doesn't seem to work for me either, it always ends up showing the left value

Ah, yes, sorry, wrong function :sweat:

@label:IsChecked("Set DARKMODE=on") ? "Test - Dark On" : "Test - Dark Off"
1 Like

If you set the button's label color as well as the background, that should fix it.

If you set the button's label color as well as the background, that should fix it.

Ah ok setting the text color to black did make the text readable in dark mode.

I was more looking to make it look like the version on the right though in dark mode, which I current have with the separate button:
image

@label:IsChecked("Set DARKMODE=on") ? "Test - Dark On" : "Test - Dark Off"

Cool that one works!

1 Like

We'll add the ability to change colors dynamically via the evaluator in 13.7.1.

1 Like

Awesome that will come in handy!

The new feature works great in the new beta 13.7.1

Here's an example for what I did to set color based on dark mode
@color:IsChecked("Set DARKMODE=on") ? back="#390000" : back="#ffe6e6"

Where the #390000 and #FFE6E6 hex color values are for whether dark mode is on or off respectively.

An example of setting the colors directly without a conditional:
@color:text = "#FF0000"; back = "#FFFF00";

1 Like

Adding to the examples, you could use this to set both text and background colors on one line, for dark and light modes:

@color:=SysInfo("DarkMode") ? { text="#ff0000"; back="#ffff00"; } : { text="#0000ff"; back="#00ffff"; }

(I've added that to the manual page to make it easier to find.)

1 Like