Tree

Inherits: Control < CanvasItem < Node < Object

Category: Core

Brief Description

Control to show a tree of items.

Properties

boolallow_reselect
boolallow_rmb_select
intcolumns
intdrop_mode_flags
boolhide_folding
boolhide_root
SelectModeselect_mode

Methods

boolare_column_titles_visible ( ) const
voidclear ( )
TreeItemcreate_item ( Object parent=null, int idx=-1 )
voidensure_cursor_is_visible ( )
intget_column_at_position ( Vector2 position ) const
Stringget_column_title ( int column ) const
intget_column_width ( int column ) const
Rect2get_custom_popup_rect ( ) const
intget_drop_section_at_position ( Vector2 position ) const
TreeItemget_edited ( ) const
intget_edited_column ( ) const
Rect2get_item_area_rect ( Object item, int column=-1 ) const
TreeItemget_item_at_position ( Vector2 position ) const
TreeItemget_next_selected ( Object from )
intget_pressed_button ( ) const
TreeItemget_root ( )
Vector2get_scroll ( ) const
TreeItemget_selected ( ) const
intget_selected_column ( ) const
voidset_column_expand ( int column, bool expand )
voidset_column_min_width ( int column, int min_width )
voidset_column_title ( int column, String title )
voidset_column_titles_visible ( bool visible )

Theme Properties

Texturearrow
Texturearrow_collapsed
StyleBoxbg
StyleBoxbg_focus
intbutton_margin
StyleBoxbutton_pressed
Texturechecked
StyleBoxcursor
Colorcursor_color
StyleBoxcursor_unfocused
StyleBoxcustom_button
Colorcustom_button_font_highlight
StyleBoxcustom_button_hover
StyleBoxcustom_button_pressed
intdraw_guides
intdraw_relationship_lines
Colordrop_position_color
Fontfont
Colorfont_color
Colorfont_color_selected
Colorguide_color
intguide_width
inthseparation
intitem_margin
Colorrelationship_line_color
intscroll_border
intscroll_speed
Textureselect_arrow
StyleBoxselected
StyleBoxselected_focus
Colorselection_color
Colortitle_button_color
Fonttitle_button_font
StyleBoxtitle_button_hover
StyleBoxtitle_button_normal
StyleBoxtitle_button_pressed
Textureunchecked
Textureupdown
intvseparation

Signals

Emitted when a button on the tree was pressed (see TreeItem.add_button).


  • cell_selected ( )

Emitted when a cell is selected.


  • column_title_pressed ( int column )

Emitted when a column’s title is pressed.


  • custom_popup_edited ( bool arrow_clicked )

Emitted when a cell with the TreeItem.CELL_MODE_CUSTOM is clicked to be edited.


  • empty_tree_rmb_selected ( Vector2 position )

Emitted when the right mouse button is pressed if RMB selection is active and the tree is empty.


  • item_activated ( )

Emitted when an item’s label is double-clicked.


Emitted when an item is collapsed by a click on the folding arrow.


  • item_custom_button_pressed ( )

  • item_double_clicked ( )

Emitted when an item’s icon is double-clicked.


  • item_edited ( )

Emitted when an item is edited.


  • item_rmb_edited ( )

Emitted when an item is edited using the right mouse button.


  • item_rmb_selected ( Vector2 position )

Emitted when an item is selected with the right mouse button.


  • item_selected ( )

Emitted when an item is selected.


Emitted instead of item_selected when select_mode is SELECT_MULTI.


  • nothing_selected ( )

Enumerations

enum SelectMode:

  • SELECT_SINGLE = 0 — Allow selection of a single item at a time.
  • SELECT_ROW = 1
  • SELECT_MULTI = 2 — Allow selection of multiple items at the same time.

enum DropModeFlags:

  • DROP_MODE_DISABLED = 0
  • DROP_MODE_ON_ITEM = 1
  • DROP_MODE_INBETWEEN = 2

Description

