Struct Tree

Control to show a tree of items.

struct Tree ;

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.

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

To iterate over all the TreeItem objects in a Tree object, use TreeItem.getNext and TreeItem.getChildren after getting the root through getRoot.

Properties

NameTypeDescription
allowReselect[get, set] boolIf true, the currently selected cell may be selected again.
allowRmbSelect[get, set] boolIf true, a right mouse button click can select items.
columns[get, set] longThe number of columns.
dropModeFlags[get, set] longThe drop mode as an OR combination of flags. See dropmodeflags constants. Once dropping is done, reverts to constant DROP_MODE_DISABLED. Setting this during Control.canDropData is recommended. This controls the drop sections, i.e. the decision and drawing of possible drop locations based on the mouse position.
hideFolding[get, set] boolIf true, the folding arrow is hidden.
hideRoot[get, set] boolIf true, the tree's root is hidden.
selectMode[get, set] Tree.SelectModeAllows single or multiple selection. See the selectmode constants.

Methods

NameDescription
_guiInput
_popupSelect
_rangeClickTimeout
_scrollMoved
_textEditorEnter
_textEditorModalClose
_valueEditorChanged
areColumnTitlesVisible Returns true if the column titles are being shown.
clear Clears the tree. This removes all items.
createItem Creates an item in the tree and adds it as a child of parent. If parent is null, the root item will be the parent, or the new item will be the root itself if the tree is empty. The new item will be the idxth child of parent, or it will be the last child if there are not enough siblings.
ensureCursorIsVisible Makes the currently focused cell visible. This will scroll the tree if necessary. In constant SELECT_ROW mode, this will not do horizontal scrolling, as all the cells in the selected row is focused logically. Note: Despite the name of this method, the focus cursor itself is only visible in constant SELECT_MULTI mode.
getAllowReselect
getAllowRmbSelect
getColumnAtPosition Returns the column index at position, or -1 if no item is there.
getColumns
getColumnTitle Returns the column's title.
getColumnWidth Returns the column's width in pixels.
getCustomPopupRect Returns the rectangle for custom popups. Helper to create custom cell controls that display a popup. See TreeItem.setCellMode.
getDropModeFlags
getDropSectionAtPosition Returns the drop section at position, or -100 if no item is there. Values -1, 0, or 1 will be returned for the "above item", "on item", and "below item" drop sections, respectively. See dropmodeflags for a description of each drop section. To get the item which the returned drop section is relative to, use getItemAtPosition.
getEdited Returns the currently edited item. This is only available for custom cell mode.
getEditedColumn Returns the column for the currently edited item. This is only available for custom cell mode.
getItemAreaRect 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.
getItemAtPosition Returns the tree item at the specified position (relative to the tree origin position).
getNextSelected Returns the next selected item after the given one, or null if the end is reached. If from is null, this returns the first selected item.
getPressedButton Returns the last pressed button's index.
getRoot Returns the tree's root item, or null if the tree is empty.
getScroll Returns the current scrolling position.
getSelected Returns the currently focused item, or null if no item is focused. In constant SELECT_ROW and constant SELECT_SINGLE modes, the focused item is same as the selected item. In constant SELECT_MULTI mode, the focused item is the item under the focus cursor, not necessarily selected. To get the currently selected item(s), use getNextSelected.
getSelectedColumn Returns the currently focused column, or -1 if no column is focused. In constant SELECT_SINGLE mode, the focused column is the selected column. In constant SELECT_ROW mode, the focused column is always 0 if any item is selected. In constant SELECT_MULTI mode, the focused column is the column under the focus cursor, and there are not necessarily any column selected. To tell whether a column of an item is selected, use TreeItem.isSelected.
getSelectMode
isFoldingHidden
isRootHidden
setAllowReselect
setAllowRmbSelect
setColumnExpand 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.
setColumnMinWidth 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.
setColumns
setColumnTitle Sets the title of a column.
setColumnTitlesVisible If true, column titles are visible.
setDropModeFlags
setHideFolding
setHideRoot
setSelectMode

Enums

NameDescription
Constants
DropModeFlags
SelectMode