Control to show a tree of items.
    public class Tree : Control

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.

[codeblock]

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”)

[/codeblock]

Inheritance Chain

Constructors

    public Tree()

Signals

    "button_pressed" (Object item, int column, int id)

Emitted when a button on the tree was pressed (see TreeItem.AddButton(int, Godot.Texture, int, bool, string)).

    "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 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 is activated (double-clicked).

    "item_collapsed" (Object item)

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

    "item_custom_button_pressed" ()

    "item_double_clicked" ()

Emitted when an item 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 right mouse button.

    "item_selected" ()

Emitted when an item is selected with right mouse button.

    "multi_selected" (Object item, int column, bool selected)

Emitted instead of item_selected when select_mode is SELECT_MULTI.

    "nothing_selected" ()

Properties

    public bool AllowReselect { get; set; }

If true the currently selected cell may be selected again.

    public bool AllowRmbSelect { get; set; }

If true a right mouse button click can select items.

    public int Columns { get; set; }

The amount of columns.

    public int DropModeFlags { get; set; }

The drop mode as an OR combination of flags. See DROP_MODE_* constants.

    public bool HideFolding { get; set; }

If true the folding arrow is hidden.

    public bool HideRoot { get; set; }

If true the tree’s root is hidden.

    public SelectModeEnum SelectMode { get; set; }

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

Methods

    public bool AreColumnTitlesVisible()

Returns true if the column titles are being shown.

    public void Clear()

Clears the tree. This removes all items.

    public Object CreateItem(Object parent = null, int idx = -1)

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.

    public void EnsureCursorIsVisible()

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

    public bool GetAllowReselect()

Getter for AllowReselect

    public bool GetAllowRmbSelect()

Getter for AllowRmbSelect

    public int GetColumnAtPosition(Vector2 position)

Returns the column index under the given point.

    public int GetColumns()

Getter for Columns

    public string GetColumnTitle(int column)

Returns the column’s title.

    public int GetColumnWidth(int column)

Returns the column’s width in pixels.

    public Rect2 GetCustomPopupRect()

Returns the rectangle for custom popups. Helper to create custom cell controls that display a popup. See TreeItem.SetCellMode(int, Godot.TreeItem.TreeCellMode).

    public int GetDropModeFlags()

Getter for DropModeFlags

    public int GetDropSectionAtPosition(Vector2 position)

    public TreeItem GetEdited()

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

    public int GetEditedColumn()

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

    public Rect2 GetItemAreaRect(Object item, int column = -1)

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.

    public TreeItem GetItemAtPosition(Vector2 position)

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

    public TreeItem GetNextSelected(Object from)

Returns the next selected item after the given one.

    public int GetPressedButton()

Returns the last pressed button’s index.

    public TreeItem GetRoot()

Returns the tree’s root item.

    public Vector2 GetScroll()

Returns the current scrolling position.

    public TreeItem GetSelected()

Returns the currently selected item.

    public int GetSelectedColumn()

Returns the current selection’s column.

    public SelectModeEnum GetSelectMode()

Getter for SelectMode

    public bool IsFoldingHidden()

Getter for HideFolding

    public bool IsRootHidden()

Getter for HideRoot

    public void SetAllowReselect(bool allow)

Setter for AllowReselect

    public void SetAllowRmbSelect(bool allow)

Setter for AllowRmbSelect

    public void SetColumnExpand(int column, bool expand)

If true the column will have the “Expand” flag of Control.

    public void SetColumnMinWidth(int column, int minWidth)

Set the minimum width of a column.

    public void SetColumns(int amount)

Setter for Columns

    public void SetColumnTitle(int column, string title)

Set the title of a column.

    public void SetColumnTitlesVisible(bool visible)

If true column titles are visible.

    public void SetDropModeFlags(int flags)

Setter for DropModeFlags

    public void SetHideFolding(bool hide)

Setter for HideFolding

    public void SetHideRoot(bool enable)

Setter for HideRoot

    public void SetSelectMode(SelectModeEnum mode)

Setter for SelectMode

Inner Types

DropModeFlagsEnum

Name Value Description
Disabled 0  
OnItem 1  
Inbetween 2  

SelectModeEnum

Name Value Description
Single 0 Allow selection of a single item at a time.
Row 1  
Multi 2 Allow selection of multiple items at the same time.
Tags: