Theme

继承: Resource < RefCounted < Object

用于样式/皮肤Controls和Windows的资源。

描述

用于样式化/蒙皮ControlWindow节点的资源。虽然可以使用其本地主题覆盖来设置单个控件的样式(参见Control.add_theme_color_override()),但主题资源允许您在共享相同类型的所有控件中存储和应用相同的设置(例如,将所有Button的样式设置为相同)。一个主题资源可用于整个项目,但您也可以将单独的主题资源设置为控件节点的分支。分配给控件的主题资源适用于控件本身,以及它的所有直接和间接子级(只要控件链不中断)。

使用ProjectSettings.gui/theme/custom设置项目范围主题,该主题可用于项目中的每个控件。

使用任何控件节点的Control.theme来设置一个主题,该主题将可供该控件及其所有直接和间接子项使用。

属性

方法

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)


枚举

enum DataType: 🔗

DataType DATA_TYPE_COLOR = 0

主题的Color项目类型。

DataType DATA_TYPE_CONSTANT = 1

主题的常量项类型。

DataType DATA_TYPE_FONT = 2

主题的Font项目类型。

DataType DATA_TYPE_FONT_SIZE = 3

主题的字体大小项目类型。

DataType DATA_TYPE_ICON = 4

主题的图标Texture2D项目类型。

DataType DATA_TYPE_STYLEBOX = 5

主题的StyleBox项目类型。

DataType DATA_TYPE_MAX = 6

DataType枚举的最大值。


属性说明

float default_base_scale = 0.0 🔗

  • void set_default_base_scale(value: float)

  • float get_default_base_scale()

此主题资源的默认基本比例因子。某些控件使用它来根据全局比例因子缩放其视觉属性。如果此值设置为0.0,则使用全局比例因子(参见ThemeDB.fallback_base_scale)。

使用has_default_base_scale()检查此值是否有效。


Font default_font 🔗

  • void set_default_font(value: Font)

  • Font get_default_font()

此主题资源的默认字体。当尝试获取此主题中不存在或处于无效状态的字体资源时,用作默认值。如果默认字体也丢失或无效,则使用引擎后备值(参见ThemeDB.fallback_font)。

使用has_default_font()检查此值是否有效。


int default_font_size = -1 🔗

  • void set_default_font_size(value: int)

  • int get_default_font_size()

此主题资源的默认字体大小。当尝试获取此主题中不存在或处于无效状态的字体大小值时,用作默认值。如果默认字体大小也丢失或无效,则使用引擎回退值(参见ThemeDB.fallback_font_size)。

低于1的值无效,可用于取消设置属性。使用has_default_font_size()检查此值是否有效。


方法说明

void add_type(theme_type: StringName) 🔗

为每个有效数据类型添加一个空主题类型。

注意:空类型不与主题一起保存。此方法仅用于对资源执行内存中更改。使用可用的set_*方法添加主题项。


void clear() 🔗

删除在主题资源上定义的所有主题属性。


void clear_color(name: StringName, theme_type: StringName) 🔗

删除nametheme_type定义的Color属性(如果存在)。

如果不存在,则失败。使用has_color()检查是否存在。


void clear_constant(name: StringName, theme_type: StringName) 🔗

删除nametheme_type定义的常量属性(如果存在)。

如果不存在,则失败。使用has_constant()检查是否存在。


void clear_font(name: StringName, theme_type: StringName) 🔗

删除nametheme_type定义的Font属性(如果存在)。

如果不存在,则失败。使用has_font()检查是否存在。


void clear_font_size(name: StringName, theme_type: StringName) 🔗

删除由nametheme_type定义的字体大小属性(如果存在)。

如果不存在,则失败。使用has_font_size()检查是否存在。


void clear_icon(name: StringName, theme_type: StringName) 🔗

删除nametheme_type定义的图标属性(如果存在)。

如果不存在,则失败。使用has_icon()检查是否存在。


void clear_stylebox(name: StringName, theme_type: StringName) 🔗

删除nametheme_type定义的StyleBox属性(如果存在)。

如果不存在,则失败。使用has_stylebox()检查是否存在。


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

删除由nametheme_type定义的data_type的主题属性(如果存在)。

如果不存在,则失败。使用has_theme_item()检查是否存在。

注意:此方法类似于调用相应的数据类型特定方法,但可用于更通用的逻辑。


void clear_type_variation(theme_type: StringName) 🔗

theme_type标记为另一种主题类型的变体。参见set_type_variation()


Color get_color(name: StringName, theme_type: StringName) const 🔗

返回nametheme_type定义的Color属性(如果存在)。

如果属性不存在,则返回默认颜色值。使用has_color()检查是否存在。


PackedStringArray get_color_list(theme_type: String) const 🔗

返回使用theme_type定义的Color属性的名称列表。使用get_color_type_list()获取可能的主题类型名称列表。


PackedStringArray get_color_type_list() const 🔗

返回Color属性的所有唯一主题类型名称的列表。使用get_type_list()获取所有唯一主题类型的列表。


int get_constant(name: StringName, theme_type: StringName) const 🔗