This shows a tree of items that can be selected, expanded and collapsed. The tree can have multiple columns with custom controls like text editing, buttons and popups. It can be useful for structured displays and interactions.

Trees are built via code, using TreeItem objects to create the structure. They have a single root but multiple roots can be simulated if a dummy hidden root is added.

  1. func _ready():
  2. var tree = Tree.new()
  3. var root = tree.create_item()
  4. tree.set_hide_root(true)
  5. var child1 = tree.create_item(root)
  6. var child2 = tree.create_item(root)
  7. var subchild1 = tree.create_item(child1)
  8. subchild1.set_text(0, "Subchild1")

Property Descriptions

  • bool allow_reselect
Setterset_allow_reselect(value)
Getterget_allow_reselect()

If true, the currently selected cell may be selected again.


  • bool allow_rmb_select
Setterset_allow_rmb_select(value)
Getterget_allow_rmb_select()

If true, a right mouse button click can select items.


Setterset_columns(value)
Getterget_columns()

The amount of columns.


  • int drop_mode_flags
Setterset_drop_mode_flags(value)
Getterget_drop_mode_flags()

The drop mode as an OR combination of flags. See DROP_MODE_* constants. Once dropping is done, reverts to DROP_MODE_DISABLED. Setting this during Control.can_drop_data is recommended.


Setterset_hide_folding(value)
Getteris_folding_hidden()

If true, the folding arrow is hidden.


Setterset_hide_root(value)
Getteris_root_hidden()

If true, the tree’s root is hidden.


Setterset_select_mode(value)
Getterget_select_mode()

Allow single or multiple selection. See the SELECT_* constants.

Method Descriptions

  • bool are_column_titles_visible ( ) const

Returns true if the column titles are being shown.


  • void clear ( )

Clears the tree. This removes all items.


Create an item in the tree and add it as the last child of parent. If parent is not given, it will be added as the root’s last child, or it’ll the be the root itself if the tree is empty.


  • void ensure_cursor_is_visible ( )

Makes the currently selected item visible. This will scroll the tree to make sure the selected item is visible.


  • int get_column_at_position ( Vector2 position ) const

Returns the column index under the given point.


  • String get_column_title ( int column ) const

Returns the column’s title.


  • int get_column_width ( int column ) const

Returns the column’s width in pixels.


  • Rect2 get_custom_popup_rect ( ) const

Returns the rectangle for custom popups. Helper to create custom cell controls that display a popup. See TreeItem.set_cell_mode.


  • int get_drop_section_at_position ( Vector2 position ) const

If drop_mode_flags includes DROP_MODE_INBETWEEN, returns -1 if position is the upper part of a tree item at that position, 1 for the lower part, and additionally 0 for the middle part if drop_mode_flags includes DROP_MODE_ON_ITEM.

Otherwise, returns 0. If there are no tree item at position, returns -100.


Returns the currently edited item. This is only available for custom cell mode.


  • int get_edited_column ( ) const

Returns the column for the currently edited item. This is only available for custom cell mode.


Returns the rectangle area for the specified item. If column is specified, only get the position and size of that column, otherwise get the rectangle containing all columns.


Returns the tree item at the specified position (relative to the tree origin position).


Returns the next selected item after the given one.


  • int get_pressed_button ( ) const

Returns the last pressed button’s index.


Returns the tree’s root item.


Returns the current scrolling position.


Returns the currently selected item.


  • int get_selected_column ( ) const

Returns the current selection’s column.


  • void set_column_expand ( int column, bool expand )

If true, the column will have the “Expand” flag of Control. Columns that have the “Expand” flag will use their “min_width” in a similar fashion to Control.size_flags_stretch_ratio.


  • void set_column_min_width ( int column, int min_width )

Sets the minimum width of a column. Columns that have the “Expand” flag will use their “min_width” in a similar fashion to Control.size_flags_stretch_ratio.


  • void set_column_title ( int column, String title )

Set the title of a column.


  • void set_column_titles_visible ( bool visible )

If true, column titles are visible.