Tree

package
v0.0.0-...-e1beaa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 29 Imported by: 0

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

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 Any

type Any interface {
	gd.IsClass
	AsTree() Instance
}

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

type Expanded [1]gdclass.Tree

func (Expanded) CreateItem

func (self Expanded) CreateItem(parent TreeItem.Instance, index int) TreeItem.Instance

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

func (self Expanded) EditSelected(force_edit bool) bool

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

func (self Expanded) ScrollToItem(item TreeItem.Instance, center_on_item bool)

Causes the graphics.gd/classdb/Tree to jump to the specified graphics.gd/classdb/TreeItem.

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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

func (*Extension[T]) AsControl

func (self *Extension[T]) AsControl() Control.Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsTree

func (self *Extension[T]) AsTree() Instance

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Tree

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 Get

func Get(peer TreeItem.Instance) Instance

Returns the [Tree] that owns this TreeItem.

func New

func New() Instance

func (Instance) AllowReselect

func (self Instance) AllowReselect() bool

func (Instance) AllowRmbSelect

func (self Instance) AllowRmbSelect() bool

func (Instance) AllowSearch

func (self Instance) AllowSearch() bool

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsControl

func (self Instance) AsControl() Control.Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsTree

func (self Instance) AsTree() Instance

func (Instance) AutoTooltip

func (self Instance) AutoTooltip() bool

func (Instance) Clear

func (self Instance) Clear()

Clears the tree. This removes all items.

func (Instance) ColumnTitlesVisible

func (self Instance) ColumnTitlesVisible() bool

func (Instance) Columns

func (self Instance) Columns() int

func (Instance) CreateItem

func (self Instance) CreateItem() TreeItem.Instance

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 (self Instance) DropModeFlags() int

func (Instance) EditSelected

func (self Instance) EditSelected() bool

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 (self Instance) EnableRecursiveFolding() bool

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

func (self Instance) GetButtonIdAtPosition(position Vector2.XY) int

Returns the button ID at 'position', or -1 if no button is there.

func (Instance) GetColumnAtPosition

func (self Instance) GetColumnAtPosition(position Vector2.XY) int

Returns the column index at 'position', or -1 if no item is there.

func (Instance) GetColumnExpandRatio

func (self Instance) GetColumnExpandRatio(column int) int

Returns the expand ratio assigned to the column.

func (Instance) GetColumnTitle

func (self Instance) GetColumnTitle(column int) string

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

func (self Instance) GetColumnTitleLanguage(column int) string

Returns column title language code.

func (Instance) GetColumnWidth

func (self Instance) GetColumnWidth(column int) int

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

func (self Instance) GetDropSectionAtPosition(position Vector2.XY) int

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

func (self Instance) GetEdited() TreeItem.Instance

Returns the currently edited item. Can be used with Instance.OnItemEdited to get the item that was modified.

func (Instance) GetEditedColumn

func (self Instance) GetEditedColumn() int

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

func (self Instance) GetItemAtPosition(position Vector2.XY) TreeItem.Instance

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

func (Instance) GetNextSelected

func (self Instance) GetNextSelected(from TreeItem.Instance) TreeItem.Instance

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

func (self Instance) GetPressedButton() int

Returns the last pressed button's index.

func (Instance) GetRoot

func (self Instance) GetRoot() TreeItem.Instance

Returns the tree's root item, or null if the tree is empty.

func (Instance) GetScroll

func (self Instance) GetScroll() Vector2.XY

Returns the current scrolling position.

func (Instance) GetSelected

func (self Instance) GetSelected() TreeItem.Instance

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

func (self Instance) GetSelectedColumn() int

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 (self Instance) HideFolding() bool

func (Instance) HideRoot

func (self Instance) HideRoot() bool

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsColumnClippingContent

func (self Instance) IsColumnClippingContent(column int) bool

Returns true if the column has enabled clipping (see Instance.SetColumnClipContent).

func (Instance) IsColumnExpanding

func (self Instance) IsColumnExpanding(column int) bool

Returns true if the column has enabled expanding (see Instance.SetColumnExpand).

func (Instance) OnButtonClicked

func (self Instance) OnButtonClicked(cb func(item TreeItem.Instance, column int, id int, mouse_button_index int), flags ...Signal.Flags)

func (Instance) OnCellSelected

func (self Instance) OnCellSelected(cb func(), flags ...Signal.Flags)

func (Instance) OnCheckPropagatedToItem

