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]

To iterate over all the TreeItem objects in a Tree object, use TreeItem.GetNext() and TreeItem.GetChildren() after getting the root through GetRoot().

Inheritance Chain

Constructors

    public Tree()

Signals

    "button_pressed" (TreeItem 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 [constant TreeItem.CELL_MODE_CUSTOM] is clicked to be edited.

    "empty_rmb" (Vector2 position)

    "empty_tree_rmb_selected" (Vector2 position)

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

    "item_activated" ()

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

    "item_collapsed" (TreeItem 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’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.

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

Emitted instead of item_selected if select_mode is [constant 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 number of columns.

    public int DropModeFlags { get; set; }

The drop mode as an OR combination of flags. See DROP_MODE_* constants. Once dropping is done, reverts to [constant DROP_MODE_DISABLED]. Setting this during Control.CanDropData(Godot.Vector2, object) is recommended.

    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; }

Allows 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 TreeItem 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 null, it will be added as the root’s last child, or it’ll be the 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.

    [Obsolete("GetAllowReselect is deprecated. Use the AllowReselect property instead.")]
    public bool GetAllowReselect()

Getter for AllowReselect

    [Obsolete("GetAllowRmbSelect is deprecated. Use the AllowRmbSelect property instead.")]
    public bool GetAllowRmbSelect()

Getter for AllowRmbSelect

    public int GetColumnAtPosition(Vector2 position)

Returns the column index under the given point.

    [Obsolete("GetColumns is deprecated. Use the Columns property instead.")]
    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).

    [Obsolete("GetDropModeFlags is deprecated. Use the DropModeFlags property instead.")]
    public int GetDropModeFlags()

Getter for DropModeFlags

    public int GetDropSectionAtPosition(Vector2 position)

If DropModeFlags includes [constant 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 DropModeFlags includes [constant DROP_MODE_ON_ITEM].

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

    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.

    [Obsolete("GetSelectMode is deprecated. Use the SelectMode property instead.")]
    public SelectModeEnum GetSelectMode()

Getter for SelectMode

    [Obsolete("IsFoldingHidden is deprecated. Use the HideFolding property instead.")]
    public bool IsFoldingHidden()

Getter for HideFolding

    [Obsolete("IsRootHidden is deprecated. Use the HideRoot property instead.")]
    public bool IsRootHidden()

Getter for HideRoot

    [Obsolete("SetAllowReselect is deprecated. Use the AllowReselect property instead.")]
    public void SetAllowReselect(bool allow)

Setter for AllowReselect

    [Obsolete("SetAllowRmbSelect is deprecated. Use the AllowRmbSelect property instead.")]
    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. Columns that have the “Expand” flag will use their “min_width” in a similar fashion to Control.SizeFlagsStretchRatio.

    public void SetColumnMinWidth(int column, int minWidth)

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

    [Obsolete("SetColumns is deprecated. Use the Columns property instead.")]
    public void SetColumns(int amount)

Setter for Columns

    public void SetColumnTitle(int column, string title)

Sets the title of a column.

    public void SetColumnTitlesVisible(bool visible)

If true, column titles are visible.

    [Obsolete("SetDropModeFlags is deprecated. Use the DropModeFlags property instead.")]
    public void SetDropModeFlags(int flags)

Setter for DropModeFlags

    [Obsolete("SetHideFolding is deprecated. Use the HideFolding property instead.")]
    public void SetHideFolding(bool hide)

Setter for HideFolding

    [Obsolete("SetHideRoot is deprecated. Use the HideRoot property instead.")]
    public void SetHideRoot(bool enable)

Setter for HideRoot

    [Obsolete("SetSelectMode is deprecated. Use the SelectMode property instead.")]
    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 Allows selection of a single item at a time.
Row 1  
Multi 2 Allows selection of multiple items at the same time.
Tags: