Theme

Inherits:Resource<RefCounted<Object

A resource used for styling/skinningControls andWindows.

Description

A resource used for styling/skinningControl andWindow nodes. While individual controls can be styled using their local theme overrides (seeControl.add_theme_color_override()), theme resources allow you to store and apply the same settings across all controls sharing the same type (e.g. style allButtons the same). One theme resource can be used for the entire project, but you can also set a separate theme resource to a branch of control nodes. A theme resource assigned to a control applies to the control itself, as well as all of its direct and indirect children (as long as a chain of controls is uninterrupted).

UseProjectSettings.gui/theme/custom to set up a project-scope theme that will be available to every control in your project.

UseControl.theme of any control node to set up a theme that will be available to that control and all of its direct and indirect children.

Tutorials

Properties

float

default_base_scale

0.0

Font

default_font

int

default_font_size

-1

Methods

void

add_type(theme_type:StringName)

void

clear()

void

clear_color(name:StringName, theme_type:StringName)

void

clear_constant(name:StringName, theme_type:StringName)

void

clear_font(name:StringName, theme_type:StringName)

void

clear_font_size(name:StringName, theme_type:StringName)

void

clear_icon(name:StringName, theme_type:StringName)

void

clear_stylebox(name:StringName, theme_type:StringName)

void

clear_theme_item(data_type:DataType, name:StringName, theme_type:StringName)

void

clear_type_variation(theme_type:StringName)

Color

get_color(name:StringName, theme_type:StringName)const

PackedStringArray

get_color_list(theme_type:String)const

PackedStringArray

get_color_type_list()const

int

get_constant(name:StringName, theme_type:StringName)const

PackedStringArray

get_constant_list(theme_type:String)const

PackedStringArray

get_constant_type_list()const

Font

get_font(name:StringName, theme_type:StringName)const

PackedStringArray

get_font_list(theme_type:String)const

int

get_font_size(name:StringName, theme_type:StringName)const

PackedStringArray

get_font_size_list(theme_type:String)const

PackedStringArray

get_font_size_type_list()const

PackedStringArray

get_font_type_list()const

Texture2D

get_icon(name:StringName, theme_type:StringName)const

PackedStringArray

get_icon_list(theme_type:String)const

PackedStringArray

get_icon_type_list()const

StyleBox

get_stylebox(name:StringName, theme_type:StringName)const

PackedStringArray

get_stylebox_list(theme_type:String)const

PackedStringArray

get_stylebox_type_list()const

Variant

get_theme_item(data_type:DataType, name:StringName, theme_type:StringName)const

PackedStringArray

get_theme_item_list(data_type:DataType, theme_type:String)const

PackedStringArray

get_theme_item_type_list(data_type:DataType)const

PackedStringArray

get_type_list()const

StringName

get_type_variation_base(theme_type:StringName)const

PackedStringArray

get_type_variation_list(base_type:StringName)const

bool

has_color(name:StringName, theme_type:StringName)const

bool

has_constant(name:StringName, theme_type:StringName)const

bool

has_default_base_scale()const

bool

has_default_font()const

bool

has_default_font_size()const

bool

has_font(name:StringName, theme_type:StringName)const

bool

has_font_size(name:StringName, theme_type:StringName)const

bool

has_icon(name:StringName, theme_type:StringName)const

bool

has_stylebox(name:StringName, theme_type:StringName)const

bool

has_theme_item(data_type:DataType, name:StringName, theme_type:StringName)const

bool

is_type_variation(theme_type:StringName, base_type:StringName)const

void

merge_with(other:Theme)

void

remove_type(theme_type:StringName)

void

rename_color(old_name:StringName, name:StringName, theme_type:StringName)

void

rename_constant(old_name:StringName, name:StringName, theme_type:StringName)

void

rename_font(old_name:StringName, name:StringName, theme_type:StringName)

void

rename_font_size(old_name:StringName, name:StringName, theme_type:StringName)

void

rename_icon(old_name:StringName, name:StringName, theme_type:StringName)

