Up to date

This page is up to date for Godot 4.1. If you still find outdated information, please open an issue.

TreeItem

Inherits: Object

An internal control for a single item inside Tree.

Description

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 create_child. To remove a TreeItem, use Object.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

bool

collapsed

int

custom_minimum_height

bool

disable_folding

bool

visible

Methods

void

add_button ( int column, Texture2D button, int id=-1, bool disabled=false, String tooltip_text=”” )

void

add_child ( TreeItem child )

void

call_recursive ( StringName method, … ) vararg

void

clear_custom_bg_color ( int column )

void

clear_custom_color ( int column )

TreeItem

create_child ( int index=-1 )

void

deselect ( int column )

void

erase_button ( int column, int button_index )

AutowrapMode

get_autowrap_mode ( int column ) const

Texture2D

get_button ( int column, int button_index ) const

int

get_button_by_id ( int column, int id ) const

int

get_button_count ( int column ) const

int

get_button_id ( int column, int button_index ) const

String

get_button_tooltip_text ( int column, int button_index ) const

TreeCellMode

get_cell_mode ( int column ) const

TreeItem

get_child ( int index )

int

get_child_count ( )

TreeItem[]

get_children ( )

Color

get_custom_bg_color ( int column ) const

Color

get_custom_color ( int column ) const

Font

get_custom_font ( int column ) const

int

get_custom_font_size ( int column ) const

bool

get_expand_right ( int column ) const

TreeItem

get_first_child ( ) const

Texture2D

get_icon ( int column ) const

int

get_icon_max_width ( int column ) const

Color

get_icon_modulate ( int column ) const

Rect2

get_icon_region ( int column ) const

int

get_index ( )

String

get_language ( int column ) const

Variant

get_metadata ( int column ) const

TreeItem

get_next ( ) const

TreeItem

get_next_in_tree ( bool wrap=false )

TreeItem

get_next_visible ( bool wrap=false )

TreeItem

get_parent ( ) const

TreeItem

get_prev ( )

TreeItem

get_prev_in_tree ( bool wrap=false )

TreeItem

get_prev_visible ( bool wrap=false )

float

get_range ( int column ) const

Dictionary

get_range_config ( int column )

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

String

get_tooltip_text ( int column ) const

Tree

get_tree ( ) const

bool

is_any_collapsed ( bool only_visible=false )

bool

is_button_disabled ( int column, int button_index ) const

bool

is_checked ( int column ) const

bool

is_custom_set_as_button ( int column ) const

bool

is_edit_multiline ( int column ) const

bool

is_editable ( int column )

bool

is_indeterminate ( int column ) const

bool

is_selectable ( int column ) const

bool

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

select ( int column )

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_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

set_icon ( int column, Texture2D texture )

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

set_range ( int column, float value )

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

set_text ( int column, String text )

void

set_text_alignment ( int column, HorizontalAlignment text_alignment )

void

set_text_direction ( int column, TextDirection direction )

void

set_tooltip_text ( int column, String tooltip )

void

uncollapse_tree ( )


Enumerations

enum TreeCellMode:

TreeCellMode CELL_MODE_STRING = 0

Cell contains a string.

TreeCellMode CELL_MODE_CHECK = 1

Cell contains a checkbox.

TreeCellMode CELL_MODE_RANGE = 2

Cell contains a range.

TreeCellMode CELL_MODE_ICON = 3

Cell contains an icon.

TreeCellMode CELL_MODE_CUSTOM = 4


Property Descriptions

bool collapsed

  • void set_collapsed ( bool value )

  • bool is_collapsed ( )

If true, the TreeItem is collapsed.


int custom_minimum_height

  • void set_custom_minimum_height ( int value )

  • int get_custom_minimum_height ( )

The custom minimum height.


bool disable_folding

  • void set_disable_folding ( bool value )

  • bool is_folding_disabled ( )

If true, folding is disabled for this TreeItem.


bool visible

  • void set_visible ( bool value )

  • bool is_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.


Method Descriptions

void add_button ( int column, Texture2D button, int id=-1, bool disabled=false, String tooltip_text=”” )

Adds a button with Texture2D button 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.


void add_child ( TreeItem child )

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 remove_child.


void call_recursive ( StringName method, … ) vararg

Calls the method on the actual TreeItem and its children recursively. Pass parameters as a comma separated list.


