Class TreeItem
An internal control for a single item inside Tree.
- Inheritance
-
TreeItem
Remarks
A single item of a Tree control. It can contain other TreeItems as children, which allows it to create a hierarchy. It can also contain text and buttons. TreeItem is not a Node, it is internal to the Tree.
To create a TreeItem, use Tree.create_item or TreeItem.create_child. To remove a TreeItem, use free.
Note: The ID values used for buttons are 32-bit, unlike int which is always 64-bit. They go from -2147483648
to 2147483647
.
Properties
collapsed
If true
, the TreeItem is collapsed.
var collapsed : bool
Property Value
Remarks
custom_minimum_height
The custom minimum height.
var custom_minimum_height : int
Property Value
Remarks
disable_folding
If true
, folding is disabled for this TreeItem.
var disable_folding : bool
Property Value
Remarks
visible
If true
, the TreeItem is visible (default).
Note that if a TreeItem is set to not be visible, none of its children will be visible either.
var visible : bool
Property Value
Remarks
Methods
add_button(int, Texture2D, int, bool, 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 TreeItem.get_button_count immediately before this method. Optionally, the button can be disabled
and have a tooltip_text
.
void add_button(int column, Texture2D button, int id, bool disabled, String tooltip_text)
Parameters
add_child(TreeItem)
Adds a previously unparented TreeItem as a direct child of this one. The child
item must not be a part of any Tree or parented to any TreeItem. See also TreeItem.remove_child.
void add_child(TreeItem child)
Parameters
child
TreeItem
call_recursive(StringName, ...)
Qualifiers: vararg
Calls the method
on the actual TreeItem and its children recursively. Pass parameters as a comma separated list.
void call_recursive(StringName method, ...)
Parameters
method
StringName
clear_buttons
Removes all buttons from all columns of this item.
void clear_buttons
clear_custom_bg_color(int)
Resets the background color for the given column to default.
void clear_custom_bg_color(int column)
Parameters
column
int
clear_custom_color(int)
Resets the color for the given column to default.
void clear_custom_color(int column)
Parameters
column
int
create_child(int)
Creates an item and adds it as a child.
The new item will be inserted as position index
(the default value -1
means the last position), or it will be the last child if index
is higher than the child count.
TreeItem create_child(int index)
Parameters
index
int
deselect(int)
Deselects the given column.
void deselect(int column)
Parameters
column
int
erase_button(int, int)
Removes the button at index button_index
in column column
.
void erase_button(int column, int button_index)
Parameters
get_auto_translate_mode(int)
Qualifiers: const
Returns the column's auto translate mode.
int get_auto_translate_mode(int column)
Parameters
column
int
get_autowrap_mode(int)
Qualifiers: const
Returns the text autowrap mode in the given column
. By default it is TextServer.AUTOWRAP_OFF.
int get_autowrap_mode(int column)
Parameters
column
int
get_button(int, int)
Qualifiers: const
Returns the Texture2D of the button at index button_index
in column column
.
Texture2D get_button(int column, int button_index)
Parameters
get_button_by_id(int, int)
Qualifiers: const
Returns the button index if there is a button with ID id
in column column
, otherwise returns -1.
int get_button_by_id(int column, int id)
Parameters
get_button_color(int, int)
Qualifiers: const
Returns the color of the button with ID id
in column column
. If the specified button does not exist, returns BLACK.
Color get_button_color(int column, int id)
Parameters
get_button_count(int)
Qualifiers: const
Returns the number of buttons in column column
.
int get_button_count(int column)
Parameters
column
int
get_button_id(int, int)
Qualifiers: const
Returns the ID for the button at index button_index
in column column
.
int get_button_id(int column, int button_index)
Parameters
get_button_tooltip_text(int, int)
Qualifiers: const
Returns the tooltip text for the button at index button_index
in column column
.
String get_button_tooltip_text(int column, int button_index)
Parameters
get_cell_mode(int)
Qualifiers: const
Returns the column's cell mode.
int get_cell_mode(int column)
Parameters
column
int
get_child(int)
Returns a child item by its index
(see get_child_count). This method is often used for iterating all children of an item.
Negative indices access the children from the last one.
TreeItem get_child(int index)
Parameters
index
int
get_child_count
Returns the number of child items.
int get_child_count
get_children
Returns an array of references to the item's children.
TreeItem[] get_children
get_custom_bg_color(int)
Qualifiers: const
Returns the custom background color of column column
.
Color get_custom_bg_color(int column)
Parameters
column
int
get_custom_color(int)
Qualifiers: const
Returns the custom color of column column
.
Color get_custom_color(int column)
Parameters
column
int
get_custom_draw_callback(int)
Qualifiers: const
Returns the custom callback of column column
.
Callable get_custom_draw_callback(int column)
Parameters
column
int
get_custom_font(int)
Qualifiers: const
Returns custom font used to draw text in the column column
.
Font get_custom_font(int column)
Parameters
column
int
get_custom_font_size(int)
Qualifiers: const
Returns custom font size used to draw text in the column column
.
int get_custom_font_size(int column)
Parameters
column
int
get_expand_right(int)
Qualifiers: const
Returns true
if expand_right
is set.
bool get_expand_right(int column)
Parameters
column
int
get_first_child
Qualifiers: const
Returns the TreeItem's first child.
TreeItem get_first_child
get_icon(int)
Qualifiers: const
Returns the given column's icon Texture2D. Error if no icon is set.
Texture2D get_icon(int column)
Parameters
column
int
get_icon_max_width(int)
Qualifiers: const
Returns the maximum allowed width of the icon in the given column
.
int get_icon_max_width(int column)
Parameters
column
int
get_icon_modulate(int)
Qualifiers: const
Returns the Color modulating the column's icon.
Color get_icon_modulate(int column)
Parameters
column
int
get_icon_overlay(int)
Qualifiers: const
Returns the given column's icon overlay Texture2D.
Texture2D get_icon_overlay(int column)
Parameters
column
int
get_icon_region(int)
Rect2 get_icon_region(int column)
Parameters
column
int
get_index
Returns the node's order in the tree. For example, if called on the first child item the position is 0
.
int get_index
get_language(int)
Qualifiers: const
Returns item's text language code.
String get_language(int column)
Parameters
column
int
get_metadata(int)
Qualifiers: const
Returns the metadata value that was set for the given column using TreeItem.set_metadata.
Variant get_metadata(int column)
Parameters
column
int
get_next
Qualifiers: const
Returns the next sibling TreeItem in the tree or a null
object if there is none.
TreeItem get_next
get_next_in_tree(bool)
Returns the next TreeItem in the tree (in the context of a depth-first search) or a null
object if there is none.
If wrap
is enabled, the method will wrap around to the first element in the tree when called on the last element, otherwise it returns null
.
TreeItem get_next_in_tree(bool wrap)
Parameters
wrap
bool
get_next_visible(bool)
Returns the next visible TreeItem in the tree (in the context of a depth-first search) or a null
object if there is none.
If wrap
is enabled, the method will wrap around to the first visible element in the tree when called on the last visible element, otherwise it returns null
.
TreeItem get_next_visible(bool wrap)
Parameters
wrap
bool
get_parent
Qualifiers: const
Returns the parent TreeItem or a null
object if there is none.
TreeItem get_parent
get_prev
Returns the previous sibling TreeItem in the tree or a null
object if there is none.
TreeItem get_prev
get_prev_in_tree(bool)
Returns the previous TreeItem in the tree (in the context of a depth-first search) or a null
object if there is none.
If wrap
is enabled, the method will wrap around to the last element in the tree when called on the first visible element, otherwise it returns null
.
TreeItem get_prev_in_tree(bool wrap)
Parameters
wrap
bool
get_prev_visible(bool)
Returns the previous visible sibling TreeItem in the tree (in the context of a depth-first search) or a null
object if there is none.
If wrap
is enabled, the method will wrap around to the last visible element in the tree when called on the first visible element, otherwise it returns null
.
TreeItem get_prev_visible(bool wrap)
Parameters
wrap
bool
get_range(int)
Qualifiers: const
Returns the value of a TreeItem.CELL_MODE_RANGE column.
float get_range(int column)
Parameters
column
int
get_range_config(int)
Returns a dictionary containing the range parameters for a given column. The keys are "min", "max", "step", and "expr".
Dictionary get_range_config(int column)
Parameters
column
int
get_structured_text_bidi_override(int)
Qualifiers: const
Returns the BiDi algorithm override set for this cell.
int get_structured_text_bidi_override(int column)
Parameters
column
int
get_structured_text_bidi_override_options(int)
Qualifiers: const
Returns the additional BiDi options set for this cell.
Array get_structured_text_bidi_override_options(int column)
Parameters
column
int
get_suffix(int)
Qualifiers: const
Gets the suffix string shown after the column value.
String get_suffix(int column)
Parameters
column
int
get_text(int)
Qualifiers: const
Returns the given column's text.
String get_text(int column)
Parameters
column
int
get_text_alignment(int)
Qualifiers: const
Returns the given column's text alignment.
int get_text_alignment(int column)
Parameters
column
int
get_text_direction(int)
Qualifiers: const
Returns item's text base writing direction.
int get_text_direction(int column)
Parameters
column
int
get_text_overrun_behavior(int)
Qualifiers: const
Returns the clipping behavior when the text exceeds the item's bounding rectangle in the given column
. By default it is TextServer.OVERRUN_TRIM_ELLIPSIS.
int get_text_overrun_behavior(int column)
Parameters
column
int
get_tooltip_text(int)
Qualifiers: const
Returns the given column's tooltip text.
String get_tooltip_text(int column)
Parameters
column
int
get_tree
Qualifiers: const
Returns the Tree that owns this TreeItem.
Tree get_tree
is_any_collapsed(bool)
Returns true
if this TreeItem, or any of its descendants, is collapsed.
If only_visible
is true
it ignores non-visible TreeItems.
bool is_any_collapsed(bool only_visible)
Parameters
only_visible
bool
is_button_disabled(int, int)
Qualifiers: const
Returns true
if the button at index button_index
for the given column
is disabled.
bool is_button_disabled(int column, int button_index)
Parameters
is_checked(int)
Qualifiers: const
Returns true
if the given column
is checked.
bool is_checked(int column)
Parameters
column
int
is_custom_set_as_button(int)
Qualifiers: const
Returns true
if the cell was made into a button with TreeItem.set_custom_as_button.
bool is_custom_set_as_button(int column)
Parameters
column
int
is_edit_multiline(int)
Qualifiers: const
Returns true
if the given column
is multiline editable.
bool is_edit_multiline(int column)
Parameters
column
int
is_editable(int)
Returns true
if the given column
is editable.
bool is_editable(int column)
Parameters
column
int
is_indeterminate(int)
Qualifiers: const
Returns true
if the given column
is indeterminate.
bool is_indeterminate(int column)
Parameters
column
int
is_selectable(int)
Qualifiers: const
Returns true
if the given column
is selectable.
bool is_selectable(int column)
Parameters
column
int
is_selected(int)
Returns true
if the given column
is selected.
bool is_selected(int column)
Parameters
column
int
is_visible_in_tree
Qualifiers: const
Returns true
if visible is true
and all its ancestors are also visible.
bool is_visible_in_tree
move_after(TreeItem)
Moves this TreeItem right after the given item
.
Note: You can't move to the root or move the root.
void move_after(TreeItem item)
Parameters
item
TreeItem
move_before(TreeItem)
Moves this TreeItem right before the given item
.
Note: You can't move to the root or move the root.
void move_before(TreeItem item)
Parameters
item
TreeItem
propagate_check(int, bool)
Propagates this item's checked status to its children and parents for the given column
. It is possible to process the items affected by this method call by connecting to Tree.check_propagated_to_item. The order that the items affected will be processed is as follows: the item invoking this method, children of that item, and finally parents of that item. If emit_signal
is false
, then Tree.check_propagated_to_item will not be emitted.
void propagate_check(int column, bool emit_signal)
Parameters
remove_child(TreeItem)
Removes the given child TreeItem and all its children from the Tree. Note that it doesn't free the item from memory, so it can be reused later (see TreeItem.add_child). To completely remove a TreeItem use free.
Note: If you want to move a child from one Tree to another, then instead of removing and adding it manually you can use TreeItem.move_before or TreeItem.move_after.
void remove_child(TreeItem child)
Parameters
child
TreeItem
select(int)
Selects the given column
.
void select(int column)
Parameters
column
int
set_auto_translate_mode(int, int)
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_auto_translate_mode(int column, int mode)
Parameters
set_autowrap_mode(int, int)
Sets the autowrap mode in the given column
. If set to something other than TextServer.AUTOWRAP_OFF, the text gets wrapped inside the cell's bounding rectangle.
void set_autowrap_mode(int column, int autowrap_mode)
Parameters
set_button(int, int, Texture2D)
Sets the given column's button Texture2D at index button_index
to button
.
void set_button(int column, int button_index, Texture2D button)
Parameters
set_button_color(int, int, Color)
Sets the given column's button color at index button_index
to color
.
void set_button_color(int column, int button_index, Color color)
Parameters
set_button_disabled(int, int, bool)
If true
, disables the button at index button_index
in the given column
.
void set_button_disabled(int column, int button_index, bool disabled)
Parameters
set_button_tooltip_text(int, int, String)
Sets the tooltip text for the button at index button_index
in the given column
.
void set_button_tooltip_text(int column, int button_index, String tooltip)
Parameters
set_cell_mode(int, int)
Sets the given column's cell mode to mode
. This determines how the cell is displayed and edited. See TreeCellMode constants for details.
void set_cell_mode(int column, int mode)
Parameters
set_checked(int, bool)
If checked
is true
, the given column
is checked. Clears column's indeterminate status.
void set_checked(int column, bool checked)
Parameters
set_collapsed_recursive(bool)
Collapses or uncollapses this TreeItem and all the descendants of this item.
void set_collapsed_recursive(bool enable)
Parameters
enable
bool
set_custom_as_button(int, bool)
Makes a cell with TreeItem.CELL_MODE_CUSTOM display as a non-flat button with a StyleBox.
void set_custom_as_button(int column, bool enable)
Parameters
set_custom_bg_color(int, Color, bool)
Sets the given column's custom background color and whether to just use it as an outline.
void set_custom_bg_color(int column, Color color, bool just_outline)
Parameters
set_custom_color(int, Color)
Sets the given column's custom color.
void set_custom_color(int column, Color color)
Parameters
set_custom_draw(int, Object, StringName)
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(int column, Object object, StringName callback)
Parameters
column
intobject
Objectcallback
StringName
set_custom_draw_callback(int, 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 TreeItem.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.
void set_custom_draw_callback(int column, Callable callback)
Parameters
set_custom_font(int, Font)
Sets custom font used to draw text in the given column
.
void set_custom_font(int column, Font font)
Parameters
set_custom_font_size(int, int)
Sets custom font size used to draw text in the given column
.
void set_custom_font_size(int column, int font_size)
Parameters
set_edit_multiline(int, bool)
If multiline
is true
, the given column
is multiline editable.
Note: This option only affects the type of control (LineEdit or TextEdit) that appears when editing the column. You can set multiline values with TreeItem.set_text even if the column is not multiline editable.
void set_edit_multiline(int column, bool multiline)
Parameters
set_editable(int, bool)
If enabled
is true
, the given column
is editable.
void set_editable(int column, bool enabled)
Parameters
set_expand_right(int, bool)
If enable
is true
, the given column
is expanded to the right.
void set_expand_right(int column, bool enable)
Parameters
set_icon(int, Texture2D)
Sets the given cell's icon Texture2D. If the cell is in TreeItem.CELL_MODE_ICON mode, the icon is displayed in the center of the cell. Otherwise, the icon is displayed before the cell's text. TreeItem.CELL_MODE_RANGE does not display an icon.
void set_icon(int column, Texture2D texture)
Parameters
set_icon_max_width(int, int)
Sets the maximum allowed width of the icon in the given column
. This limit is applied on top of the default size of the icon and on top of icon_max_width. The height is adjusted according to the icon's ratio.
void set_icon_max_width(int column, int width)
Parameters
set_icon_modulate(int, Color)
Modulates the given column's icon with modulate
.
void set_icon_modulate(int column, Color modulate)
Parameters
set_icon_overlay(int, Texture2D)
Sets the given cell's icon overlay Texture2D. The cell has to be in TreeItem.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_overlay(int column, Texture2D texture)
Parameters
set_icon_region(int, Rect2)
Sets the given column's icon's texture region.
void set_icon_region(int column, Rect2 region)
Parameters
set_indeterminate(int, bool)
If indeterminate
is true
, the given column
is marked indeterminate.
Note: If set true
from false
, then column is cleared of checked status.
void set_indeterminate(int column, bool indeterminate)
Parameters
set_language(int, String)
Sets language code of item's text used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
void set_language(int column, String language)
Parameters
set_metadata(int, Variant)
Sets the metadata value for the given column, which can be retrieved later using TreeItem.get_metadata. This can be used, for example, to store a reference to the original data.
void set_metadata(int column, Variant meta)
Parameters
set_range(int, float)
Sets the value of a TreeItem.CELL_MODE_RANGE column.
void set_range(int column, float value)
Parameters
set_range_config(int, float, float, float, bool)
Sets the range of accepted values for a column. The column must be in the TreeItem.CELL_MODE_RANGE mode.
If expr
is true
, the edit mode slider will use an exponential scale as with exp_edit.
void set_range_config(int column, float min, float max, float step, bool expr)
Parameters
set_selectable(int, bool)
If selectable
is true
, the given column
is selectable.
void set_selectable(int column, bool selectable)
Parameters
set_structured_text_bidi_override(int, int)
Set BiDi algorithm override for the structured text. Has effect for cells that display text.
void set_structured_text_bidi_override(int column, int parser)
Parameters
set_structured_text_bidi_override_options(int, Array)
Set additional options for BiDi override. Has effect for cells that display text.
void set_structured_text_bidi_override_options(int column, Array args)
Parameters
set_suffix(int, String)
Sets a string to be shown after a column's value (for example, a unit abbreviation).
void set_suffix(int column, String text)
Parameters
set_text(int, String)
Sets the given column's text value.
void set_text(int column, String text)
Parameters
set_text_alignment(int, int)
Sets the given column's text alignment. See HorizontalAlignment for possible values.
void set_text_alignment(int column, int text_alignment)
Parameters
set_text_direction(int, int)
Sets item's text base writing direction.
void set_text_direction(int column, int direction)
Parameters
set_text_overrun_behavior(int, int)
Sets the clipping behavior when the text exceeds the item's bounding rectangle in the given column
.
void set_text_overrun_behavior(int column, int overrun_behavior)
Parameters
set_tooltip_text(int, String)
Sets the given column's tooltip text.
void set_tooltip_text(int column, String tooltip)
Parameters
uncollapse_tree
Uncollapses all TreeItems necessary to reveal this TreeItem, i.e. all ancestor TreeItems.
void uncollapse_tree