void

rename_stylebox(old_name:StringName, name:StringName, theme_type:StringName)

void

rename_theme_item(data_type:DataType, old_name:StringName, name:StringName, theme_type:StringName)

void

set_color(name:StringName, theme_type:StringName, color:Color)

void

set_constant(name:StringName, theme_type:StringName, constant:int)

void

set_font(name:StringName, theme_type:StringName, font:Font)

void

set_font_size(name:StringName, theme_type:StringName, font_size:int)

void

set_icon(name:StringName, theme_type:StringName, texture:Texture2D)

void

set_stylebox(name:StringName, theme_type:StringName, texture:StyleBox)

void

set_theme_item(data_type:DataType, name:StringName, theme_type:StringName, value:Variant)

void

set_type_variation(theme_type:StringName, base_type:StringName)


Enumerations

enumDataType:🔗

DataTypeDATA_TYPE_COLOR =0

Theme'sColor item type.

DataTypeDATA_TYPE_CONSTANT =1

Theme's constant item type.

DataTypeDATA_TYPE_FONT =2

Theme'sFont item type.

DataTypeDATA_TYPE_FONT_SIZE =3

Theme's font size item type.

DataTypeDATA_TYPE_ICON =4

Theme's iconTexture2D item type.

DataTypeDATA_TYPE_STYLEBOX =5

Theme'sStyleBox item type.

DataTypeDATA_TYPE_MAX =6

Maximum value for the DataType enum.


Property Descriptions

floatdefault_base_scale =0.0🔗

The default base scale factor of this theme resource. Used by some controls to scale their visual properties based on the global scale factor. If this value is set to0.0, the global scale factor is used (seeThemeDB.fallback_base_scale).

Usehas_default_base_scale() to check if this value is valid.


Fontdefault_font🔗

The default font of this theme resource. Used as the default value when trying to fetch a font resource that doesn't exist in this theme or is in invalid state. If the default font is also missing or invalid, the engine fallback value is used (seeThemeDB.fallback_font).

Usehas_default_font() to check if this value is valid.


intdefault_font_size =-1🔗

The default font size of this theme resource. Used as the default value when trying to fetch a font size value that doesn't exist in this theme or is in invalid state. If the default font size is also missing or invalid, the engine fallback value is used (seeThemeDB.fallback_font_size).

Values below1 are invalid and can be used to unset the property. Usehas_default_font_size() to check if this value is valid.


Method Descriptions

voidadd_type(theme_type:StringName)🔗

Adds an empty theme type for every valid data type.

Note: Empty types are not saved with the theme. This method only exists to perform in-memory changes to the resource. Use availableset_* methods to add theme items.


voidclear()🔗

Removes all the theme properties defined on the theme resource.


voidclear_color(name:StringName, theme_type:StringName)🔗

Removes theColor property defined byname andtheme_type, if it exists.

Fails if it doesn't exist. Usehas_color() to check for existence.


voidclear_constant(name:StringName, theme_type:StringName)🔗

Removes the constant property defined byname andtheme_type, if it exists.

Fails if it doesn't exist. Usehas_constant() to check for existence.


voidclear_font(name:StringName, theme_type:StringName)🔗

Removes theFont property defined byname andtheme_type, if it exists.

Fails if it doesn't exist. Usehas_font() to check for existence.


voidclear_font_size(name:StringName, theme_type:StringName)🔗

Removes the font size property defined byname andtheme_type, if it exists.

Fails if it doesn't exist. Usehas_font_size() to check for existence.


voidclear_icon(name:StringName, theme_type:StringName)🔗

Removes the icon property defined byname andtheme_type, if it exists.

Fails if it doesn't exist. Usehas_icon() to check for existence.


voidclear_stylebox(name:StringName, theme_type:StringName)🔗

Removes theStyleBox property defined byname andtheme_type, if it exists.

Fails if it doesn't exist. Usehas_stylebox() to check for existence.


voidclear_theme_item(data_type:DataType, name:StringName, theme_type:StringName)🔗