void clear_custom_bg_color ( int column )

Resets the background color for the given column to default.


void clear_custom_color ( int column )

Resets the color for the given column to default.


TreeItem create_child ( int index=-1 )

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.


void deselect ( int column )

Deselects the given column.


void erase_button ( int column, int button_index )

Removes the button at index button_index in column column.


AutowrapMode get_autowrap_mode ( int column ) const

Returns the text autowrap mode in the given column. By default it is TextServer.AUTOWRAP_OFF.


Texture2D get_button ( int column, int button_index ) const

Returns the Texture2D of the button at index button_index in column column.


int get_button_by_id ( int column, int id ) const

Returns the button index if there is a button with ID id in column column, otherwise returns -1.


int get_button_count ( int column ) const

Returns the number of buttons in column column.


int get_button_id ( int column, int button_index ) const

Returns the ID for the button at index button_index in column column.


String get_button_tooltip_text ( int column, int button_index ) const

Returns the tooltip text for the button at index button_index in column column.


TreeCellMode get_cell_mode ( int column ) const

Returns the column’s cell mode.


TreeItem get_child ( int index )

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.


int get_child_count ( )

Returns the number of child items.


TreeItem[] get_children ( )

Returns an array of references to the item’s children.


Color get_custom_bg_color ( int column ) const

Returns the custom background color of column column.


Color get_custom_color ( int column ) const

Returns the custom color of column column.


Font get_custom_font ( int column ) const

Returns custom font used to draw text in the column column.


int get_custom_font_size ( int column ) const

Returns custom font size used to draw text in the column column.


bool get_expand_right ( int column ) const

Returns true if expand_right is set.


TreeItem get_first_child ( ) const

Returns the TreeItem’s first child.


Texture2D get_icon ( int column ) const

Returns the given column’s icon Texture2D. Error if no icon is set.


int get_icon_max_width ( int column ) const

Returns the maximum allowed width of the icon in the given column.


Color get_icon_modulate ( int column ) const

Returns the Color modulating the column’s icon.


Rect2 get_icon_region ( int column ) const

Returns the icon Texture2D region as Rect2.


int get_index ( )

Returns the node’s order in the tree. For example, if called on the first child item the position is 0.


String get_language ( int column ) const

Returns item’s text language code.


Variant get_metadata ( int column ) const

Returns the metadata value that was set for the given column using set_metadata.


TreeItem get_next ( ) const

Returns the next sibling TreeItem in the tree or a null object if there is none.


TreeItem get_next_in_tree ( bool wrap=false )

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_visible ( bool wrap=false )

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

Returns the parent TreeItem or a null object if there is none.


TreeItem get_prev ( )

Returns the previous sibling TreeItem in the tree or a null object if there is none.


TreeItem get_prev_in_tree ( bool wrap=false )

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_visible ( bool wrap=false )

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.


float get_range ( int column ) const

Returns the value of a CELL_MODE_RANGE column.


Dictionary get_range_config ( int column )

Returns a dictionary containing the range parameters for a given column. The keys are “min”, “max”, “step”, and “expr”.


StructuredTextParser get_structured_text_bidi_override ( int column ) const

There is currently no description for this method. Please help us by contributing one!


Array get_structured_text_bidi_override_options ( int column ) const

There is currently no description for this method. Please help us by contributing one!


String get_suffix ( int column ) const

Gets the suffix string shown after the column value.


String get_text ( int column ) const

Returns the given column’s text.


HorizontalAlignment get_text_alignment ( int column ) const

Returns the given column’s text alignment.


TextDirection get_text_direction ( int column ) const

Returns item’s text base writing direction.


String get_tooltip_text ( int column ) const

Returns the given column’s tooltip text.


Tree get_tree ( ) const

Returns the Tree that owns this TreeItem.


bool is_any_collapsed ( bool only_visible=false )

Returns true if this TreeItem, or any of its descendants, is collapsed.

If only_visible is true it ignores non-visible TreeItems.


bool is_button_disabled ( int column, int button_index ) const

Returns true if the button at index button_index for the given column is disabled.


bool is_checked ( int column ) const

Returns true if the given column is checked.


bool is_custom_set_as_button ( int column ) const

There is currently no description for this method. Please help us by contributing one!


bool is_edit_multiline ( int column ) const

Returns true if the given column is multiline editable.


bool is_editable ( int column )

