Tree

Inherits: Control < CanvasItem < Node < Object

Category: Core

Brief Description

Control to show a tree of items.

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 )
  • custom_popup_edited ( bool arrow_clicked )

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

  • empty_tree_rmb_selected ( Vector2 pos )

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

  • item_activated ( )

Emitted when an item is activated (double-clicked).

  • item_collapsed ( Object item )

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

  • item_edited ( )

Emitted when an item is editted.

  • item_rmb_selected ( Vector2 pos )

Emitted when an item is selected with right mouse button.

  • item_selected ( )

Emitted when an item is selected with right mouse button.

Numeric Constants

  • SELECT_SINGLE = 0
  • SELECT_ROW = 1
  • SELECT_MULTI = 2
  • 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 structural displaying and interactions.

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

func _ready():
    var tree = Tree.new()
    var root = tree.create_item()
    tree.set_hide_root(true)
    var child1 = tree.create_item(root)
    var child2 = tree.create_item(root)
    var subchild1 = tree.create_item(child1)
    subchild1.set_text(0, "Subchild1")

Member Function Description

  • bool are_column_titles_visible ( ) const

Get whether the column titles are being shown.

  • void clear ( )

Clear the tree. This erases all of the 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 last child of the root, or it’ll the be the root itself if the tree is empty.

  • void ensure_cursor_is_visible ( )

Make the current selected item visible. This will scroll the tree to make sure the selected item is in sight.

  • bool get_allow_rmb_select ( ) const

Get whether a right click can select items.

Get the column index under the given point.

  • String get_column_title ( int column ) const

Get the title of the given column.

  • int get_column_width ( int column ) const

Get the width of the given column in pixels.

  • int get_columns ( ) const

Get the amount of columns.

  • Rect2 get_custom_popup_rect ( ) const

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

  • int get_drop_mode_flags ( ) const

Get the flags of the current drop mode.

Get the current edited item. This is only available for custom cell mode.

  • int get_edited_column ( ) const

Get the column of the cell for the current edited icon. This is only available for custom cell mode.

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

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

Get the next selected item after the given one.

  • int get_pressed_button ( ) const

Get the index of the last pressed button.

Get the root item of the tree.

Get the current scrolling position.

Get the currently selected item.

  • int get_selected_column ( ) const

Get the column number of the current selection.

  • bool get_single_select_cell_editing_only_when_already_selected ( ) const

Get whether the editing of a cell should only happen when it is already selected.

  • bool is_folding_hidden ( ) const

Get whether the folding arrow is hidden.

  • void set_allow_rmb_select ( bool allow )

Set whether or not a right mouse button click can select items.

  • void set_column_expand ( int column, bool expand )

Set whether a column will have the “Expand” flag of Control.

  • void set_column_min_width ( int column, int min_width )

Set the minimum width of a column.

  • void set_column_title ( int column, String title )

Set the title of a column.

  • void set_column_titles_visible ( bool visible )

Set whether the column titles visibility.

  • void set_columns ( int amount )

Set the amount of columns.

  • void set_drop_mode_flags ( int flags )

Set the drop mode as an OR combination of flags. See DROP_MODE\_\* constants.

  • void set_hide_folding ( bool hide )

Set whether the folding arrow should be hidden.

  • void set_hide_root ( bool enable )

Set whether the root of the tree should be hidden.

  • void set_select_mode ( int mode )

Set the selection mode. Use one of the SELECT\_\* constants.

  • void set_single_select_cell_editing_only_when_already_selected ( bool enable )

Set whether the editing of a cell should only happen when it is already selected.