Removes the theme property ofdata_type defined byname andtheme_type, if it exists.

Fails if it doesn't exist. Usehas_theme_item() to check for existence.

Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.


voidclear_type_variation(theme_type:StringName)🔗

Unmarkstheme_type as being a variation of another theme type. Seeset_type_variation().


Colorget_color(name:StringName, theme_type:StringName)const🔗

Returns theColor property defined byname andtheme_type, if it exists.

Returns the default color value if the property doesn't exist. Usehas_color() to check for existence.


PackedStringArrayget_color_list(theme_type:String)const🔗

Returns a list of names forColor properties defined withtheme_type. Useget_color_type_list() to get a list of possible theme type names.


PackedStringArrayget_color_type_list()const🔗

Returns a list of all unique theme type names forColor properties. Useget_type_list() to get a list of all unique theme types.


intget_constant(name:StringName, theme_type:StringName)const🔗

Returns the constant property defined byname andtheme_type, if it exists.

Returns0 if the property doesn't exist. Usehas_constant() to check for existence.


PackedStringArrayget_constant_list(theme_type:String)const🔗

Returns a list of names for constant properties defined withtheme_type. Useget_constant_type_list() to get a list of possible theme type names.


PackedStringArrayget_constant_type_list()const🔗

Returns a list of all unique theme type names for constant properties. Useget_type_list() to get a list of all unique theme types.


Fontget_font(name:StringName, theme_type:StringName)const🔗

Returns theFont property defined byname andtheme_type, if it exists.

Returns the default theme font if the property doesn't exist and the default theme font is set up (seedefault_font). Usehas_font() to check for existence of the property andhas_default_font() to check for existence of the default theme font.

Returns the engine fallback font value, if neither exist (seeThemeDB.fallback_font).


PackedStringArrayget_font_list(theme_type:String)const🔗

Returns a list of names forFont properties defined withtheme_type. Useget_font_type_list() to get a list of possible theme type names.


intget_font_size(name:StringName, theme_type:StringName)const🔗

Returns the font size property defined byname andtheme_type, if it exists.

Returns the default theme font size if the property doesn't exist and the default theme font size is set up (seedefault_font_size). Usehas_font_size() to check for existence of the property andhas_default_font_size() to check for existence of the default theme font.

Returns the engine fallback font size value, if neither exist (seeThemeDB.fallback_font_size).


PackedStringArrayget_font_size_list(theme_type:String)const🔗

Returns a list of names for font size properties defined withtheme_type. Useget_font_size_type_list() to get a list of possible theme type names.


PackedStringArrayget_font_size_type_list()const🔗

Returns a list of all unique theme type names for font size properties. Useget_type_list() to get a list of all unique theme types.


PackedStringArrayget_font_type_list()const🔗

Returns a list of all unique theme type names forFont properties. Useget_type_list() to get a list of all unique theme types.


Texture2Dget_icon(name:StringName, theme_type:StringName)const🔗

Returns the icon property defined byname andtheme_type, if it exists.

Returns the engine fallback icon value if the property doesn't exist (seeThemeDB.fallback_icon). Usehas_icon() to check for existence.


PackedStringArrayget_icon_list(theme_type:String)const🔗

Returns a list of names for icon properties defined withtheme_type. Useget_icon_type_list() to get a list of possible theme type names.


PackedStringArrayget_icon_type_list()const🔗

Returns a list of all unique theme type names for icon properties. Useget_type_list() to get a list of all unique theme types.


StyleBoxget_stylebox(name:StringName, theme_type:StringName)const🔗

Returns theStyleBox property defined byname andtheme_type, if it exists.

Returns the engine fallback stylebox value if the property doesn't exist (seeThemeDB.fallback_stylebox). Usehas_stylebox() to check for existence.


PackedStringArrayget_stylebox_list(theme_type:String)const🔗

Returns a list of names forStyleBox properties defined withtheme_type. Useget_stylebox_type_list() to get a list of possible theme type names.


PackedStringArrayget_stylebox_type_list()const🔗