Returns true if the given column is editable.


bool is_indeterminate ( int column ) const

Returns true if the given column is indeterminate.


bool is_selectable ( int column ) const

Returns true if the given column is selectable.


bool is_selected ( int column )

Returns true if the given column is selected.


void move_after ( TreeItem item )

Moves this TreeItem right after the given item.

Note: You can’t move to the root or move the root.


void move_before ( TreeItem item )

Moves this TreeItem right before the given item.

Note: You can’t move to the root or move the root.


void propagate_check ( int column, bool emit_signal=true )

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 remove_child ( TreeItem child )

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 add_child). To completely remove a TreeItem use Object.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 move_before or move_after.


void select ( int column )

Selects the given column.


void set_autowrap_mode ( int column, AutowrapMode autowrap_mode )

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_button ( int column, int button_index, Texture2D button )

Sets the given column’s button Texture2D at index button_index to button.


void set_button_color ( int column, int button_index, Color color )

Sets the given column’s button color at index button_index to color.


void set_button_disabled ( int column, int button_index, bool disabled )

If true, disables the button at index button_index in the given column.


void set_cell_mode ( int column, TreeCellMode mode )

Sets the given column’s cell mode to mode. See TreeCellMode constants.


void set_checked ( int column, bool checked )

If checked is true, the given column is checked. Clears column’s indeterminate status.


void set_collapsed_recursive ( bool enable )

Collapses or uncollapses this TreeItem and all the descendants of this item.


void set_custom_as_button ( int column, bool enable )

There is currently no description for this method. Please help us by contributing one!


void set_custom_bg_color ( int column, Color color, bool just_outline=false )

Sets the given column’s custom background color and whether to just use it as an outline.


void set_custom_color ( int column, Color color )

Sets the given column’s custom color.


void set_custom_draw ( int column, Object object, StringName callback )

Sets the given column’s custom draw callback to callback method on object.

The callback should accept two arguments: the TreeItem that is drawn and its position and size as a Rect2.


void set_custom_font ( int column, Font font )

Sets custom font used to draw text in the given column.


void set_custom_font_size ( int column, int font_size )

Sets custom font size used to draw text in the given column.


void set_edit_multiline ( int column, bool multiline )

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 set_text even if the column is not multiline editable.


void set_editable ( int column, bool enabled )

If enabled is true, the given column is editable.


void set_expand_right ( int column, bool enable )

If enable is true, the given column is expanded to the right.


void set_icon ( int column, Texture2D texture )

Sets the given column’s icon Texture2D.


void set_icon_max_width ( int column, int width )

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 Tree.icon_max_width. The height is adjusted according to the icon’s ratio.


void set_icon_modulate ( int column, Color modulate )

Modulates the given column’s icon with modulate.


void set_icon_region ( int column, Rect2 region )

Sets the given column’s icon’s texture region.


void set_indeterminate ( int column, bool indeterminate )

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_language ( int column, String language )

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_metadata ( int column, Variant meta )

Sets the metadata value for the given column, which can be retrieved later using get_metadata. This can be used, for example, to store a reference to the original data.


void set_range ( int column, float value )

Sets the value of a CELL_MODE_RANGE column.


void set_range_config ( int column, float min, float max, float step, bool expr=false )

Sets the range of accepted values for a column. The column must be in the CELL_MODE_RANGE mode.

If expr is true, the edit mode slider will use an exponential scale as with Range.exp_edit.


void set_selectable ( int column, bool selectable )

If selectable is true, the given column is selectable.


void set_structured_text_bidi_override ( int column, StructuredTextParser parser )

There is currently no description for this method. Please help us by contributing one!


void set_structured_text_bidi_override_options ( int column, Array args )

There is currently no description for this method. Please help us by contributing one!


void set_suffix ( int column, String text )

Sets a string to be shown after a column’s value (for example, a unit abbreviation).


void set_text ( int column, String text )

Sets the given column’s text value.


void set_text_alignment ( int column, HorizontalAlignment text_alignment )

Sets the given column’s text alignment. See HorizontalAlignment for possible values.


void set_text_direction ( int column, TextDirection direction )

Sets item’s text base writing direction.


void set_tooltip_text ( int column, String tooltip )

Sets the given column’s tooltip text.


void uncollapse_tree ( )

There is currently no description for this method. Please help us by contributing one!