I’m trying to change the style of a button via code. I’ve made a custom theme, it has styles for when a button is “focused”, “hovered” and so on. I want the button, when pressed, to keep the “pressed” style (until my fading animation finishes and the scene changes).
I know I could set the values of the button’s style manually, overriding the “normal” style to be like the “pressed” one, but it’s a hassle ! I would need to store in variables the color, background and so on, and it would nearly defeat the purpose of the built-in themes.
I tried looking at the button doc and didn’t find a way to tell the button which style it should currently display.
Does someone knows how to access that ?
To clarify things, I’m looking for something like that :
button.style = style.pressed
I tried right now, and it doesn’t change the style’s behaviour.
To be sure, the code you’re expecting me to put when the button is pressed would look like : button.MOUSE_FILTER_IGNORE or did I misunderstood something ? (Of course I did put the button as toggle, as you told me)
I don’t see how it would solve things ? I would still have to register the color values and so on to tell the tween what end values it should be aiming for, no ?
Your previous code should give a warning something like: “Standalone expression (the line has no effect).” You can change the severity to error in the project settings if you want. Just search for “standalone expression”.
It’s really hard to tell apart the button states to be honest. How is the pressed state supposed to look?
Everything that appears (border and font) are darker, like a richer brown
I mean, I know it doesn’t matter much, everything works fine, the transition is clear with the position animations I’ve put and the black screen fading in… But I’m a bit frustrated. Shouldn’t something like setting the states of the button in code be easily accessible ?
I’m no engine programmer, though, so I can’t complain too loudly
My brain is fried for the day. I’ll look more into it another time. Though, the more I think of it, the more your solution appears fitting, so I’ll mark it as the answer. Theoretically it should work, and it works for you. I must have something else going on in my project, maybe in my animation or whatever. Thank you anyway for sticking with me !!
You can also use some other nodes like Panel, or textureRect, you style these and then you can program the onclick event in a personalized way, that way when you click you wait for the animation to finish and then you make the scene change, or whatever what do you want me to do. I really hope you can fix it
The problem in that solution is that what it does is maintain a texture when the button is pressed, and what you want is that when you click the button it waits for an animation to occur and then does something