Returns a list of all unique theme type names forStyleBox properties. Useget_type_list() to get a list of all unique theme types.


Variantget_theme_item(data_type:DataType, name:StringName, theme_type:StringName)const🔗

Returns the theme property ofdata_type defined byname andtheme_type, if it exists.

Returns the engine fallback value if the property doesn't exist (seeThemeDB). Usehas_theme_item() to check for existence.

Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.


PackedStringArrayget_theme_item_list(data_type:DataType, theme_type:String)const🔗

Returns a list of names for properties ofdata_type defined withtheme_type. Useget_theme_item_type_list() to get a list of possible theme type names.

Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.


PackedStringArrayget_theme_item_type_list(data_type:DataType)const🔗

Returns a list of all unique theme type names fordata_type properties. Useget_type_list() to get a list of all unique theme types.

Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.


PackedStringArrayget_type_list()const🔗

Returns a list of all unique theme type names. Use the appropriateget_*_type_list method to get a list of unique theme types for a single data type.


StringNameget_type_variation_base(theme_type:StringName)const🔗

Returns the name of the base theme type iftheme_type is a valid variation type. Returns an empty string otherwise.


PackedStringArrayget_type_variation_list(base_type:StringName)const🔗

Returns a list of all type variations for the givenbase_type.


boolhas_color(name:StringName, theme_type:StringName)const🔗

Returnstrue if theColor property defined byname andtheme_type exists.

Returnsfalse if it doesn't exist. Useset_color() to define it.


boolhas_constant(name:StringName, theme_type:StringName)const🔗

Returnstrue if the constant property defined byname andtheme_type exists.

Returnsfalse if it doesn't exist. Useset_constant() to define it.


boolhas_default_base_scale()const🔗

Returnstrue ifdefault_base_scale has a valid value.

Returnsfalse if it doesn't. The value must be greater than0.0 to be considered valid.


boolhas_default_font()const🔗

Returnstrue ifdefault_font has a valid value.

Returnsfalse if it doesn't.


boolhas_default_font_size()const🔗

Returnstrue ifdefault_font_size has a valid value.

Returnsfalse if it doesn't. The value must be greater than0 to be considered valid.


boolhas_font(name:StringName, theme_type:StringName)const🔗

Returnstrue if theFont property defined byname andtheme_type exists, or if the default theme font is set up (seehas_default_font()).

Returnsfalse if neither exist. Useset_font() to define the property.


boolhas_font_size(name:StringName, theme_type:StringName)const🔗

Returnstrue if the font size property defined byname andtheme_type exists, or if the default theme font size is set up (seehas_default_font_size()).

Returnsfalse if neither exist. Useset_font_size() to define the property.


boolhas_icon(name:StringName, theme_type:StringName)const🔗

Returnstrue if the icon property defined byname andtheme_type exists.

Returnsfalse if it doesn't exist. Useset_icon() to define it.


boolhas_stylebox(name:StringName, theme_type:StringName)const🔗

Returnstrue if theStyleBox property defined byname andtheme_type exists.

Returnsfalse if it doesn't exist. Useset_stylebox() to define it.


boolhas_theme_item(data_type:DataType, name:StringName, theme_type:StringName)const🔗

Returnstrue if the theme property ofdata_type defined byname andtheme_type exists.

Returnsfalse if it doesn't exist. Useset_theme_item() to define it.

Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.


boolis_type_variation(theme_type:StringName, base_type:StringName)const🔗

Returnstrue iftheme_type is marked as a variation ofbase_type.


voidmerge_with(other:Theme)🔗

Adds missing and overrides existing definitions with values from theother theme resource.

Note: This modifies the current theme. If you want to merge two themes together without modifying either one, create a new empty theme and merge the other two into it one after another.


voidremove_type(theme_type:StringName)🔗

Removes the theme type, gracefully discarding defined theme items. If the type is a variation, this information is also erased. If the type is a base for type variations, those variations lose their base.


voidrename_color(old_name:StringName, name:StringName, theme_type:StringName)🔗

