0 votes

In my game I want to style panels in 2 different ways (or maybe even more in the future). Can I store styles for those in a single theme?

I know I can add multiple styles for the same control type in the theme using "Add item" option and naming the second style differently, but can I actually use the second style? My panel controls only seem to be interested in using the style named Panel.

For a second I thought I might be able to use the Style property of my Panel to select which style to use, but it appears I can only use this to explicitly override the style for the control (not select which style in the theme to use).

in Engine by (61 points)

1 Answer

+1 vote

But can I actually use the second style?

From the GUI: no, I don't think so. It can be easily done form code though:

extends Panel

const STYLENAME = "Green"

func _ready():
    var style = get_theme().get_stylebox(STYLENAME, "Panel")
    add_stylebox_override("panel", style)

Here I named the alternative style "Green" - of course you can name it differently.

by (10,584 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.