Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
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 ( int column, Texture2D button, int id=-1, bool disabled=false, String tooltip_text="" ) |
void |
|
void |
call_recursive ( StringName method, ... ) vararg |
void |
clear_custom_bg_color ( int column ) |
void |
clear_custom_color ( int column ) |
create_child ( int index=-1 ) |
|
void |
|
void |
erase_button ( int column, int button_index ) |
get_autowrap_mode ( int column ) const |
|
get_button ( int column, int button_index ) const |
|
get_button_by_id ( int column, int id ) const |
|
get_button_count ( int column ) const |
|
get_button_id ( int column, int button_index ) const |
|
get_button_tooltip_text ( int column, int button_index ) const |
|
get_cell_mode ( int column ) const |
|
get_child_count ( ) |
|
get_children ( ) |
|
get_custom_bg_color ( int column ) const |
|
get_custom_color ( int column ) const |
|
get_custom_font ( int column ) const |
|
get_custom_font_size ( int column ) const |
|
get_expand_right ( int column ) const |
|
get_first_child ( ) const |
|
get_icon_max_width ( int column ) const |
|
get_icon_modulate ( int column ) const |
|
get_icon_region ( int column ) const |
|
get_index ( ) |
|
get_language ( int column ) const |
|
get_metadata ( int column ) const |
|
get_next ( ) const |
|
get_next_in_tree ( bool wrap=false ) |
|
get_next_visible ( bool wrap=false ) |
|
get_parent ( ) const |
|
get_prev ( ) |
|
get_prev_in_tree ( bool wrap=false ) |
|
get_prev_visible ( bool wrap=false ) |
|
get_range_config ( int column ) |
|
get_structured_text_bidi_override ( int column ) const |
|
get_structured_text_bidi_override_options ( int column ) const |
|
get_suffix ( int column ) const |
|
get_text_alignment ( int column ) const |
|
get_text_direction ( int column ) const |
|
get_text_overrun_behavior ( int column ) const |
|
get_tooltip_text ( int column ) const |
|
get_tree ( ) const |
|
is_any_collapsed ( bool only_visible=false ) |
|
is_button_disabled ( int column, int button_index ) const |
|
is_checked ( int column ) const |
|
is_custom_set_as_button ( int column ) const |
|
is_edit_multiline ( int column ) const |
|
is_editable ( int column ) |
|
is_indeterminate ( int column ) const |
|
is_selectable ( int column ) const |
|
is_selected ( int column ) |
|
void |
move_after ( TreeItem item ) |
void |
move_before ( TreeItem item ) |
void |
propagate_check ( int column, bool emit_signal=true ) |
void |
remove_child ( TreeItem child ) |
void |
|
void |
set_autowrap_mode ( int column, AutowrapMode autowrap_mode ) |
void |
set_button ( int column, int button_index, Texture2D button ) |
void |
set_button_color ( int column, int button_index, Color color ) |
void |
set_button_disabled ( int column, int button_index, bool disabled ) |
void |
set_button_tooltip_text ( int column, int button_index, String tooltip ) |
void |
set_cell_mode ( int column, TreeCellMode mode ) |
void |
set_checked ( int column, bool checked ) |
void |
set_collapsed_recursive ( bool enable ) |
void |
set_custom_as_button ( int column, bool enable ) |
void |
set_custom_bg_color ( int column, Color color, bool just_outline=false ) |
void |
set_custom_color ( int column, Color color ) |
void |
set_custom_draw ( int column, Object object, StringName callback ) |
void |
set_custom_font ( int column, Font font ) |
void |
set_custom_font_size ( int column, int font_size ) |
void |
set_edit_multiline ( int column, bool multiline ) |
void |
set_editable ( int column, bool enabled ) |
void |
set_expand_right ( int column, bool enable ) |
void |
|
void |
set_icon_max_width ( int column, int width ) |
void |
set_icon_modulate ( int column, Color modulate ) |
void |
set_icon_region ( int column, Rect2 region ) |
void |
set_indeterminate ( int column, bool indeterminate ) |
void |
set_language ( int column, String language ) |
void |
set_metadata ( int column, Variant meta ) |
void |
|
void |
set_range_config ( int column, float min, float max, float step, bool expr=false ) |
void |
set_selectable ( int column, bool selectable ) |
void |
set_structured_text_bidi_override ( int column, StructuredTextParser parser ) |
void |
set_structured_text_bidi_override_options ( int column, Array args ) |
void |
set_suffix ( int column, String text ) |
void |
|
void |
set_text_alignment ( int column, HorizontalAlignment text_alignment ) |
void |
set_text_direction ( int column, TextDirection direction ) |
void |
set_text_overrun_behavior ( int column, OverrunBehavior overrun_behavior ) |
void |
set_tooltip_text ( int column, String tooltip ) |
void |
uncollapse_tree ( ) |
枚举¶
enum TreeCellMode:
TreeCellMode CELL_MODE_STRING = 0
单元包含字符串。
TreeCellMode CELL_MODE_CHECK = 1
单元格包含复选框。
TreeCellMode CELL_MODE_RANGE = 2
单元包含一个范围。
TreeCellMode CELL_MODE_ICON = 3
单元包含图标。
TreeCellMode CELL_MODE_CUSTOM = 4
属性说明¶
bool collapsed
如果为 true
,则该 TreeItem 被折叠。
int custom_minimum_height
自定义最小高度。
bool disable_folding
如果为 true
,则这个 TreeItem 禁用折叠。
bool visible
如果为 true
,则该 TreeItem 可见(默认)。
请注意,如果将 TreeItem 设置为不可见,则其子项也将不可见。
方法说明¶
void add_button ( int column, Texture2D button, int id=-1, bool disabled=false, String tooltip_text="" )
在 column
列添加一个带有 Texture button
的按钮。id
用于标识按钮。如果未指定,则使用下一个可用索引,可以在此方法之前调用 get_button_count 来获取该索引。另外,该按钮还可以通过 disabled
禁用、通过 tooltip_text
设置工具提示。
void add_child ( TreeItem child )
将已解除父子关系的 TreeItem 添加为这个树项的直接子项。child
树项必须不是任何 Tree 的一部分,也不能有任何 TreeItem 父级。另见 remove_child。
void call_recursive ( StringName method, ... ) vararg
递归调用在实际 TreeItem 及其子项上的 method
。将参数作为一个逗号分隔列表传递。
void clear_custom_bg_color ( int column )
重置指定列默认的背景颜色。
void clear_custom_color ( int column )
重置指定列默认的颜色。
TreeItem create_child ( int index=-1 )
创建项目并添加为子项。
新建的项目会插入到索引 index
位置(默认的 -1
表示最后的位置),如果 index
比子项数量大则会作为最后一项。
void deselect ( int column )
取消选择指定列。
void erase_button ( int column, int button_index )
删除列 column
中索引 button_index
处的按钮。
AutowrapMode get_autowrap_mode ( int column ) const
返回给定列 column
的文本自动换行模式。默认为 TextServer.AUTOWRAP_OFF。
Texture2D get_button ( int column, int button_index ) const
返回在 column
列中索引为 button_index
的按钮的 Texture。
int get_button_by_id ( int column, int id ) const
如果在 column
列中存在 ID 为 id
的按钮,则返回其索引号,否则返回 -1。
int get_button_count ( int column ) const
返回在 column
列中按钮的数量。
int get_button_id ( int column, int button_index ) const
返回在 column
列中索引为 button_index
的按钮的 ID。
String get_button_tooltip_text ( int column, int button_index ) const
返回在 column
列中索引为 button_index
的按钮的工具提示字符串。
TreeCellMode get_cell_mode ( int column ) const
返回该列的单元格模式。
TreeItem get_child ( int index )
按其 index
返回一个子项(参见 get_child_count)。该方法通常被用于迭代一个项目的所有子项。
负索引将从最后一个访问孩子。
int get_child_count ( )
返回子项的数量。
TreeItem[] get_children ( )
返回引用该项目子级的数组。
Color get_custom_bg_color ( int column ) const
返回列 column
的自定义背景色。
Color get_custom_color ( int column ) const
返回列 column
的自定义颜色。
Font get_custom_font ( int column ) const
返回用于在 column
列绘制文本的自定义字体。
int get_custom_font_size ( int column ) const
返回用于在 column
列绘制文本的自定义字体大小。
bool get_expand_right ( int column ) const
如果设置了 expand_right
,则返回 true
。
TreeItem get_first_child ( ) const
返回该 TreeItem 的第一个子项。
Texture2D get_icon ( int column ) const
返回给定列的图标 Texture2D。如果未设置图标,则会出错。
int get_icon_max_width ( int column ) const
返回给定列 column
中图标所允许的最大宽度。
Color get_icon_modulate ( int column ) const
返回调制列的图标的 Color 颜色。
Rect2 get_icon_region ( int column ) const
int get_index ( )
返回该节点在树中的顺序。例如对第一个子项调用时,得到的位置为 0
。
String get_language ( int column ) const
返回项目文本的语言代码。
Variant get_metadata ( int column ) const
返回使用 set_metadata 为指定列设置的元数据。
TreeItem get_next ( ) const
返回树中的下一个兄弟 TreeItem,如果没有,则返回一个空对象。
TreeItem get_next_in_tree ( bool wrap=false )
返回树中下一个可见的同级 TreeItem(按照深度优先顺序搜索),如果不存在则返回 null
对象。
如果启用了 wrap
,则当在最后一个元素调用时,该方法将环绕到树中的第一个可见元素,否则它将返回 null
。
TreeItem get_next_visible ( bool wrap=false )
返回树中下一个可见的同级 TreeItem(按照深度优先顺序搜索),如果不存在则返回 null
对象。
如果启用了 wrap
,则当在最后一个可见元素调用时,该方法将环绕到树中的第一个可见元素,否则它将返回 null
。
TreeItem get_parent ( ) const
返回父级 TreeItem,如果没有,则返回一个空对象。
TreeItem get_prev ( )
返回树中的前一个兄弟 TreeItem,如果没有,则返回一个空对象。
TreeItem get_prev_in_tree ( bool wrap=false )
返回树中前一个同级 TreeItem(按照深度优先顺序搜索),如果不存在则返回 null
对象。
如果启用了 wrap
,则在第一个可见元素上调用时,该方法将环绕到树中的最后一个可见元素,否则它将返回 null
。
TreeItem get_prev_visible ( bool wrap=false )
返回树中前一个可见的同级 TreeItem(按照深度优先顺序搜索),如果不存在则返回 null
对象。
如果启用了 wrap
,则在第一个可见元素上调用时,该方法将环绕到树中的最后一个可见元素,否则它将返回 null
。
float get_range ( int column ) const
返回 CELL_MODE_RANGE 列的值。
Dictionary get_range_config ( int column )
返回包含给定列的范围参数的字典。键是“min”、“max”、“step”和“expr”。
StructuredTextParser get_structured_text_bidi_override ( int column ) const
目前没有这个方法的描述。请帮我们贡献一个!
Array get_structured_text_bidi_override_options ( int column ) const
目前没有这个方法的描述。请帮我们贡献一个!
String get_suffix ( int column ) const
获取显示在列值后面的后缀字符串。
String get_text ( int column ) const
返回给定列的文本。
HorizontalAlignment get_text_alignment ( int column ) const
返回给定列的文本对齐方式。
TextDirection get_text_direction ( int column ) const
返回项目文本的基础书写方向。
OverrunBehavior get_text_overrun_behavior ( int column ) const
返回当给定 column
中文本超出项目的边界矩形时的裁剪行为。默认情况下它是 TextServer.OVERRUN_TRIM_ELLIPSIS。
String get_tooltip_text ( int column ) const
设置给定列的工具提示文本。
Tree get_tree ( ) const
返回拥有此 TreeItem 的 Tree。
bool is_any_collapsed ( bool only_visible=false )
如果这个 TreeItem 或其任意子级为折叠状态,则返回 true
。
如果 only_visible
为 true
,则会忽略不可见的 TreeItem。
bool is_button_disabled ( int column, int button_index ) const
如果给定列 column
上索引为 button_index
的按钮被禁用,则返回 true
。
bool is_checked ( int column ) const
如果给定的列 column
被勾选,则返回 true
。
bool is_custom_set_as_button ( int column ) const
目前没有这个方法的描述。请帮我们贡献一个!
bool is_edit_multiline ( int column ) const
如果给定的列 column
可多行编辑,则返回 true
。
bool is_editable ( int column )
如果给定的列 column
可编辑,则返回 true
。
bool is_indeterminate ( int column ) const
如果给定的列 column
未确定,则返回 true
。
bool is_selectable ( int column ) const
如果给定的列 column
可选,则返回 true
。
bool is_selected ( int column )
如果给定的列 column
被选中,则返回 true
。
void move_after ( TreeItem item )
将这个 TreeItem 移动至给定的 item
之后。
注意:无法移动至根部,也无法移动根部。
void move_before ( TreeItem item )
将这个 TreeItem 移动至给定的 item
之前。
注意:无法移动至根部,也无法移动根部。
void propagate_check ( int column, bool emit_signal=true )
将该项的勾选状态传播给给定 column
的子项和父项。可以通过连接到 Tree.check_propagated_to_item 来处理受该方法调用影响的项目。受影响的项目的处理顺序如下:调用该方法的项目、该项的子项,最后是该项的父项。如果 emit_signal
为 false
,则不会发出 Tree.check_propagated_to_item。
void remove_child ( TreeItem child )
将给定的子项 TreeItem 和它的所有子项从 Tree 中移除。注意,它并未从内存中释放该项,所以之后可重新使用(见 add_child)。要完全删除 TreeItem,请使用 Object.free。
注意:如果你想要将一个子项移动到其他 Tree 中,则不必手动先移除再添加,你可以使用 move_before 或 move_after。
void select ( int column )
选中 column
指定的列。
void set_autowrap_mode ( int column, AutowrapMode autowrap_mode )
设置给定 column
的自动换行模式。如果设置为 TextServer.AUTOWRAP_OFF 以外的值,则文本将在节点的边界矩形内换行。
void set_button ( int column, int button_index, Texture2D button )
将给定列中索引为 button_index
的按钮 Texture2D 设置为 button
。
void set_button_color ( int column, int button_index, Color color )
将给定列中索引为 button_index
的按钮颜色设置为 color
。
void set_button_disabled ( int column, int button_index, bool disabled )
如果为 true
,则禁用给定列 column
中索引为 button_index
的按钮。
void set_bu