Unable to use add_theme_color_override() on a Button
Asked Answered
S

5

0

Edit: Resolved ! See my last comment

I want to change the font color of a button when I press on hit. So I call add_theme_color_override("font_color", Color.RED) in the function called when I press a button (with "button_up"), and it doesn't change the normal font color of the button to red when I press the button and that I unhover it.

However, it works if I override the "font_hover_color", or if I override "font_color" by pressing on another button (that I press on without hovering the button that change color). So it seems to me that calling add_theme_color_override only works for the current state / DrawMode of the button (hovered vs normal, in my case).

Am I missing something ?

Spiffy answered 23/2, 2024 at 20:45 Comment(0)
B
0

Spiffy have you perhaps tried checking the button state and then altering the font color based on the state? Like:

func _process(delta):
if button_up.pressed:
       button_up.add_theme_color_override("font_color", Color.RED)

Note: you don't have to do this in delta, you could just make a custom signal like this:

bool _upIsPressed

func _process(delta):
if _upIsPressed:
       add_theme_color_override("font_color", Color.RED)
Bolshevist answered 23/2, 2024 at 20:55 Comment(0)
S
0

Bolshevist
"button_up" and "pressed" are two signals. I don't understand what you mean with "if button_up.pressed:"

Spiffy answered 23/2, 2024 at 21:52 Comment(0)
B
0

Spiffy whoops. I meant to say make a bool. Sorry. My brain is a mess this week. I edited my post and typed what I meant.

The button signal occurs when you press but if you check it each frame, the color sticks. Now you don't want to use this method with large objects, but text color shouldn't slow down anything whatsoever. (Also you can check if the color is correct so it's not trying to load it each frame, but honestly, this works for me in smaller apps.)

Bolshevist answered 24/2, 2024 at 17:49 Comment(0)
S
1

Bolshevist Thank you ! I see your solution, but setting the color override at each _process wasn't solving my case.
But I found the issue : after having pressed the button, it was in "focus" mode, meaning that is wasn't using the normal "font_color" override, but rather the "font_focus_color", that I also need to set to make it work as intended.

Spiffy answered 26/2, 2024 at 3:29 Comment(0)
B
0

Spiffy sometimes looking at a problem from different angles helps - I know this too well. Glad you figured it out!!!

Bolshevist answered 27/2, 2024 at 18:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.