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).

asked Jun 21 in Engine by jahu00 (45 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.

answered Jun 22 by njamster (8,874 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 How to use this Q&A? before posting your first questions.