Renames theColor property defined byold_name andtheme_type toname, if it exists.

Fails if it doesn't exist, or if a similar property with the new name already exists. Usehas_color() to check for existence, andclear_color() to remove the existing property.


voidrename_constant(old_name:StringName, name:StringName, theme_type:StringName)🔗

Renames the constant property defined byold_name andtheme_type toname, if it exists.

Fails if it doesn't exist, or if a similar property with the new name already exists. Usehas_constant() to check for existence, andclear_constant() to remove the existing property.


voidrename_font(old_name:StringName, name:StringName, theme_type:StringName)🔗

Renames theFont property defined byold_name andtheme_type toname, if it exists.

Fails if it doesn't exist, or if a similar property with the new name already exists. Usehas_font() to check for existence, andclear_font() to remove the existing property.


voidrename_font_size(old_name:StringName, name:StringName, theme_type:StringName)🔗

Renames the font size property defined byold_name andtheme_type toname, if it exists.

Fails if it doesn't exist, or if a similar property with the new name already exists. Usehas_font_size() to check for existence, andclear_font_size() to remove the existing property.


voidrename_icon(old_name:StringName, name:StringName, theme_type:StringName)🔗

Renames the icon property defined byold_name andtheme_type toname, if it exists.

Fails if it doesn't exist, or if a similar property with the new name already exists. Usehas_icon() to check for existence, andclear_icon() to remove the existing property.


voidrename_stylebox(old_name:StringName, name:StringName, theme_type:StringName)🔗

Renames theStyleBox property defined byold_name andtheme_type toname, if it exists.

Fails if it doesn't exist, or if a similar property with the new name already exists. Usehas_stylebox() to check for existence, andclear_stylebox() to remove the existing property.


voidrename_theme_item(data_type:DataType, old_name:StringName, name:StringName, theme_type:StringName)🔗

Renames the theme property ofdata_type defined byold_name andtheme_type toname, if it exists.

Fails if it doesn't exist, or if a similar property with the new name already exists. Usehas_theme_item() to check for existence, andclear_theme_item() to remove the existing property.

Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.


voidset_color(name:StringName, theme_type:StringName, color:Color)🔗

Creates or changes the value of theColor property defined byname andtheme_type. Useclear_color() to remove the property.


voidset_constant(name:StringName, theme_type:StringName, constant:int)🔗

Creates or changes the value of the constant property defined byname andtheme_type. Useclear_constant() to remove the property.


voidset_font(name:StringName, theme_type:StringName, font:Font)🔗

Creates or changes the value of theFont property defined byname andtheme_type. Useclear_font() to remove the property.


voidset_font_size(name:StringName, theme_type:StringName, font_size:int)🔗

Creates or changes the value of the font size property defined byname andtheme_type. Useclear_font_size() to remove the property.


voidset_icon(name:StringName, theme_type:StringName, texture:Texture2D)🔗

Creates or changes the value of the icon property defined byname andtheme_type. Useclear_icon() to remove the property.


voidset_stylebox(name:StringName, theme_type:StringName, texture:StyleBox)🔗

Creates or changes the value of theStyleBox property defined byname andtheme_type. Useclear_stylebox() to remove the property.


voidset_theme_item(data_type:DataType, name:StringName, theme_type:StringName, value:Variant)🔗

Creates or changes the value of the theme property ofdata_type defined byname andtheme_type. Useclear_theme_item() to remove the property.

Fails if thevalue type is not accepted bydata_type.

Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.


voidset_type_variation(theme_type:StringName, base_type:StringName)🔗

Markstheme_type as a variation ofbase_type.

This addstheme_type as a suggested option forControl.theme_type_variation on aControl that is of thebase_type class.

Variations can also be nested, i.e.base_type can be another variation. If a chain of variations ends with abase_type matching the class of theControl, the whole chain is going to be suggested as options.

Note: Suggestions only show up if this theme resource is set as the project default theme. SeeProjectSettings.gui/theme/custom.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.