返回nametheme_type定义的常量属性(如果存在)。

如果属性不存在,则返回0。使用has_constant()检查是否存在。


PackedStringArray get_constant_list(theme_type: String) const 🔗

返回使用theme_type定义的常量属性的名称列表。使用get_constant_type_list()获取可能的主题类型名称列表。


PackedStringArray get_constant_type_list() const 🔗

返回常量属性的所有唯一主题类型名称的列表。使用get_type_list()获取所有唯一主题类型的列表。


Font get_font(name: StringName, theme_type: StringName) const 🔗

返回由nametheme_type定义的Font属性(如果存在)。

如果属性不存在并且设置了默认主题字体,则返回默认主题字体(参见default_font)。使用has_font()检查属性是否存在,使用has_default_font()检查默认主题字体是否存在。

返回引擎后备字体值(如果两者都不存在)(参见ThemeDB.fallback_font)。


PackedStringArray get_font_list(theme_type: String) const 🔗

返回使用theme_type定义的Font属性的名称列表。使用get_font_type_list()获取可能的主题类型名称列表。


int get_font_size(name: StringName, theme_type: StringName) const 🔗

返回由nametheme_type定义的字体大小属性(如果存在)。

如果属性不存在并且设置了默认主题字体大小,则返回默认主题字体大小(参见default_font_size)。使用has_font_size()检查属性是否存在,使用has_default_font_size()检查默认主题字体是否存在。

返回引擎后备字体大小值(如果两者都不存在)(参见ThemeDB.fallback_font_size)。


PackedStringArray get_font_size_list(theme_type: String) const 🔗

返回使用theme_type定义的字体大小属性的名称列表。使用get_font_size_type_list()获取可能的主题类型名称列表。


PackedStringArray get_font_size_type_list() const 🔗

返回字体大小属性的所有唯一主题类型名称的列表。使用get_type_list()获取所有唯一主题类型的列表。


PackedStringArray get_font_type_list() const 🔗

返回Font属性的所有唯一主题类型名称的列表。使用get_type_list()获取所有唯一主题类型的列表。


Texture2D get_icon(name: StringName, theme_type: StringName) const 🔗

返回nametheme_type定义的图标属性(如果存在)。

如果属性不存在,则返回引擎回退图标值(参见ThemeDB.fallback_icon)。使用has_icon()检查是否存在。


PackedStringArray get_icon_list(theme_type: String) const 🔗

返回使用theme_type定义的图标属性的名称列表。使用get_icon_type_list()获取可能的主题类型名称列表。


PackedStringArray get_icon_type_list() const 🔗

返回图标属性的所有唯一主题类型名称的列表。使用get_type_list()获取所有唯一主题类型的列表。


StyleBox get_stylebox(name: StringName, theme_type: StringName) const 🔗

返回nametheme_type定义的StyleBox属性(如果存在)。

如果属性不存在,则返回引擎回退样式框值(参见ThemeDB.fallback_stylebox)。使用has_stylebox()检查是否存在。


PackedStringArray get_stylebox_list(theme_type: String) const 🔗

返回使用theme_type定义的StyleBox属性的名称列表。使用get_stylebox_type_list()获取可能的主题类型名称列表。


PackedStringArray get_stylebox_type_list() const 🔗

返回StyleBox属性的所有唯一主题类型名称的列表。使用get_type_list()获取所有唯一主题类型的列表。


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

返回由nametheme_type定义的data_type的主题属性(如果存在)。

如果属性不存在,则返回引擎回退值(参见ThemeDB)。使用has_theme_item()检查是否存在。

注意:此方法类似于调用相应的数据类型特定方法,但可用于更通用的逻辑。


PackedStringArray get_theme_item_list(data_type: DataType, theme_type: String) const 🔗

返回使用theme_type定义的data_type属性的名称列表。使用get_theme_item_type_list()获取可能的主题类型名称列表。

注意:此方法类似于调用相应的数据类型特定方法,但可用于更通用的逻辑。


PackedStringArray get_theme_item_type_list(data_type: DataType) const 🔗

返回data_type属性的所有唯一主题类型名称的列表。使用get_type_list()获取所有唯一主题类型的列表。

注意:此方法类似于调用相应的数据类型特定方法,但可用于更通用的逻辑。


PackedStringArray get_type_list() const 🔗

返回所有唯一主题类型名称的列表。使用适当的get_*_type_list方法获取单个数据类型的唯一主题类型列表。


StringName get_type_variation_base(theme_type: StringName) const 🔗

如果theme_type是有效的变体类型,则返回基本主题类型的名称。否则返回空字符串。


PackedStringArray get_type_variation_list(base_type: StringName) const 🔗

返回给定base_type的所有类型变体的列表。


bool has_color(name: StringName, theme_type: StringName) const 🔗

如果nametheme_type定义的Color属性存在,则返回true

如果false不存在,则返回。使用set_color()来定义它。


bool has_constant(name: StringName, theme_type: StringName) const 🔗

如果nametheme_type定义的常量属性存在,则返回true

如果false不存在,则返回。使用set_constant()来定义它。


bool has_default_base_scale() const 🔗

