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.
Checking the stable version of the documentation...
TreeItem
繼承: Object
代表 Tree 中某個專案的內部控制項。
說明
Tree 控制項中的單個專案。可以包含其他 TreeItem 作為子級,從而建立層級結構。還可以包含文字和按鈕。TreeItem 不是 Node,在 Tree 內部使用。
要建立 TreeItem,請使用 Tree.create_item() 或 create_child()。要移除 TreeItem,請使用 Object.free()。
注意:按鈕的 ID 值為 32 位,與始終為 64 位的 int 不同。取值範圍為 -2147483648 到 2147483647。
屬性
方法
void |
add_button(column: int, button: Texture2D, id: int = -1, disabled: bool = false, tooltip_text: String = "", description: String = "") |
void |
|
void |
call_recursive(method: StringName, ...) vararg |
void |
|
void |
clear_custom_bg_color(column: int) |
void |
clear_custom_color(column: int) |
create_child(index: int = -1) |
|
void |
|
void |
erase_button(column: int, button_index: int) |
get_auto_translate_mode(column: int) const |
|
get_autowrap_mode(column: int) const |
|
BitField[LineBreakFlag] |
get_autowrap_trim_flags(column: int) const |
get_button(column: int, button_index: int) const |
|
get_button_by_id(column: int, id: int) const |
|
get_button_color(column: int, id: int) const |
|
get_button_count(column: int) const |
|
get_button_id(column: int, button_index: int) const |
|
get_button_tooltip_text(column: int, button_index: int) const |
|
get_cell_mode(column: int) const |
|
get_custom_bg_color(column: int) const |
|
get_custom_color(column: int) const |
|
get_custom_draw_callback(column: int) const |
|
get_custom_font(column: int) const |
|
get_custom_font_size(column: int) const |
|
get_custom_stylebox(column: int) const |
|
get_description(column: int) const |
|
get_expand_right(column: int) const |
|
get_first_child() const |
|
get_icon_max_width(column: int) const |
|
get_icon_modulate(column: int) const |
|
get_icon_overlay(column: int) const |
|
get_icon_region(column: int) const |
|
get_language(column: int) const |
|
get_metadata(column: int) const |
|
get_next() const |
|
get_next_in_tree(wrap: bool = false) |
|
get_next_visible(wrap: bool = false) |
|
get_parent() const |
|
get_prev() |
|
get_prev_in_tree(wrap: bool = false) |
|
get_prev_visible(wrap: bool = false) |
|
get_range_config(column: int) |
|
get_structured_text_bidi_override(column: int) const |
|
get_structured_text_bidi_override_options(column: int) const |
|
get_suffix(column: int) const |
|
get_text_alignment(column: int) const |
|
get_text_direction(column: int) const |
|
get_text_overrun_behavior(column: int) const |
|
get_tooltip_text(column: int) const |
|
get_tree() const |
|
is_accepting_children() const |
|
is_any_collapsed(only_visible: bool = false) |
|
is_button_disabled(column: int, button_index: int) const |
|
is_checked(column: int) const |
|
is_custom_set_as_button(column: int) const |
|
is_edit_multiline(column: int) const |
|
is_editable(column: int) |
|
is_indeterminate(column: int) const |
|
is_selectable(column: int) const |
|
is_selected(column: int) |
|
is_visible_in_tree() const |
|
void |
move_after(item: TreeItem) |
void |
move_before(item: TreeItem) |
void |
propagate_check(column: int, emit_signal: bool = true) |
void |
remove_child(child: TreeItem) |
void |
|
void |
set_accept_children(allowed: bool) |
void |
set_auto_translate_mode(column: int, mode: AutoTranslateMode) |
void |
set_autowrap_mode(column: int, autowrap_mode: AutowrapMode) |
void |
set_autowrap_trim_flags(column: int, flags: BitField[LineBreakFlag]) |
void |
set_button(column: int, button_index: int, button: Texture2D) |
void |
set_button_color(column: int, button_index: int, color: Color) |
void |
set_button_description(column: int, button_index: int, description: String) |
void |
set_button_disabled(column: int, button_index: int, disabled: bool) |
void |
set_button_tooltip_text(column: int, button_index: int, tooltip: String) |
void |
set_cell_mode(column: int, mode: TreeCellMode) |
void |
set_checked(column: int, checked: bool) |
void |
set_collapsed_recursive(enable: bool) |
void |
set_custom_as_button(column: int, enable: bool) |
void |
set_custom_bg_color(column: int, color: Color, just_outline: bool = false) |
void |
set_custom_color(column: int, color: Color) |
void |
set_custom_draw(column: int, object: Object, callback: StringName) |
void |
set_custom_draw_callback(column: int, callback: Callable) |
void |
set_custom_font(column: int, font: Font) |
void |
set_custom_font_size(column: int, font_size: int) |
void |
set_custom_stylebox(column: int, stylebox: StyleBox) |
void |
set_description(column: int, description: String) |
void |
set_edit_multiline(column: int, multiline: bool) |
void |
set_editable(column: int, enabled: bool) |
void |
set_expand_right(column: int, enable: bool) |
void |
|
void |
set_icon_max_width(column: int, width: int) |
void |
set_icon_modulate(column: int, modulate: Color) |
void |
set_icon_overlay(column: int, texture: Texture2D) |
void |
set_icon_region(column: int, region: Rect2) |
void |
set_indeterminate(column: int, indeterminate: bool) |
void |
set_language(column: int, language: String) |
void |
set_metadata(column: int, meta: Variant) |
void |
|
void |
set_range_config(column: int, min: float, max: float, step: float, expr: bool = false) |
void |
set_selectable(column: int, selectable: bool) |
void |
set_structured_text_bidi_override(column: int, parser: StructuredTextParser) |
void |
set_structured_text_bidi_override_options(column: int, args: Array) |
void |
set_suffix(column: int, text: String) |
void |
|
void |
set_text_alignment(column: int, text_alignment: HorizontalAlignment) |
void |
set_text_direction(column: int, direction: TextDirection) |
void |
set_text_overrun_behavior(column: int, overrun_behavior: OverrunBehavior) |
void |
set_tooltip_text(column: int, tooltip: String) |
void |
列舉
enum TreeCellMode: 🔗
TreeCellMode CELL_MODE_STRING = 0
Cell shows a string label, optionally with an icon. When editable, the text can be edited using a LineEdit, or a TextEdit popup if set_edit_multiline() is used.
TreeCellMode CELL_MODE_CHECK = 1
Cell shows a checkbox, optionally with text and an icon. The checkbox can be pressed, released, or indeterminate (via set_indeterminate()). The checkbox can't be clicked unless the cell is editable.
TreeCellMode CELL_MODE_RANGE = 2
Cell shows a numeric range. When editable, it can be edited using a range slider. Use set_range() to set the value and set_range_config() to configure the range.
This cell can also be used in a text dropdown mode when you assign a text with set_text(). Separate options with a comma, e.g. "Option1,Option2,Option3".
TreeCellMode CELL_MODE_ICON = 3
Cell shows an icon. It can't be edited nor display text. The icon is always centered within the cell.
TreeCellMode CELL_MODE_CUSTOM = 4
Cell shows as a clickable button. It will display an arrow similar to OptionButton, but doesn't feature a dropdown (for that you can use CELL_MODE_RANGE). Clicking the button emits the Tree.item_edited signal. The button is flat by default, you can use set_custom_as_button() to display it with a StyleBox.
This mode also supports custom drawing using set_custom_draw_callback().
屬性說明
如果為 true,則該 TreeItem 被折疊。
自訂最小高度。
如果為 true,則這個 TreeItem 禁用折疊。
如果為 true,則該 TreeItem 可見(預設)。
請注意,如果將 TreeItem 設定為不可見,則其子項也將不可見。
方法說明
void add_button(column: int, button: Texture2D, id: int = -1, disabled: bool = false, tooltip_text: String = "", description: String = "") 🔗
Adds a button with Texture2D button to the end of the cell at column column. The id is used to identify the button in the according Tree.button_clicked signal and can be different from the buttons index. If not specified, the next available index is used, which may be retrieved by calling get_button_count() immediately before this method. Optionally, the button can be disabled and have a tooltip_text. description is used as the button description for assistive apps.
void add_child(child: TreeItem) 🔗
將已解除父子關係的 TreeItem 新增為這個樹項的直接子項。child 樹項必須不是任何 Tree 的一部分,也不能有任何 TreeItem 父級。另見 remove_child()。
void call_recursive(method: StringName, ...) vararg 🔗
遞迴呼叫在實際 TreeItem 及其子項上的 method。將參數作為一個逗號分隔列表傳遞。
void clear_buttons() 🔗
Removes all buttons from all columns of this item.
void clear_custom_bg_color(column: int) 🔗
重設指定列預設的背景顏色。
void clear_custom_color(column: int) 🔗
重設指定列預設的顏色。
TreeItem create_child(index: int = -1) 🔗
建立專案並新增為子項。
新建的專案會插入到索引 index 位置(預設的 -1 表示最後的位置),如果 index 比子項數量大則會作為最後一項。
取消選擇指定列。
void erase_button(column: int, button_index: int) 🔗
刪除列 column 中索引 button_index 處的按鈕。
AutoTranslateMode get_auto_translate_mode(column: int) const 🔗
Returns the column's auto translate mode.
AutowrapMode get_autowrap_mode(column: int) const 🔗
返回給定列 column 的文字自動換行模式。預設為 TextServer.AUTOWRAP_OFF。
BitField[LineBreakFlag] get_autowrap_trim_flags(column: int) const 🔗
Returns the autowrap trim flags for the given column. By default, both TextServer.BREAK_TRIM_START_EDGE_SPACES and TextServer.BREAK_TRIM_END_EDGE_SPACES are enabled.
Texture2D get_button(column: int, button_index: int) const 🔗
返回在 column 列中索引為 button_index 的按鈕的 Texture。
int get_button_by_id(column: int, id: int) const 🔗
如果在 column 列中存在 ID 為 id 的按鈕,則返回其索引號,否則返回 -1。
Color get_button_color(column: int, id: int) const 🔗
Returns the color of the button with ID id in column column. If the specified button does not exist, returns Color.BLACK.
int get_button_count(column: int) const 🔗
返回在 column 列中按鈕的數量。
int get_button_id(column: int, button_index: int) const 🔗
返回在 column 列中索引為 button_index 的按鈕的 ID。
String get_button_tooltip_text(column: int, button_index: int) const 🔗
返回在 column 列中索引為 button_index 的按鈕的工具提示字元串。
TreeCellMode get_cell_mode(column: int) const 🔗
返回該列的儲存格模式。
TreeItem get_child(index: int) 🔗
按其 index 返回一個子項(參見 get_child_count())。該方法通常被用於反覆運算一個專案的所有子項。
負索引將從最後一個存取孩子。
返回子項的數量。
Array[TreeItem] get_children() 🔗
返回引用該專案子級的陣列。
Color get_custom_bg_color(column: int) const 🔗
返回列 column 的自訂背景色。
Color get_custom_color(column: int) const 🔗
返回列 column 的自訂顏色。
Callable get_custom_draw_callback(column: int) const 🔗
Returns the custom callback of column column.
Font get_custom_font(column: int) const 🔗
返回用於在 column 列繪製文字的自訂字形。
int get_custom_font_size(column: int) const 🔗
返回用於在 column 列繪製文字的自訂字形大小。
StyleBox get_custom_stylebox(column: int) const 🔗
Returns the given column's custom StyleBox used to draw the background.
String get_description(column: int) const 🔗
Returns the given column's description for assistive apps.
bool get_expand_right(column: int) const 🔗
如果設定了 expand_right,則返回 true。
TreeItem get_first_child() const 🔗
返回該 TreeItem 的第一個子項。
Texture2D get_icon(column: int) const 🔗
返回給定列的圖示 Texture2D。如果未設定圖示,則會出錯。
int get_icon_max_width(column: int) const 🔗
返回給定列 column 中圖示所允許的最大寬度。
Color get_icon_modulate(column: int) const 🔗
返回調變列的圖示的 Color 顏色。
Texture2D get_icon_overlay(column: int) const 🔗
Returns the given column's icon overlay Texture2D.
Rect2 get_icon_region(column: int) const 🔗
返回該節點在樹中的順序。例如對第一個子項呼叫時,得到的位置為 0。
String get_language(column: int) const 🔗
返回專案文字的語言程式碼。
Variant get_metadata(column: int) const 🔗
返回使用 set_metadata() 為指定列設定的中繼資料。
Returns the next sibling TreeItem in the tree or a null object if there is none.
TreeItem get_next_in_tree(wrap: bool = false) 🔗
返回樹中下一個同級 TreeItem(按照深度優先搜尋循序),如果不存在則返回 null 對象。
如果啟用了 wrap,則當在最後一個元素上調用時,該方法將繞回到樹中的第一個元素,否則它將返回 null。
TreeItem get_next_visible(wrap: bool = false) 🔗
返回樹中下一個可見的同級 TreeItem(按照深度優先循序搜尋),如果不存在則返回 null 對象。
如果啟用了 wrap,則當在最後一個元素上調用時,該方法將繞回到樹中的第一個可見元素,否則它將返回 null。
Returns the parent TreeItem or a null object if there is none.
Returns the previous sibling TreeItem in the tree or a null object if there is none.
TreeItem get_prev_in_tree(wrap: bool = false) 🔗
返回樹中前一個同級 TreeItem(按照深度優先循序搜尋),如果不存在則返回 null 對象。
如果啟用了 wrap,則在第一個可見元素上呼叫時,該方法將環繞到樹中的最後一個可見元素,否則它將返回 null。
TreeItem get_prev_visible(wrap: bool = false) 🔗
返回樹中前一個可見的同級 TreeItem(按照深度優先搜尋循序),如果不存在則返回 null 對象。
如果啟用了 wrap,則在第一個可見元素上呼叫時,該方法將繞回到樹中的最後一個可見元素,否則它將返回 null。
float get_range(column: int) const 🔗
返回 CELL_MODE_RANGE 列的值。
Dictionary get_range_config(column: int) 🔗
返回包含給定列的範圍參數的字典。鍵是“min”、“max”、“step”和“expr”。
StructuredTextParser get_structured_text_bidi_override(column: int) const 🔗
Returns the BiDi algorithm override set for this cell.
Array get_structured_text_bidi_override_options(column: int) const 🔗
Returns the additional BiDi options set for this cell.
String get_suffix(column: int) const 🔗
獲取顯示在列值後面的後綴字串。
String get_text(column: int) const 🔗
返回給定列的文字。
HorizontalAlignment get_text_alignment(column: int) const 🔗
返回給定列的文字對齊方式。
TextDirection get_text_direction(column: int) const 🔗
返回專案文字的基礎書寫方向。
OverrunBehavior get_text_overrun_behavior(column: int) const 🔗
返回給定列 column 的文字自動換行模式。預設為 TextServer.AUTOWRAP_OFF。
String get_tooltip_text(column: int) const 🔗
設定給定列的工具提示文字。
返回擁有此 TreeItem 的 Tree。
bool is_accepting_children() const 🔗
Returns true if this TreeItem is allowed to accept children.
bool is_any_collapsed(only_visible: bool = false) 🔗
如果這個 TreeItem 或其任意子級為折疊狀態,則返回 true。
如果 only_visible 為 true,則會忽略不可見的 TreeItem。
bool is_button_disabled(column: int, button_index: int) const 🔗
如果給定列 column 上索引為 button_index 的按鈕被禁用,則返回 true。
bool is_checked(column: int) const 🔗
如果給定的列 column 被勾選,則返回 true。
bool is_custom_set_as_button(column: int) const 🔗
Returns true if the cell was made into a button with set_custom_as_button().
bool is_edit_multiline(column: int) const 🔗
如果給定的列 column 可多行編輯,則返回 true。
bool is_editable(column: int) 🔗
如果給定的列 column 可編輯,則返回 true。
bool is_indeterminate(column: int) const 🔗
如果給定的列 column 未確定,則返回 true。
bool is_selectable(column: int) const 🔗
如果給定的列 column 可選,則返回 true。
bool is_selected(column: int) 🔗
如果給定的列 column 被選中,則返回 true。
bool is_visible_in_tree() const 🔗
Returns true if visible is true and all its ancestors are also visible.
void move_after(item: TreeItem) 🔗
將這個 TreeItem 移動至給定的 item 之後。
注意:無法移動至根部,也無法移動根部。
void move_before(item: TreeItem) 🔗
將這個 TreeItem 移動至給定的 item 之前。
注意:無法移動至根部,也無法移動根部。
void propagate_check(column: int, emit_signal: bool = true) 🔗
將該項的勾選狀態傳播給給定 column 的子項和父項。可以通過連接到 Tree.check_propagated_to_item 來處理受該方法呼叫影響的專案。受影響的專案的處理順序如下:呼叫該方法的專案、該項的子項,最後是該項的父項。如果 emit_signal 為 false,則不會發出 Tree.check_propagated_to_item。
void remove_child(child: TreeItem) 🔗
將給定的子項 TreeItem 和它的所有子項從 Tree 中移除。注意,它並未從記憶體中釋放該項,所以之後可重新使用(見 add_child())。要完全刪除 TreeItem,請使用 Object.free()。
注意:如果你想要將一個子項移動到其他 Tree 中,則不必手動先移除再添加,你可以使用 move_before() 或 move_after()。
void select(column: int, set_as_cursor: bool = true) 🔗
Selects the given column. If set_as_cursor is true, the Tree's cursor will be moved to this item (only matters if Tree.select_mode is set to Tree.SELECT_MULTI).
void set_accept_children(allowed: bool) 🔗
Sets TreeItem's ability to accept children.
void set_auto_translate_mode(column: int, mode: AutoTranslateMode) 🔗
Sets the given column's auto translate mode to mode.
All columns use Node.AUTO_TRANSLATE_MODE_INHERIT by default, which uses the same auto translate mode as the Tree itself.
void set_autowrap_mode(column: int, autowrap_mode: AutowrapMode) 🔗
設定給定 column 的自動換行模式。如果設定為 TextServer.AUTOWRAP_OFF 以外的值,則文字將在節點的邊界矩形內換行。
void set_autowrap_trim_flags(column: int, flags: BitField[LineBreakFlag]) 🔗
Sets the autowrap trim flags for the given column. These flags control whether leading and trailing spaces are trimmed on wrapped lines. Set to 0 to disable all trimming.
void set_button(column: int, button_index: int, button: Texture2D) 🔗
將給定列中索引為 button_index 的按鈕 Texture2D 設定為 button。
void set_button_color(column: int, button_index: int, color: Color) 🔗
將給定列中索引為 button_index 的按鈕顏色設定為 color。
void set_button_description(column: int, button_index: int, description: String) 🔗
Sets the given column's button description at index button_index for assistive apps.
void set_button_disabled(column: int, button_index: int, disabled: bool) 🔗
如果為 true,則禁用給定列 column 中索引為 button_index 的按鈕。
void set_button_tooltip_text(column: int, button_index: int, tooltip: String) 🔗
返回在 column 列中索引為 button_index 的按鈕的工具提示字元串。
void set_cell_mode(column: int, mode: TreeCellMode) 🔗
Sets the given column's cell mode to mode. This determines how the cell is displayed and edited.
void set_checked(column: int, checked: bool) 🔗
如果 checked 為 true,則給定列 column 處於勾選狀態。會清空該列的中間狀態。
void set_collapsed_recursive(enable: bool) 🔗
折疊或展開該 TreeItem 及該項的所有子級。
void set_custom_as_button(column: int, enable: bool) 🔗
Makes a cell with CELL_MODE_CUSTOM display as a non-flat button with a StyleBox.
void set_custom_bg_color(column: int, color: Color, just_outline: bool = false) 🔗
Sets the given column's custom background color and whether to just use it as an outline.
Note: If a custom StyleBox is set, the background color will be drawn behind it.
void set_custom_color(column: int, color: Color) 🔗
設定給定列的自訂顏色。
void set_custom_draw(column: int, object: Object, callback: StringName) 🔗
已棄用: Use set_custom_draw_callback() instead.
Sets the given column's custom draw callback to the callback method on object.
The method named callback should accept two arguments: the TreeItem that is drawn and its position and size as a Rect2.
void set_custom_draw_callback(column: int, callback: Callable) 🔗
Sets the given column's custom draw callback. Use an empty Callable (Callable()) to clear the custom callback. The cell has to be in CELL_MODE_CUSTOM to use this feature.
The callback should accept two arguments: the TreeItem that is drawn and its position and size as a Rect2.
To draw custom content over the native style, please use Tree.get_custom_drawing_canvas_item().
void set_custom_font(column: int, font: Font) 🔗
設定用於在給定列 column 中繪製文字的自訂字形。
void set_custom_font_size(column: int, font_size: int) 🔗
設定用於在給定列 column 中繪製文字的自訂字形大小。
void set_custom_stylebox(column: int, stylebox: StyleBox) 🔗
Sets the given column's custom StyleBox used to draw the background.
Note: If a custom background color is set, the StyleBox will be drawn in front of it.
void set_description(column: int, description: String) 🔗
Sets the given column's description for assistive apps.
void set_edit_multiline(column: int, multiline: bool) 🔗
如果 multiline 為 true,則給定的列 column 可進行多行編輯。
注意:這個選項僅影響編輯該列時所出現控制項的型別(LineEdit 或 TextEdit)。即便該列不可進行多行編輯,也可以通過 set_text() 來設定多行的值。
void set_editable(column: int, enabled: bool) 🔗
如果 enabled 為 true,則給定的列 column 可編輯。
void set_expand_right(column: int, enable: bool) 🔗
如果 enable 為 true,則給定的列 column 向右擴展。
void set_icon(column: int, texture: Texture2D) 🔗
Sets the given cell's icon Texture2D. If the cell is in CELL_MODE_ICON mode, the icon is displayed in the center of the cell. Otherwise, the icon is displayed before the cell's text. CELL_MODE_RANGE does not display an icon.
void set_icon_max_width(column: int, width: int) 🔗
設定給定列 column 所允許的最大圖示寬度。這是在圖示預設大小和 Tree.icon_max_width 的基礎上的限制。高度會根據圖示的長寬比調整。
void set_icon_modulate(column: int, modulate: Color) 🔗
用 modulate 調變給定列的圖示。
void set_icon_overlay(column: int, texture: Texture2D) 🔗
Sets the given cell's icon overlay Texture2D. The cell has to be in CELL_MODE_ICON mode, and icon has to be set. Overlay is drawn on top of icon, in the bottom left corner.
void set_icon_region(column: int, region: Rect2) 🔗
設定給定列的圖示的紋理區域。
void set_indeterminate(column: int, indeterminate: bool) 🔗
如果 indeterminate 為 true,則給定列 column 被標記為未決狀態。
注意:如果從 false 設定為 true,則該列的勾選狀態會被清除。
void set_language(column: int, language: String) 🔗
Sets the language code of the given column's text to language. This is used for line-breaking and text shaping algorithms. If language is empty, the current locale is used.
void set_metadata(column: int, meta: Variant) 🔗
設定給定列的中繼資料,之後可用 get_metadata() 進行檢索。例如,這可用於存儲對原始資料的引用。
void set_range(column: int, value: float) 🔗
設定 CELL_MODE_RANGE 列的值。
void set_range_config(column: int, min: float, max: float, step: float, expr: bool = false) 🔗
設定列的可接受值的範圍。該列必須處於 CELL_MODE_RANGE 模式。
如果 expr 為 true,則編輯模式滑桿將使用與 Range.exp_edit 一樣的指數刻度。
void set_selectable(column: int, selectable: bool) 🔗
如果 selectable 為 true,則給定列 column 可選。
void set_structured_text_bidi_override(column: int, parser: StructuredTextParser) 🔗
Set BiDi algorithm override for the structured text. Has effect for cells that display text.
void set_structured_text_bidi_override_options(column: int, args: Array) 🔗
Set additional options for BiDi override. Has effect for cells that display text.
void set_suffix(column: int, text: String) 🔗
設定字串,顯示在列的值之後(例如,單位的縮寫)。
void set_text(column: int, text: String) 🔗
設定給定列的文字值。
void set_text_alignment(column: int, text_alignment: HorizontalAlignment) 🔗
Sets the given column's text alignment to text_alignment.
void set_text_direction(column: int, direction: TextDirection) 🔗
設定專案文字的基礎書寫方向。
void set_text_overrun_behavior(column: int, overrun_behavior: OverrunBehavior) 🔗
設定文字超出專案的邊界矩形時的裁剪行為。所有模式的說明見 OverrunBehavior。
void set_tooltip_text(column: int, tooltip: String) 🔗
設定給定列的工具提示文字。
void uncollapse_tree() 🔗
Uncollapses all TreeItems necessary to reveal this TreeItem, i.e. all ancestor TreeItems.