Class Theme
- Namespace
- Godot
- Assembly
- GodotSharp.dll
A resource used for styling/skinning Control and Window nodes. While individual controls can be styled using their local theme overrides (see AddThemeColorOverride(StringName, Color)), theme resources allow you to store and apply the same settings across all controls sharing the same type (e.g. style all Buttons 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).
Use ProjectSettings.gui/theme/custom
to set up a project-scope theme that will be available to every control in your project.
Use 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.
public class Theme : Resource, IDisposable
- Inheritance
-
Theme
- Implements
- Inherited Members
Constructors
Theme()
public Theme()
Properties
DefaultBaseScale
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 to 0.0
, the global scale factor is used (see FallbackBaseScale).
Use HasDefaultBaseScale() to check if this value is valid.
public float DefaultBaseScale { get; set; }
Property Value
DefaultFont
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 (see FallbackFont).
Use HasDefaultFont() to check if this value is valid.
public Font DefaultFont { get; set; }
Property Value
DefaultFontSize
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 (see FallbackFontSize).
Values below 0
are invalid and can be used to unset the property. Use HasDefaultFontSize() to check if this value is valid.
public int DefaultFontSize { get; set; }
Property Value
Methods
AddType(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 available set_*
methods to add theme items.
public void AddType(StringName themeType)
Parameters
themeType
StringName
Clear()
Removes all the theme properties defined on the theme resource.
public void Clear()
ClearColor(StringName, StringName)
Removes the Color property defined by name
and themeType
, if it exists.
Fails if it doesn't exist. Use HasColor(StringName, StringName) to check for existence.
public void ClearColor(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
ClearConstant(StringName, StringName)
Removes the constant property defined by name
and themeType
, if it exists.
Fails if it doesn't exist. Use HasConstant(StringName, StringName) to check for existence.
public void ClearConstant(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
ClearFont(StringName, StringName)
Removes the Font property defined by name
and themeType
, if it exists.
Fails if it doesn't exist. Use HasFont(StringName, StringName) to check for existence.
public void ClearFont(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
ClearFontSize(StringName, StringName)
Removes the font size property defined by name
and themeType
, if it exists.
Fails if it doesn't exist. Use HasFontSize(StringName, StringName) to check for existence.
public void ClearFontSize(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
ClearIcon(StringName, StringName)
Removes the icon property defined by name
and themeType
, if it exists.
Fails if it doesn't exist. Use HasIcon(StringName, StringName) to check for existence.
public void ClearIcon(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
ClearStylebox(StringName, StringName)
Removes the StyleBox property defined by name
and themeType
, if it exists.
Fails if it doesn't exist. Use HasStylebox(StringName, StringName) to check for existence.
public void ClearStylebox(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
ClearThemeItem(DataType, StringName, StringName)
Removes the theme property of dataType
defined by name
and themeType
, if it exists.
Fails if it doesn't exist. Use HasThemeItem(DataType, StringName, StringName) 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.
public void ClearThemeItem(Theme.DataType dataType, StringName name, StringName themeType)
Parameters
dataType
Theme.DataTypename
StringNamethemeType
StringName
ClearTypeVariation(StringName)
Unmarks themeType
as being a variation of another theme type. See SetTypeVariation(StringName, StringName).
public void ClearTypeVariation(StringName themeType)
Parameters
themeType
StringName
GetColor(StringName, StringName)
Returns the Color property defined by name
and themeType
, if it exists.
Returns the default color value if the property doesn't exist. Use HasColor(StringName, StringName) to check for existence.
public Color GetColor(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
GetColorList(string)
Returns a list of names for Color properties defined with themeType
. Use GetColorTypeList() to get a list of possible theme type names.
public string[] GetColorList(string themeType)
Parameters
themeType
string
Returns
- string[]
GetColorTypeList()
Returns a list of all unique theme type names for Color properties. Use GetTypeList() to get a list of all unique theme types.
public string[] GetColorTypeList()
Returns
- string[]
GetConstant(StringName, StringName)
Returns the constant property defined by name
and themeType
, if it exists.
Returns 0
if the property doesn't exist. Use HasConstant(StringName, StringName) to check for existence.
public int GetConstant(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
GetConstantList(string)
Returns a list of names for constant properties defined with themeType
. Use GetConstantTypeList() to get a list of possible theme type names.
public string[] GetConstantList(string themeType)
Parameters
themeType
string
Returns
- string[]
GetConstantTypeList()
Returns a list of all unique theme type names for constant properties. Use GetTypeList() to get a list of all unique theme types.
public string[] GetConstantTypeList()
Returns
- string[]
GetFont(StringName, StringName)
Returns the Font property defined by name
and themeType
, if it exists.
Returns the default theme font if the property doesn't exist and the default theme font is set up (see DefaultFont). Use HasFont(StringName, StringName) to check for existence of the property and HasDefaultFont() to check for existence of the default theme font.
Returns the engine fallback font value, if neither exist (see FallbackFont).
public Font GetFont(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
GetFontList(string)
Returns a list of names for Font properties defined with themeType
. Use GetFontTypeList() to get a list of possible theme type names.
public string[] GetFontList(string themeType)
Parameters
themeType
string
Returns
- string[]
GetFontSize(StringName, StringName)
Returns the font size property defined by name
and themeType
, if it exists.
Returns the default theme font size if the property doesn't exist and the default theme font size is set up (see DefaultFontSize). Use HasFontSize(StringName, StringName) to check for existence of the property and HasDefaultFontSize() to check for existence of the default theme font.
Returns the engine fallback font size value, if neither exist (see FallbackFontSize).
public int GetFontSize(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
GetFontSizeList(string)
Returns a list of names for font size properties defined with themeType
. Use GetFontSizeTypeList() to get a list of possible theme type names.
public string[] GetFontSizeList(string themeType)
Parameters
themeType
string
Returns
- string[]
GetFontSizeTypeList()
Returns a list of all unique theme type names for font size properties. Use GetTypeList() to get a list of all unique theme types.
public string[] GetFontSizeTypeList()
Returns
- string[]
GetFontTypeList()
Returns a list of all unique theme type names for Font properties. Use GetTypeList() to get a list of all unique theme types.
public string[] GetFontTypeList()
Returns
- string[]
GetIcon(StringName, StringName)
Returns the icon property defined by name
and themeType
, if it exists.
Returns the engine fallback icon value if the property doesn't exist (see FallbackIcon). Use HasIcon(StringName, StringName) to check for existence.
public Texture2D GetIcon(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
GetIconList(string)
Returns a list of names for icon properties defined with themeType
. Use GetIconTypeList() to get a list of possible theme type names.
public string[] GetIconList(string themeType)
Parameters
themeType
string
Returns
- string[]
GetIconTypeList()
Returns a list of all unique theme type names for icon properties. Use GetTypeList() to get a list of all unique theme types.
public string[] GetIconTypeList()
Returns
- string[]
GetStylebox(StringName, StringName)
Returns the StyleBox property defined by name
and themeType
, if it exists.
Returns the engine fallback stylebox value if the property doesn't exist (see FallbackStylebox). Use HasStylebox(StringName, StringName) to check for existence.
public StyleBox GetStylebox(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
GetStyleboxList(string)
Returns a list of names for StyleBox properties defined with themeType
. Use GetStyleboxTypeList() to get a list of possible theme type names.
public string[] GetStyleboxList(string themeType)
Parameters
themeType
string
Returns
- string[]
GetStyleboxTypeList()
Returns a list of all unique theme type names for StyleBox properties. Use GetTypeList() to get a list of all unique theme types.
public string[] GetStyleboxTypeList()
Returns
- string[]
GetThemeItem(DataType, StringName, StringName)
Returns the theme property of dataType
defined by name
and themeType
, if it exists.
Returns the engine fallback value if the property doesn't exist (see ThemeDB). Use HasThemeItem(DataType, StringName, StringName) 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.
public Variant GetThemeItem(Theme.DataType dataType, StringName name, StringName themeType)
Parameters
dataType
Theme.DataTypename
StringNamethemeType
StringName
Returns
GetThemeItemList(DataType, string)
Returns a list of names for properties of dataType
defined with themeType
. Use GetThemeItemTypeList(DataType) 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.
public string[] GetThemeItemList(Theme.DataType dataType, string themeType)
Parameters
Returns
- string[]
GetThemeItemTypeList(DataType)
Returns a list of all unique theme type names for dataType
properties. Use GetTypeList() 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.
public string[] GetThemeItemTypeList(Theme.DataType dataType)
Parameters
Returns
- string[]
GetTypeList()
Returns a list of all unique theme type names. Use the appropriate get_*_type_list
method to get a list of unique theme types for a single data type.
public string[] GetTypeList()
Returns
- string[]
GetTypeVariationBase(StringName)
Returns the name of the base theme type if themeType
is a valid variation type. Returns an empty string otherwise.
public StringName GetTypeVariationBase(StringName themeType)
Parameters
themeType
StringName
Returns
GetTypeVariationList(StringName)
Returns a list of all type variations for the given baseType
.
public string[] GetTypeVariationList(StringName baseType)
Parameters
baseType
StringName
Returns
- string[]
HasColor(StringName, StringName)
Returns true
if the Color property defined by name
and themeType
exists.
Returns false
if it doesn't exist. Use SetColor(StringName, StringName, Color) to define it.
public bool HasColor(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
HasConstant(StringName, StringName)
Returns true
if the constant property defined by name
and themeType
exists.
Returns false
if it doesn't exist. Use SetConstant(StringName, StringName, int) to define it.
public bool HasConstant(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
HasDefaultBaseScale()
Returns true
if DefaultBaseScale has a valid value.
Returns false
if it doesn't. The value must be greater than 0.0
to be considered valid.
public bool HasDefaultBaseScale()
Returns
HasDefaultFont()
Returns true
if DefaultFont has a valid value.
Returns false
if it doesn't.
public bool HasDefaultFont()
Returns
HasDefaultFontSize()
Returns true
if DefaultFontSize has a valid value.
Returns false
if it doesn't. The value must be greater than 0
to be considered valid.
public bool HasDefaultFontSize()
Returns
HasFont(StringName, StringName)
Returns true
if the Font property defined by name
and themeType
exists, or if the default theme font is set up (see HasDefaultFont()).
Returns false
if neither exist. Use SetFont(StringName, StringName, Font) to define the property.
public bool HasFont(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
HasFontSize(StringName, StringName)
Returns true
if the font size property defined by name
and themeType
exists, or if the default theme font size is set up (see HasDefaultFontSize()).
Returns false
if neither exist. Use SetFontSize(StringName, StringName, int) to define the property.
public bool HasFontSize(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
HasIcon(StringName, StringName)
Returns true
if the icon property defined by name
and themeType
exists.
Returns false
if it doesn't exist. Use SetIcon(StringName, StringName, Texture2D) to define it.
public bool HasIcon(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
HasStylebox(StringName, StringName)
Returns true
if the StyleBox property defined by name
and themeType
exists.
Returns false
if it doesn't exist. Use SetStylebox(StringName, StringName, StyleBox) to define it.
public bool HasStylebox(StringName name, StringName themeType)
Parameters
name
StringNamethemeType
StringName
Returns
HasThemeItem(DataType, StringName, StringName)
Returns true
if the theme property of dataType
defined by name
and themeType
exists.
Returns false
if it doesn't exist. Use SetThemeItem(DataType, StringName, StringName, Variant) to define it.
Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.
public bool HasThemeItem(Theme.DataType dataType, StringName name, StringName themeType)
Parameters
dataType
Theme.DataTypename
StringNamethemeType
StringName
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsTypeVariation(StringName, StringName)
Returns true
if themeType
is marked as a variation of baseType
.
public bool IsTypeVariation(StringName themeType, StringName baseType)
Parameters
themeType
StringNamebaseType
StringName
Returns
MergeWith(Theme)
Adds missing and overrides existing definitions with values from the other
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.
public void MergeWith(Theme other)
Parameters
other
Theme
RemoveType(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.
public void RemoveType(StringName themeType)
Parameters
themeType
StringName
RenameColor(StringName, StringName, StringName)
Renames the Color property defined by oldName
and themeType
to name
, if it exists.
Fails if it doesn't exist, or if a similar property with the new name already exists. Use HasColor(StringName, StringName) to check for existence, and ClearColor(StringName, StringName) to remove the existing property.
public void RenameColor(StringName oldName, StringName name, StringName themeType)
Parameters
oldName
StringNamename
StringNamethemeType
StringName
RenameConstant(StringName, StringName, StringName)
Renames the constant property defined by oldName
and themeType
to name
, if it exists.
Fails if it doesn't exist, or if a similar property with the new name already exists. Use HasConstant(StringName, StringName) to check for existence, and ClearConstant(StringName, StringName) to remove the existing property.
public void RenameConstant(StringName oldName, StringName name, StringName themeType)
Parameters
oldName
StringNamename
StringNamethemeType
StringName
RenameFont(StringName, StringName, StringName)
Renames the Font property defined by oldName
and themeType
to name
, if it exists.
Fails if it doesn't exist, or if a similar property with the new name already exists. Use HasFont(StringName, StringName) to check for existence, and ClearFont(StringName, StringName) to remove the existing property.
public void RenameFont(StringName oldName, StringName name, StringName themeType)
Parameters
oldName
StringNamename
StringNamethemeType
StringName
RenameFontSize(StringName, StringName, StringName)
Renames the font size property defined by oldName
and themeType
to name
, if it exists.
Fails if it doesn't exist, or if a similar property with the new name already exists. Use HasFontSize(StringName, StringName) to check for existence, and ClearFontSize(StringName, StringName) to remove the existing property.
public void RenameFontSize(StringName oldName, StringName name, StringName themeType)
Parameters
oldName
StringNamename
StringNamethemeType
StringName
RenameIcon(StringName, StringName, StringName)
Renames the icon property defined by oldName
and themeType
to name
, if it exists.
Fails if it doesn't exist, or if a similar property with the new name already exists. Use HasIcon(StringName, StringName) to check for existence, and ClearIcon(StringName, StringName) to remove the existing property.
public void RenameIcon(StringName oldName, StringName name, StringName themeType)
Parameters
oldName
StringNamename
StringNamethemeType
StringName
RenameStylebox(StringName, StringName, StringName)
Renames the StyleBox property defined by oldName
and themeType
to name
, if it exists.
Fails if it doesn't exist, or if a similar property with the new name already exists. Use HasStylebox(StringName, StringName) to check for existence, and ClearStylebox(StringName, StringName) to remove the existing property.
public void RenameStylebox(StringName oldName, StringName name, StringName themeType)
Parameters
oldName
StringNamename
StringNamethemeType
StringName
RenameThemeItem(DataType, StringName, StringName, StringName)
Renames the theme property of dataType
defined by oldName
and themeType
to name
, if it exists.
Fails if it doesn't exist, or if a similar property with the new name already exists. Use HasThemeItem(DataType, StringName, StringName) to check for existence, and ClearThemeItem(DataType, StringName, StringName) 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.
public void RenameThemeItem(Theme.DataType dataType, StringName oldName, StringName name, StringName themeType)
Parameters
dataType
Theme.DataTypeoldName
StringNamename
StringNamethemeType
StringName
SetColor(StringName, StringName, Color)
Creates or changes the value of the Color property defined by name
and themeType
. Use ClearColor(StringName, StringName) to remove the property.
public void SetColor(StringName name, StringName themeType, Color color)
Parameters
name
StringNamethemeType
StringNamecolor
Color
SetConstant(StringName, StringName, int)
Creates or changes the value of the constant property defined by name
and themeType
. Use ClearConstant(StringName, StringName) to remove the property.
public void SetConstant(StringName name, StringName themeType, int constant)
Parameters
name
StringNamethemeType
StringNameconstant
int
SetFont(StringName, StringName, Font)
Creates or changes the value of the Font property defined by name
and themeType
. Use ClearFont(StringName, StringName) to remove the property.
public void SetFont(StringName name, StringName themeType, Font font)
Parameters
name
StringNamethemeType
StringNamefont
Font
SetFontSize(StringName, StringName, int)
Creates or changes the value of the font size property defined by name
and themeType
. Use ClearFontSize(StringName, StringName) to remove the property.
public void SetFontSize(StringName name, StringName themeType, int fontSize)
Parameters
name
StringNamethemeType
StringNamefontSize
int
SetIcon(StringName, StringName, Texture2D)
Creates or changes the value of the icon property defined by name
and themeType
. Use ClearIcon(StringName, StringName) to remove the property.
public void SetIcon(StringName name, StringName themeType, Texture2D texture)
Parameters
name
StringNamethemeType
StringNametexture
Texture2D
SetStylebox(StringName, StringName, StyleBox)
Creates or changes the value of the StyleBox property defined by name
and themeType
. Use ClearStylebox(StringName, StringName) to remove the property.
public void SetStylebox(StringName name, StringName themeType, StyleBox texture)
Parameters
name
StringNamethemeType
StringNametexture
StyleBox
SetThemeItem(DataType, StringName, StringName, Variant)
Creates or changes the value of the theme property of dataType
defined by name
and themeType
. Use ClearThemeItem(DataType, StringName, StringName) to remove the property.
Fails if the value
type is not accepted by dataType
.
Note: This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.
public void SetThemeItem(Theme.DataType dataType, StringName name, StringName themeType, Variant value)
Parameters
dataType
Theme.DataTypename
StringNamethemeType
StringNamevalue
Variant
SetTypeVariation(StringName, StringName)
Marks themeType
as a variation of baseType
.
This adds themeType
as a suggested option for ThemeTypeVariation on a Control that is of the baseType
class.
Variations can also be nested, i.e. baseType
can be another variation. If a chain of variations ends with a baseType
matching the class of the Control, 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. See ProjectSettings.gui/theme/custom
.
public void SetTypeVariation(StringName themeType, StringName baseType)
Parameters
themeType
StringNamebaseType
StringName