func (self Instance) OnCheckPropagatedToItem(cb func(item TreeItem.Instance, column int), flags ...Signal.Flags)

func (Instance) OnColumnTitleClicked

func (self Instance) OnColumnTitleClicked(cb func(column int, mouse_button_index int), flags ...Signal.Flags)

func (Instance) OnCustomItemClicked

func (self Instance) OnCustomItemClicked(cb func(mouse_button_index int), flags ...Signal.Flags)

func (Instance) OnCustomPopupEdited

func (self Instance) OnCustomPopupEdited(cb func(arrow_clicked bool), flags ...Signal.Flags)

func (Instance) OnEmptyClicked

func (self Instance) OnEmptyClicked(cb func(click_position Vector2.XY, mouse_button_index int), flags ...Signal.Flags)

func (Instance) OnItemActivated

func (self Instance) OnItemActivated(cb func(), flags ...Signal.Flags)

func (Instance) OnItemCollapsed

func (self Instance) OnItemCollapsed(cb func(item TreeItem.Instance), flags ...Signal.Flags)

func (Instance) OnItemEdited

func (self Instance) OnItemEdited(cb func(), flags ...Signal.Flags)

func (Instance) OnItemIconDoubleClicked

func (self Instance) OnItemIconDoubleClicked(cb func(), flags ...Signal.Flags)

func (Instance) OnItemMouseSelected

func (self Instance) OnItemMouseSelected(cb func(mouse_position Vector2.XY, mouse_button_index int), flags ...Signal.Flags)

func (Instance) OnItemSelected

func (self Instance) OnItemSelected(cb func(), flags ...Signal.Flags)

func (Instance) OnMultiSelected

func (self Instance) OnMultiSelected(cb func(item TreeItem.Instance, column int, selected bool), flags ...Signal.Flags)

func (Instance) OnNothingSelected

func (self Instance) OnNothingSelected(cb func(), flags ...Signal.Flags)

func (Instance) ScrollHorizontalEnabled

func (self Instance) ScrollHorizontalEnabled() bool

func (Instance) ScrollToItem

func (self Instance) ScrollToItem(item TreeItem.Instance)

Causes the graphics.gd/classdb/Tree to jump to the specified graphics.gd/classdb/TreeItem.

func (Instance) ScrollVerticalEnabled

func (self Instance) ScrollVerticalEnabled() bool

func (Instance) SelectMode

func (self Instance) SelectMode() SelectMode

func (Instance) SetAllowReselect

func (self Instance) SetAllowReselect(value bool)

func (Instance) SetAllowRmbSelect

func (self Instance) SetAllowRmbSelect(value bool)

func (Instance) SetAllowSearch

func (self Instance) SetAllowSearch(value bool)

func (Instance) SetAutoTooltip

func (self Instance) SetAutoTooltip(value bool)

func (Instance) SetColumnClipContent

func (self Instance) SetColumnClipContent(column int, enable bool)

Allows to enable clipping for column's content, making the content size ignored.

func (Instance) SetColumnCustomMinimumWidth

func (self Instance) SetColumnCustomMinimumWidth(column int, min_width int)

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

func (self Instance) SetColumnExpand(column int, expand bool)

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

func (self Instance) SetColumnExpandRatio(column int, ratio int)

Sets the relative expand ratio for a column. See Instance.SetColumnExpand.

func (Instance) SetColumnTitle

func (self Instance) SetColumnTitle(column int, title string)

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

func (self Instance) SetColumnTitleLanguage(column int, language string)

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 (self Instance) SetColumnTitlesVisible(value bool)

func (Instance) SetColumns

func (self Instance) SetColumns(value int)

func (Instance) SetDropModeFlags

func (self Instance) SetDropModeFlags(value int)

func (Instance) SetEnableRecursiveFolding

func (self Instance) SetEnableRecursiveFolding(value bool)

func (Instance) SetHideFolding

func (self Instance) SetHideFolding(value bool)

func (Instance) SetHideRoot

func (self Instance) SetHideRoot(value bool)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetScrollHorizontalEnabled

func (self Instance) SetScrollHorizontalEnabled(value bool)

func (Instance) SetScrollVerticalEnabled

func (self Instance) SetScrollVerticalEnabled(value bool)

func (Instance) SetSelectMode

func (self Instance) SetSelectMode(value SelectMode)

func (Instance) SetSelected

func (self Instance) SetSelected(item TreeItem.Instance, column int)

Selects the specified graphics.gd/classdb/TreeItem and column.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL