Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Theme

繼承: Resource < RefCounted < Object

用於樣式化/皮膚化 ControlWindow 的資源。

說明

用於樣式化/皮膚化 ControlWindow 節點的資源。控制項可以使用本地的主題覆蓋項進行單獨的風格化(見 Control.add_theme_color_override()),而主題資源則能夠儲存這些設定,在所有同型別的控制項之間實作共用(例如將所有 Button 都設定為相同的風格)。主題資源可以在整個專案上使用,但你也可以為單獨的一個控件節點分支設定不同的主題資源。為某個控制項節點分配的主題資源不僅會對它自己生效,也會對它的所有直接和間接子節點生效(只要控制項鏈沒有中斷)。

專案範圍的主題請使用 ProjectSettings.gui/theme/custom 設定,這樣專案中的所有控制項就都能夠使用。

控制項節點的主題請使用 Control.theme 設定,這樣該控制項和它的所有直接和間接子節點就都能夠使用。

教學

屬性

float

default_base_scale

0.0

Font

default_font

int

default_font_size

-1

方法

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

rename_type(old_theme_type: 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

資料型別列舉的最大值。


屬性說明

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

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

Values below 1 are invalid and can be used to unset the property. Use has_default_font_size() to check if this value is valid.


方法說明

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 🔗

如果主題型別 theme_type 中存在名為 nameColor 屬性,則返回 true

不存在時返回 false。定義請使用 set_color()


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

如果主題型別 theme_type 中存在名為 name 的常數屬性,則返回 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 🔗

如果主題型別 theme_type 中存在名為 nameFont 屬性,則返回 true

不存在時返回 false。定義請使用 set_font()


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

如果主題型別 theme_type 中存在名為 name 的字形大小屬性,則返回 true

不存在時返回 false。定義請使用 set_font_size()


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

如果主題型別 theme_type 中存在名為 name 的圖示屬性,則返回 true

不存在時返回 false。定義請使用 set_icon()


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

如果主題型別 theme_type 中存在名為 nameStyleBox 屬性,則返回 true

不存在時返回 false。定義請使用 set_stylebox()


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

如果主題型別 theme_type 中存在名為 name 的主題屬性,則返回 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) 🔗

如果主題型別 theme_type 中存在名為 old_nameColor 屬性,則將其重命名為 name

不存在時失敗,新名稱已存在時也會失敗。請使用 has_color() 檢查是否存在,使用 clear_color() 移除現有屬性。


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

如果主題型別 theme_type 中存在名為 old_name 的常數屬性,則將其重命名為 name

不存在時失敗,新名稱已存在時也會失敗。請使用 has_constant() 檢查是否存在,使用 clear_constant() 移除現有屬性。


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

如果主題型別 theme_type 中存在名為 old_nameFont 屬性,則將其重命名為 name

不存在時失敗,新名稱已存在時也會失敗。請使用 has_font() 檢查是否存在,使用 clear_font() 移除現有屬性。


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

如果主題型別 theme_type 中存在名為 old_name 的字形大小屬性,則將其重命名為 name

不存在時失敗,新名稱已存在時也會失敗。請使用 has_font_size() 檢查是否存在,使用 clear_font_size() 移除現有屬性。


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

如果主題型別 theme_type 中存在名為 old_name 的圖示屬性,則將其重命名為 name

不存在時失敗,新名稱已存在時也會失敗。請使用 has_icon() 檢查是否存在,使用 clear_icon() 移除現有屬性。


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

如果主題型別 theme_type 中存在名為 old_nameStyleBox 屬性,則將其重命名為 name

不存在時失敗,新名稱已存在時也會失敗。請使用 has_stylebox() 檢查是否存在,使用 clear_stylebox() 移除現有屬性。


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

如果主題型別 theme_type 中存在名為 old_name 的主題屬性,則將其重命名為 name

不存在時失敗,新名稱已存在時也會失敗。請使用 has_theme_item() 檢查是否存在,使用 clear_theme_item() 移除現有屬性。

注意:這個方法類似於呼叫相應的資料型別特定方法,但可以用於更通用邏輯。


void rename_type(old_theme_type: StringName, theme_type: StringName) 🔗

Renames the theme type old_theme_type to theme_type, if the old type exists and the new one doesn't exist.

Note: Renaming a theme type to an empty name or a variation to a type associated with a built-in class removes type variation connections in a way that cannot be undone by reversing the rename alone.


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

建立或改變由名稱 name 和主題型別 theme_type 定義的 Color 屬性的值。移除該屬性請使用 clear_color()


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

建立或改變由名稱 name 和主題型別 theme_type 定義的常數屬性的值。移除該屬性請使用 clear_constant()


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

建立或改變由名稱 name 和主題型別 theme_type 定義的 Font 屬性的值。移除該屬性請使用 clear_font()


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

建立或改變由名稱 name 和主題型別 theme_type 定義的字形大小屬性的值。移除該屬性請使用 clear_font_size()


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

建立或改變由名稱 name 和主題型別 theme_type 定義的圖示屬性的值。移除該屬性請使用 clear_icon()


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

建立或改變由名稱 name 和主題型別 theme_type 定義的 StyleBox 屬性的值。移除該屬性請使用 clear_stylebox()


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

建立或改變由名稱 name 和主題型別 theme_type 定義的主題屬性的值。移除該屬性請使用 clear_theme_item()

如果 value 的型別不被 data_type 所接受,則失敗。

注意:這個方法類似於呼叫相應的資料型別特定方法,但可以用於更通用邏輯。


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

將主題型別 theme_type 標記為基礎型別 base_type 的變種。

這會將 theme_type 新增為屬於 base_type 類的 ControlControl.theme_type_variation 的建議選項。

變種也可以巢狀,即 base_type 可以是另一個變種。如果變種鏈以配對 Control 類的 base_type 結束,則整個鏈將被建議為選項。

注意:僅當該主題資源被設定為專案的預設主題時才會顯示建議。參見 ProjectSettings.gui/theme/custom