如果default_base_scale的值有效,则返回true

如果没有,则返回false。该值必须大于0.0才能被视为有效。


bool has_default_font() const 🔗

如果default_font的值有效,则返回true

如果没有,则返回false


bool has_default_font_size() const 🔗

如果default_font_size的值有效,则返回true

如果没有,则返回false。该值必须大于0才能被视为有效。


bool has_font(name: StringName, theme_type: StringName) const 🔗

如果nametheme_type定义的Font属性存在,或者设置了默认主题字体,则返回true(参见has_default_font())。

如果两者都不存在,则返回false。使用set_font()定义属性。


bool has_font_size(name: StringName, theme_type: StringName) const 🔗

如果nametheme_type定义的字体大小属性存在,或者如果设置了默认主题字体大小,则返回true(参见has_default_font_size())。

如果两者都不存在,则返回false。使用set_font_size()定义属性。


bool has_icon(name: StringName, theme_type: StringName) const 🔗

如果nametheme_type定义的图标属性存在,则返回true

如果false不存在,则返回。使用set_icon()来定义它。


bool has_stylebox(name: StringName, theme_type: StringName) const 🔗

如果nametheme_type定义的StyleBox属性存在,则返回true

如果false不存在,则返回。使用set_stylebox()来定义它。


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

如果nametheme_type定义的data_type的主题属性存在,则返回true

如果false不存在,则返回。使用set_theme_item()来定义它。

注意:此方法类似于调用相应的数据类型特定方法,但可用于更通用的逻辑。


bool is_type_variation(theme_type: StringName, base_type: StringName) const 🔗

如果将theme_type标记为base_type的变体,则返回true


void merge_with(other: Theme) 🔗

添加缺失的定义并使用来自other主题资源的值覆盖现有定义。

注意:这修改了当前主题。如果要将两个主题合并在一起而不修改任何一个,请创建一个新的空主题并将另外两个相继合并到其中。


void remove_type(theme_type: StringName) 🔗

删除主题类型,优雅地丢弃定义的主题项。如果类型是变体,则此信息也会被删除。如果类型是类型变体的基础,则这些变体会失去基础。


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

old_nametheme_type定义的Color属性重命名为name(如果存在)。

如果不存在,或者具有新名称的类似属性已经存在,则失败。使用has_color()检查是否存在,使用clear_color()删除现有属性。


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

old_nametheme_type定义的常量属性重命名为name(如果存在)。

如果不存在,或者具有新名称的类似属性已经存在,则失败。使用has_constant()检查是否存在,使用clear_constant()删除现有属性。


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

old_nametheme_type定义的Font属性重命名为name(如果存在)。

如果不存在,或者具有新名称的类似属性已经存在,则失败。使用has_font()检查是否存在,使用clear_font()删除现有属性。


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

old_nametheme_type定义的字体大小属性重命名为name(如果存在)。

如果不存在,或者具有新名称的类似属性已经存在,则失败。使用has_font_size()检查是否存在,使用clear_font_size()删除现有属性。


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

old_nametheme_type定义的图标属性重命名为name(如果存在)。

如果不存在,或者具有新名称的类似属性已经存在,则失败。使用has_icon()检查是否存在,使用clear_icon()删除现有属性。


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

old_nametheme_type定义的StyleBox属性重命名为name(如果存在)。

如果不存在,或者具有新名称的类似属性已经存在,则失败。使用has_stylebox()检查是否存在,使用clear_stylebox()删除现有属性。


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

将由old_nametheme_type定义的data_type的主题属性重命名为name(如果存在)。

如果不存在,或者具有新名称的类似属性已经存在,则失败。使用has_theme_item()检查是否存在,使用clear_theme_item()删除现有属性。

注意:此方法类似于调用相应的数据类型特定方法,但可用于更通用的逻辑。


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

创建或更改nametheme_type定义的Color属性的值。使用clear_color()删除该属性。


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

创建或更改由nametheme_type定义的常量属性的值。使用clear_constant()删除该属性。


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

创建或更改nametheme_type定义的Font属性的值。使用clear_font()删除该属性。


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

创建或更改由nametheme_type定义的字体大小属性的值。使用clear_font_size()删除该属性。


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

创建或更改由nametheme_type定义的图标属性的值。使用clear_icon()删除该属性。


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

创建或更改nametheme_type定义的StyleBox属性的值。使用clear_stylebox()删除该属性。


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

创建或更改由nametheme_type定义的data_type的主题属性的值。使用clear_theme_item()删除该属性。

如果value类型不被data_type接受,则失败。

注意:此方法类似于调用相应的数据类型特定方法,但可用于更通用的逻辑。


void set_type_variation(theme_type: StringName, base_type: StringName) 🔗

theme_type标记为base_type的变体。

这会在属于base_type类的Control上添加theme_type作为Control.theme_type_variation的建议选项。

变化也可以嵌套,即base_type可以是另一个变化。如果变化链以与Control类匹配的base_type结束,则整个链将被建议为选项。

注意:仅当此主题资源设置为项目默认主题时才会显示建议。请参阅ProjectSettings.gui/theme/custom