Documentation
¶
Overview ¶
A control used to show a set of internal [graphics.gd/classdb/TreeItem]s in a hierarchical structure. The tree items can be selected, expanded and collapsed. The tree can have multiple columns with custom controls like [graphics.gd/classdb/LineEdit]s, buttons and popups. It can be useful for structured displays and interactions.
Trees are built via code, using graphics.gd/classdb/TreeItem objects to create the structure. They have a single root, but multiple roots can be simulated with Instance.HideRoot:
package main import "graphics.gd/classdb/Tree" func ExampleTree() { var tree = Tree.New() var root = tree.CreateItem() tree.SetHideRoot(true) var child1 = Tree.Expanded(tree).CreateItem(root, -1) var child2 = Tree.Expanded(tree).CreateItem(root, -1) var subchild1 = Tree.Expanded(tree).CreateItem(child1, -1) subchild1.SetText(0, "Subchild1") _ = child2 }
To iterate over all the graphics.gd/classdb/TreeItem objects in a graphics.gd/classdb/Tree object, use graphics.gd/classdb/TreeItem.Instance.GetNext and graphics.gd/classdb/TreeItem.Instance.GetFirstChild after getting the root through Instance.GetRoot. You can use graphics.gd/classdb/Object.Instance.Free on a graphics.gd/classdb/TreeItem to remove it from the graphics.gd/classdb/Tree.
Incremental search: Like graphics.gd/classdb/ItemList and graphics.gd/classdb/PopupMenu, graphics.gd/classdb/Tree supports searching within the list while the control is focused. Press a key that matches the first letter of an item's name to select the first item starting with the given letter. After that point, there are two ways to perform incremental search: 1) Press the same key again before the timeout duration to select the next item starting with the same letter. 2) Press letter keys that match the rest of the word before the timeout duration to match to select the item in question directly. Both of these actions will be reset to the beginning of the list if the timeout duration has passed since the last keystroke was registered. You can adjust the timeout duration by changing graphics.gd/classdb/ProjectSettings "gui/timers/incremental_search_max_interval_msec".
Index ¶
- type Advanced
- type Any
- type DropModeFlags
- type Expanded
- func (self Expanded) CreateItem(parent TreeItem.Instance, index int) TreeItem.Instance
- func (self Expanded) EditSelected(force_edit bool) bool
- func (self Expanded) GetItemAreaRect(item TreeItem.Instance, column int, button_index int) Rect2.PositionSize
- func (self Expanded) ScrollToItem(item TreeItem.Instance, center_on_item bool)
- type Extension
- type ID
- type Instance
- func (self Instance) AllowReselect() bool
- func (self Instance) AllowRmbSelect() bool
- func (self Instance) AllowSearch() bool
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsControl() Control.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsTree() Instance
- func (self Instance) AutoTooltip() bool
- func (self Instance) Clear()
- func (self Instance) ColumnTitlesVisible() bool
- func (self Instance) Columns() int
- func (self Instance) CreateItem() TreeItem.Instance
- func (self Instance) DeselectAll()
- func (self Instance) DropModeFlags() int
- func (self Instance) EditSelected() bool
- func (self Instance) EnableRecursiveFolding() bool
- func (self Instance) EnsureCursorIsVisible()
- func (self Instance) GetButtonIdAtPosition(position Vector2.XY) int
- func (self Instance) GetColumnAtPosition(position Vector2.XY) int
- func (self Instance) GetColumnExpandRatio(column int) int
- func (self Instance) GetColumnTitle(column int) string
- func (self Instance) GetColumnTitleAlignment(column int) GUI.HorizontalAlignment
- func (self Instance) GetColumnTitleDirection(column int) Control.TextDirection
- func (self Instance) GetColumnTitleLanguage(column int) string
- func (self Instance) GetColumnWidth(column int) int
- func (self Instance) GetCustomPopupRect() Rect2.PositionSize
- func (self Instance) GetDropSectionAtPosition(position Vector2.XY) int
- func (self Instance) GetEdited() TreeItem.Instance
- func (self Instance) GetEditedColumn() int
- func (self Instance) GetItemAreaRect(item TreeItem.Instance) Rect2.PositionSize
- func (self Instance) GetItemAtPosition(position Vector2.XY) TreeItem.Instance
- func (self Instance) GetNextSelected(from TreeItem.Instance) TreeItem.Instance
- func (self Instance) GetPressedButton() int
- func (self Instance) GetRoot() TreeItem.Instance
- func (self Instance) GetScroll() Vector2.XY
- func (self Instance) GetSelected() TreeItem.Instance
- func (self Instance) GetSelectedColumn() int
- func (self Instance) HideFolding() bool
- func (self Instance) HideRoot() bool
- func (self Instance) ID() ID
- func (self Instance) IsColumnClippingContent(column int) bool
- func (self Instance) IsColumnExpanding(column int) bool
- func (self Instance) OnButtonClicked(cb func(item TreeItem.Instance, column int, id int, mouse_button_index int), ...)
- func (self Instance) OnCellSelected(cb func(), flags ...Signal.Flags)
- func (self Instance) OnCheckPropagatedToItem(cb func(item TreeItem.Instance, column int), flags ...Signal.Flags)
- func (self Instance) OnColumnTitleClicked(cb func(column int, mouse_button_index int), flags ...Signal.Flags)
- func (self Instance) OnCustomItemClicked(cb func(mouse_button_index int), flags ...Signal.Flags)
- func (self Instance) OnCustomPopupEdited(cb func(arrow_clicked bool), flags ...Signal.Flags)
- func (self Instance) OnEmptyClicked(cb func(click_position Vector2.XY, mouse_button_index int), ...)
- func (self Instance) OnItemActivated(cb func(), flags ...Signal.Flags)
- func (self Instance) OnItemCollapsed(cb func(item TreeItem.Instance), flags ...Signal.Flags)
- func (self Instance) OnItemEdited(cb func(), flags ...Signal.Flags)
- func (self Instance) OnItemIconDoubleClicked(cb func(), flags ...Signal.Flags)
- func (self Instance) OnItemMouseSelected(cb func(mouse_position Vector2.XY, mouse_button_index int), ...)
- func (self Instance) OnItemSelected(cb func(), flags ...Signal.Flags)
- func (self Instance) OnMultiSelected(cb func(item TreeItem.Instance, column int, selected bool), ...)
- func (self Instance) OnNothingSelected(cb func(), flags ...Signal.Flags)
- func (self Instance) ScrollHorizontalEnabled() bool
- func (self Instance) ScrollToItem(item TreeItem.Instance)
- func (self Instance) ScrollVerticalEnabled() bool
- func (self Instance) SelectMode() SelectMode
- func (self Instance) SetAllowReselect(value bool)
- func (self Instance) SetAllowRmbSelect(value bool)
- func (self Instance) SetAllowSearch(value bool)
- func (self Instance) SetAutoTooltip(value bool)
- func (self Instance) SetColumnClipContent(column int, enable bool)
- func (self Instance) SetColumnCustomMinimumWidth(column int, min_width int)
- func (self Instance) SetColumnExpand(column int, expand bool)
- func (self Instance) SetColumnExpandRatio(column int, ratio int)
- func (self Instance) SetColumnTitle(column int, title string)
- func (self Instance) SetColumnTitleAlignment(column int, title_alignment GUI.HorizontalAlignment)
- func (self Instance) SetColumnTitleDirection(column int, direction Control.TextDirection)
- func (self Instance) SetColumnTitleLanguage(column int, language string)
- func (self Instance) SetColumnTitlesVisible(value bool)
- func (self Instance) SetColumns(value int)
- func (self Instance) SetDropModeFlags(value int)
- func (self Instance) SetEnableRecursiveFolding(value bool)
- func (self Instance) SetHideFolding(value bool)
- func (self Instance) SetHideRoot(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetScrollHorizontalEnabled(value bool)
- func (self Instance) SetScrollVerticalEnabled(value bool)
- func (self Instance) SetSelectMode(value SelectMode)
- func (self Instance) SetSelected(item TreeItem.Instance, column int)
- func (self Instance) Virtual(name string) reflect.Value
- type SelectMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type DropModeFlags ¶
type DropModeFlags int //gd:Tree.DropModeFlags
const ( // Disables all drop sections, but still allows to detect the "on item" drop section by [Instance.GetDropSectionAtPosition]. // // Note: This is the default flag, it has no effect when combined with other flags. DropModeDisabled DropModeFlags = 0 // Enables the "on item" drop section. This drop section covers the entire item. // // When combined with [DropModeInbetween], this drop section halves the height and stays centered vertically. DropModeOnItem DropModeFlags = 1 // Enables "above item" and "below item" drop sections. The "above item" drop section covers the top half of the item, and the "below item" drop section covers the bottom half. // // When combined with [DropModeOnItem], these drop sections halves the height and stays on top / bottom accordingly. DropModeInbetween DropModeFlags = 2 )
type Expanded ¶
func (Expanded) CreateItem ¶
Creates an item in the tree and adds it as a child of 'parent', which can be either a valid graphics.gd/classdb/TreeItem or null.
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 'index'-th child of parent, or it will be the last child if there are not enough siblings.
func (Expanded) EditSelected ¶
Edits the selected tree item as if it was clicked.
Either the item must be set editable with graphics.gd/classdb/TreeItem.Instance.SetEditable or 'force_edit' must be true.
Returns true if the item could be edited. Fails if no item is selected.
func (Expanded) GetItemAreaRect ¶
func (self Expanded) GetItemAreaRect(item TreeItem.Instance, column int, button_index int) Rect2.PositionSize
Returns the rectangle area for the specified graphics.gd/classdb/TreeItem. If 'column' is specified, only get the position and size of that column, otherwise get the rectangle containing all columns. If a button index is specified, the rectangle of that button will be returned.
func (Expanded) ScrollToItem ¶
Causes the graphics.gd/classdb/Tree to jump to the specified graphics.gd/classdb/TreeItem.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsCanvasItem ¶
func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AllowReselect ¶
func (Instance) AllowRmbSelect ¶
func (Instance) AllowSearch ¶
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) AutoTooltip ¶
func (Instance) ColumnTitlesVisible ¶
func (Instance) CreateItem ¶
Creates an item in the tree and adds it as a child of 'parent', which can be either a valid graphics.gd/classdb/TreeItem or null.
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 'index'-th child of parent, or it will be the last child if there are not enough siblings.
func (Instance) DeselectAll ¶
func (self Instance) DeselectAll()
Deselects all tree items (rows and columns). In SelectMulti mode also removes selection cursor.
func (Instance) DropModeFlags ¶
func (Instance) EditSelected ¶
Edits the selected tree item as if it was clicked.
Either the item must be set editable with graphics.gd/classdb/TreeItem.Instance.SetEditable or 'force_edit' must be true.
Returns true if the item could be edited. Fails if no item is selected.
func (Instance) EnableRecursiveFolding ¶
func (Instance) EnsureCursorIsVisible ¶
func (self Instance) EnsureCursorIsVisible()
Makes the currently focused cell visible.
This will scroll the tree if necessary. In SelectRow 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 SelectMulti mode.
func (Instance) GetButtonIdAtPosition ¶
Returns the button ID at 'position', or -1 if no button is there.
func (Instance) GetColumnAtPosition ¶
Returns the column index at 'position', or -1 if no item is there.
func (Instance) GetColumnExpandRatio ¶
Returns the expand ratio assigned to the column.
func (Instance) GetColumnTitle ¶
Returns the column's title.
func (Instance) GetColumnTitleAlignment ¶
func (self Instance) GetColumnTitleAlignment(column int) GUI.HorizontalAlignment
Returns the column title alignment.
func (Instance) GetColumnTitleDirection ¶
func (self Instance) GetColumnTitleDirection(column int) Control.TextDirection
Returns column title base writing direction.
func (Instance) GetColumnTitleLanguage ¶
Returns column title language code.
func (Instance) GetColumnWidth ¶
Returns the column's width in pixels.
func (Instance) GetCustomPopupRect ¶
func (self Instance) GetCustomPopupRect() Rect2.PositionSize
Returns the rectangle for custom popups. Helper to create custom cell controls that display a popup. See graphics.gd/classdb/TreeItem.Instance.SetCellMode.
func (Instance) 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 Instance.GetItemAtPosition.
func (Instance) GetEdited ¶
Returns the currently edited item. Can be used with Instance.OnItemEdited to get the item that was modified.
func (Instance) GetEditedColumn ¶
Returns the column for the currently edited item.
func (Instance) GetItemAreaRect ¶
func (self Instance) GetItemAreaRect(item TreeItem.Instance) Rect2.PositionSize
Returns the rectangle area for the specified graphics.gd/classdb/TreeItem. If 'column' is specified, only get the position and size of that column, otherwise get the rectangle containing all columns. If a button index is specified, the rectangle of that button will be returned.
func (Instance) GetItemAtPosition ¶
Returns the tree item at the specified position (relative to the tree origin position).
func (Instance) GetNextSelected ¶
Returns the next selected graphics.gd/classdb/TreeItem after the given one, or null if the end is reached.
If 'from' is null, this returns the first selected item.
func (Instance) GetPressedButton ¶
Returns the last pressed button's index.
func (Instance) GetSelected ¶
Returns the currently focused item, or null if no item is focused.
In SelectRow and SelectSingle modes, the focused item is same as the selected item. In SelectMulti mode, the focused item is the item under the focus cursor, not necessarily selected.
To get the currently selected item(s), use Instance.GetNextSelected.
func (Instance) GetSelectedColumn ¶
Returns the currently focused column, or -1 if no column is focused.
In SelectSingle mode, the focused column is the selected column. In SelectRow mode, the focused column is always 0 if any item is selected. In SelectMulti 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 graphics.gd/classdb/TreeItem.Instance.IsSelected.
func (Instance) HideFolding ¶
func (Instance) IsColumnClippingContent ¶
Returns true if the column has enabled clipping (see Instance.SetColumnClipContent).
func (Instance) IsColumnExpanding ¶
Returns true if the column has enabled expanding (see Instance.SetColumnExpand).
func (Instance) OnButtonClicked ¶
func (Instance) OnCellSelected ¶
func (Instance) OnCheckPropagatedToItem ¶
func (Instance) OnColumnTitleClicked ¶
func (Instance) OnCustomItemClicked ¶
func (Instance) OnCustomPopupEdited ¶
func (Instance) OnEmptyClicked ¶
func (Instance) OnItemActivated ¶
func (Instance) OnItemCollapsed ¶
func (Instance) OnItemEdited ¶
func (Instance) OnItemIconDoubleClicked ¶
func (Instance) OnItemMouseSelected ¶
func (Instance) OnItemSelected ¶
func (Instance) OnMultiSelected ¶
func (Instance) OnNothingSelected ¶
func (Instance) ScrollHorizontalEnabled ¶
func (Instance) ScrollToItem ¶
Causes the graphics.gd/classdb/Tree to jump to the specified graphics.gd/classdb/TreeItem.
func (Instance) ScrollVerticalEnabled ¶
func (Instance) SelectMode ¶
func (self Instance) SelectMode() SelectMode
func (Instance) SetAllowReselect ¶
func (Instance) SetAllowRmbSelect ¶
func (Instance) SetAllowSearch ¶
func (Instance) SetAutoTooltip ¶
func (Instance) SetColumnClipContent ¶
Allows to enable clipping for column's content, making the content size ignored.
func (Instance) SetColumnCustomMinimumWidth ¶
Overrides the calculated minimum width of a column. It can be set to 0 to restore the default behavior. Columns that have the "Expand" flag will use their "min_width" in a similar fashion to graphics.gd/classdb/Control.Instance.SizeFlagsStretchRatio.
func (Instance) SetColumnExpand ¶
If true, the column will have the "Expand" flag of graphics.gd/classdb/Control. Columns that have the "Expand" flag will use their expand ratio in a similar fashion to graphics.gd/classdb/Control.Instance.SizeFlagsStretchRatio (see Instance.SetColumnExpandRatio).
func (Instance) SetColumnExpandRatio ¶
Sets the relative expand ratio for a column. See Instance.SetColumnExpand.
func (Instance) SetColumnTitle ¶
Sets the title of a column.
func (Instance) SetColumnTitleAlignment ¶
func (self Instance) SetColumnTitleAlignment(column int, title_alignment GUI.HorizontalAlignment)
Sets the column title alignment. Note that [@Globalscope.HorizontalAlignmentFill] is not supported for column titles.
func (Instance) SetColumnTitleDirection ¶
func (self Instance) SetColumnTitleDirection(column int, direction Control.TextDirection)
Sets column title base writing direction.
func (Instance) SetColumnTitleLanguage ¶
Sets language code of column title used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
func (Instance) SetColumnTitlesVisible ¶
func (Instance) SetColumns ¶
func (Instance) SetDropModeFlags ¶
func (Instance) SetEnableRecursiveFolding ¶
func (Instance) SetHideFolding ¶
func (Instance) SetHideRoot ¶
func (Instance) SetScrollHorizontalEnabled ¶
func (Instance) SetScrollVerticalEnabled ¶
func (Instance) SetSelectMode ¶
func (self Instance) SetSelectMode(value SelectMode)
func (Instance) SetSelected ¶
Selects the specified graphics.gd/classdb/TreeItem and column.
type SelectMode ¶
type SelectMode int //gd:Tree.SelectMode
const ( // Allows selection of a single cell at a time. From the perspective of items, only a single item is allowed to be selected. And there is only one column selected in the selected item. // // The focus cursor is always hidden in this mode, but it is positioned at the current selection, making the currently selected item the currently focused item. SelectSingle SelectMode = 0 // Allows selection of a single row at a time. From the perspective of items, only a single items is allowed to be selected. And all the columns are selected in the selected item. // // The focus cursor is always hidden in this mode, but it is positioned at the first column of the current selection, making the currently selected item the currently focused item. SelectRow SelectMode = 1 // Allows selection of multiple cells at the same time. From the perspective of items, multiple items are allowed to be selected. And there can be multiple columns selected in each selected item. // // The focus cursor is visible in this mode, the item or column under the cursor is not necessarily selected. SelectMulti SelectMode = 2 )