Multiple styles for the same Control type in a single theme

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jahu00

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

:bust_in_silhouette: Reply From: njamster

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.