Table of Contents

Class TreeItem

Namespace
Godot
Assembly
GodotSharp.dll

A single item of a Tree control. It can contain other TreeItems as children, which allows it to create a hierarchy. It can also contain text and buttons. TreeItem is not a Node, it is internal to the Tree.

To create a TreeItem, use CreateItem(TreeItem, int) or CreateChild(int). To remove a TreeItem, use Free().

Note: The ID values used for buttons are 32-bit, unlike int which is always 64-bit. They go from -2147483648 to 2147483647.

public class TreeItem : GodotObject, IDisposable
Inheritance
TreeItem
Implements
Inherited Members

Properties

Collapsed

If true, the TreeItem is collapsed.

public bool Collapsed { get; set; }

Property Value

bool

CustomMinimumHeight

The custom minimum height.

public int CustomMinimumHeight { get; set; }

Property Value

int

DisableFolding

If true, folding is disabled for this TreeItem.

public bool DisableFolding { get; set; }

Property Value

bool

Visible

If true, the TreeItem is visible (default).

Note that if a TreeItem is set to not be visible, none of its children will be visible either.

public bool Visible { get; set; }

Property Value

bool

Methods

AddButton(int, Texture2D, int, bool, string)

Adds a button with Texture2Dbutton at column column. The id is used to identify the button in the according ButtonClicked signal and can be different from the buttons index. If not specified, the next available index is used, which may be retrieved by calling GetButtonCount(int) immediately before this method. Optionally, the button can be disabled and have a tooltipText.

public void AddButton(int column, Texture2D button, int id = -1, bool disabled = false, string tooltipText = "")

Parameters

column int
button Texture2D
id int
disabled bool
tooltipText string

AddChild(TreeItem)

Adds a previously unparented TreeItem as a direct child of this one. The child item must not be a part of any Tree or parented to any TreeItem. See also RemoveChild(TreeItem).

public void AddChild(TreeItem child)

Parameters

child TreeItem

CallRecursive(StringName, params Variant[])

Calls the method on the actual TreeItem and its children recursively. Pass parameters as a comma separated list.

public void CallRecursive(StringName method, params Variant[] args)

Parameters

method StringName
args Variant[]

ClearCustomBgColor(int)

Resets the background color for the given column to default.

public void ClearCustomBgColor(int column)

Parameters

column int

ClearCustomColor(int)

Resets the color for the given column to default.

public void ClearCustomColor(int column)

Parameters

column int

CreateChild(int)

Creates an item and adds it as a child.

The new item will be inserted as position index (the default value -1 means the last position), or it will be the last child if index is higher than the child count.

public TreeItem CreateChild(int index = -1)

Parameters

index int

Returns

TreeItem

Deselect(int)

Deselects the given column.

public void Deselect(int column)

Parameters

column int

EraseButton(int, int)

Removes the button at index buttonIndex in column column.

public void EraseButton(int column, int buttonIndex)

Parameters

column int
buttonIndex int

GetAutowrapMode(int)

Returns the text autowrap mode in the given column. By default it is Off.

public TextServer.AutowrapMode GetAutowrapMode(int column)

Parameters

column int

Returns

TextServer.AutowrapMode

GetButton(int, int)

Returns the Texture2D of the button at index buttonIndex in column column.

public Texture2D GetButton(int column, int buttonIndex)

Parameters

column int
buttonIndex int

Returns

Texture2D

GetButtonById(int, int)

Returns the button index if there is a button with ID id in column column, otherwise returns -1.

public int GetButtonById(int column, int id)

Parameters

column int
id int

Returns

int

GetButtonColor(int, int)

Returns the color of the button with ID id in column column. If the specified button does not exist, returns Color.BLACK.

public Color GetButtonColor(int column, int id)

Parameters

column int
id int

Returns

Color

GetButtonCount(int)

Returns the number of buttons in column column.

public int GetButtonCount(int column)

Parameters

column int

Returns

int

GetButtonId(int, int)

Returns the ID for the button at index buttonIndex in column column.

public int GetButtonId(int column, int buttonIndex)

Parameters

column int
buttonIndex int

Returns

int

GetButtonTooltipText(int, int)

Returns the tooltip text for the button at index buttonIndex in column column.

public string GetButtonTooltipText(int column, int buttonIndex)

Parameters

column int
buttonIndex int

Returns

string

GetCellMode(int)

Returns the column's cell mode.

public TreeItem.TreeCellMode GetCellMode(int column)

Parameters

column int

Returns

TreeItem.TreeCellMode

GetChild(int)

Returns a child item by its index (see GetChildCount()). This method is often used for iterating all children of an item.

Negative indices access the children from the last one.

public TreeItem GetChild(int index)

Parameters

index int

Returns

TreeItem

GetChildCount()

Returns the number of child items.

public int GetChildCount()

Returns

int

GetChildren()

Returns an array of references to the item's children.

public Array<TreeItem> GetChildren()

Returns

Array<TreeItem>

GetCustomBgColor(int)

Returns the custom background color of column column.

public Color GetCustomBgColor(int column)

Parameters

column int

Returns

Color

GetCustomColor(int)

Returns the custom color of column column.

public Color GetCustomColor(int column)

Parameters

column int

Returns

Color

GetCustomDrawCallback(int)

Returns the custom callback of column column.

public Callable GetCustomDrawCallback(int column)

Parameters

column int

Returns

Callable

GetCustomFont(int)

Returns custom font used to draw text in the column column.

public Font GetCustomFont(int column)

Parameters

column int

Returns

Font

GetCustomFontSize(int)

Returns custom font size used to draw text in the column column.

public int GetCustomFontSize(int column)

Parameters

column int

Returns

int

GetExpandRight(int)

Returns true if expand_right is set.

public bool GetExpandRight(int column)

Parameters

column int

Returns

bool

GetFirstChild()

Returns the TreeItem's first child.

public TreeItem GetFirstChild()

Returns

TreeItem

GetIcon(int)

Returns the given column's icon Texture2D. Error if no icon is set.

public Texture2D GetIcon(int column)

Parameters

column int

Returns

Texture2D

GetIconMaxWidth(int)

Returns the maximum allowed width of the icon in the given column.

public int GetIconMaxWidth(int column)

Parameters

column int

Returns

int

GetIconModulate(int)

Returns the Color modulating the column's icon.

public Color GetIconModulate(int column)

Parameters

column int

Returns

Color

GetIconRegion(int)

Returns the icon Texture2D region as Rect2.

public Rect2 GetIconRegion(int column)

Parameters

column int

Returns

Rect2

GetIndex()

Returns the node's order in the tree. For example, if called on the first child item the position is 0.

public int GetIndex()

Returns

int

GetLanguage(int)

Returns item's text language code.

public string GetLanguage(int column)

Parameters

column int

Returns

string

GetMetadata(int)

Returns the metadata value that was set for the given column using SetMetadata(int, Variant).

public Variant GetMetadata(int column)

Parameters

column int

Returns

Variant

GetNext()

Returns the next sibling TreeItem in the tree or a null object if there is none.

public TreeItem GetNext()

Returns

TreeItem

GetNextInTree(bool)

Returns the next TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the first element in the tree when called on the last element, otherwise it returns null.

public TreeItem GetNextInTree(bool wrap = false)

Parameters

wrap bool

Returns

TreeItem

GetNextVisible(bool)

Returns the next visible TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the first visible element in the tree when called on the last visible element, otherwise it returns null.

public TreeItem GetNextVisible(bool wrap = false)

Parameters

wrap bool

Returns

TreeItem

GetParent()

Returns the parent TreeItem or a null object if there is none.

public TreeItem GetParent()

Returns

TreeItem

GetPrev()

Returns the previous sibling TreeItem in the tree or a null object if there is none.

public TreeItem GetPrev()

Returns

TreeItem

GetPrevInTree(bool)

Returns the previous TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the last element in the tree when called on the first visible element, otherwise it returns null.

public TreeItem GetPrevInTree(bool wrap = false)

Parameters

wrap bool

Returns

TreeItem

GetPrevVisible(bool)

Returns the previous visible sibling TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the last visible element in the tree when called on the first visible element, otherwise it returns null.

public TreeItem GetPrevVisible(bool wrap = false)

Parameters

wrap bool

Returns

TreeItem

GetRange(int)

Returns the value of a Range column.

public double GetRange(int column)

Parameters

column int

Returns

double

GetRangeConfig(int)

Returns a dictionary containing the range parameters for a given column. The keys are "min", "max", "step", and "expr".

public Dictionary GetRangeConfig(int column)

Parameters

column int

Returns

Dictionary

GetStructuredTextBidiOverride(int)

Returns the BiDi algorithm override set for this cell.

public TextServer.StructuredTextParser GetStructuredTextBidiOverride(int column)

Parameters

column int

Returns

TextServer.StructuredTextParser

GetStructuredTextBidiOverrideOptions(int)

Returns the additional BiDi options set for this cell.

public Array GetStructuredTextBidiOverrideOptions(int column)

Parameters

column int

Returns

Array

GetSuffix(int)

Gets the suffix string shown after the column value.

public string GetSuffix(int column)

Parameters

column int

Returns

string

GetText(int)

Returns the given column's text.

public string GetText(int column)

Parameters

column int

Returns

string

GetTextAlignment(int)

Returns the given column's text alignment.

public HorizontalAlignment GetTextAlignment(int column)

Parameters

column int

Returns

HorizontalAlignment

GetTextDirection(int)

Returns item's text base writing direction.

public Control.TextDirection GetTextDirection(int column)

Parameters

column int

Returns

Control.TextDirection

GetTextOverrunBehavior(int)

Returns the clipping behavior when the text exceeds the item's bounding rectangle in the given column. By default it is TrimEllipsis.

public TextServer.OverrunBehavior GetTextOverrunBehavior(int column)

Parameters

column int

Returns

TextServer.OverrunBehavior

GetTooltipText(int)

Returns the given column's tooltip text.

public string GetTooltipText(int column)

Parameters

column int

Returns

string

GetTree()

Returns the Tree that owns this TreeItem.

public Tree GetTree()

Returns

Tree

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsAnyCollapsed(bool)

Returns true if this TreeItem, or any of its descendants, is collapsed.

If onlyVisible is true it ignores non-visible TreeItems.

public bool IsAnyCollapsed(bool onlyVisible = false)

Parameters

onlyVisible bool

Returns

bool

IsButtonDisabled(int, int)

Returns true if the button at index buttonIndex for the given column is disabled.

public bool IsButtonDisabled(int column, int buttonIndex)

Parameters

column int
buttonIndex int

Returns

bool

IsChecked(int)

Returns true if the given column is checked.

public bool IsChecked(int column)

Parameters

column int

Returns

bool

IsCustomSetAsButton(int)

Returns true if the cell was made into a button with SetCustomAsButton(int, bool).

public bool IsCustomSetAsButton(int column)

Parameters

column int

Returns

bool

IsEditMultiline(int)

Returns true if the given column is multiline editable.

public bool IsEditMultiline(int column)

Parameters

column int

Returns

bool

IsEditable(int)

Returns true if the given column is editable.

public bool IsEditable(int column)

Parameters

column int

Returns

bool

IsIndeterminate(int)

Returns true if the given column is indeterminate.

public bool IsIndeterminate(int column)

Parameters

column int

Returns

bool

IsSelectable(int)

Returns true if the given column is selectable.

public bool IsSelectable(int column)

Parameters

column int

Returns

bool

IsSelected(int)

Returns true if the given column is selected.

public bool IsSelected(int column)

Parameters

column int

Returns

bool

IsVisibleInTree()

Returns true if Visible is true and all its ancestors are also visible.

public bool IsVisibleInTree()

Returns

bool

MoveAfter(TreeItem)

Moves this TreeItem right after the given item.

Note: You can't move to the root or move the root.

public void MoveAfter(TreeItem item)

Parameters

item TreeItem

MoveBefore(TreeItem)

Moves this TreeItem right before the given item.

Note: You can't move to the root or move the root.

public void MoveBefore(TreeItem item)

Parameters

item TreeItem

PropagateCheck(int, bool)

Propagates this item's checked status to its children and parents for the given column. It is possible to process the items affected by this method call by connecting to CheckPropagatedToItem. The order that the items affected will be processed is as follows: the item invoking this method, children of that item, and finally parents of that item. If emitSignal is false, then CheckPropagatedToItem will not be emitted.

public void PropagateCheck(int column, bool emitSignal = true)

Parameters

column int
emitSignal bool

RemoveChild(TreeItem)

Removes the given child TreeItem and all its children from the Tree. Note that it doesn't free the item from memory, so it can be reused later (see AddChild(TreeItem)). To completely remove a TreeItem use Free().

Note: If you want to move a child from one Tree to another, then instead of removing and adding it manually you can use MoveBefore(TreeItem) or MoveAfter(TreeItem).

public void RemoveChild(TreeItem child)

Parameters

child TreeItem

Select(int)

Selects the given column.

public void Select(int column)

Parameters

column int

SetAutowrapMode(int, AutowrapMode)

Sets the autowrap mode in the given column. If set to something other than Off, the text gets wrapped inside the cell's bounding rectangle.

public void SetAutowrapMode(int column, TextServer.AutowrapMode autowrapMode)

Parameters

column int
autowrapMode TextServer.AutowrapMode

SetButton(int, int, Texture2D)

Sets the given column's button Texture2D at index buttonIndex to button.

public void SetButton(int column, int buttonIndex, Texture2D button)

Parameters

column int
buttonIndex int
button Texture2D

SetButtonColor(int, int, Color)

Sets the given column's button color at index buttonIndex to color.

public void SetButtonColor(int column, int buttonIndex, Color color)

Parameters

column int
buttonIndex int
color Color

SetButtonDisabled(int, int, bool)

If true, disables the button at index buttonIndex in the given column.

public void SetButtonDisabled(int column, int buttonIndex, bool disabled)

Parameters

column int
buttonIndex int
disabled bool

SetButtonTooltipText(int, int, string)

Sets the tooltip text for the button at index buttonIndex in the given column.

public void SetButtonTooltipText(int column, int buttonIndex, string tooltip)

Parameters

column int
buttonIndex int
tooltip string

SetCellMode(int, TreeCellMode)

Sets the given column's cell mode to mode. This determines how the cell is displayed and edited. See TreeItem.TreeCellMode constants for details.

public void SetCellMode(int column, TreeItem.TreeCellMode mode)

Parameters

column int
mode TreeItem.TreeCellMode

SetChecked(int, bool)

If checked is true, the given column is checked. Clears column's indeterminate status.

public void SetChecked(int column, bool @checked)

Parameters

column int
checked bool

SetCollapsedRecursive(bool)

Collapses or uncollapses this TreeItem and all the descendants of this item.

public void SetCollapsedRecursive(bool enable)

Parameters

enable bool

SetCustomAsButton(int, bool)

Makes a cell with Custom display as a non-flat button with a StyleBox.

public void SetCustomAsButton(int column, bool enable)

Parameters

column int
enable bool

SetCustomBgColor(int, Color, bool)

Sets the given column's custom background color and whether to just use it as an outline.

public void SetCustomBgColor(int column, Color color, bool justOutline = false)

Parameters

column int
color Color
justOutline bool

SetCustomColor(int, Color)

Sets the given column's custom color.

public void SetCustomColor(int column, Color color)

Parameters

column int
color Color

SetCustomDraw(int, GodotObject, StringName)

Sets the given column's custom draw callback to the callback method on object.

The method named callback should accept two arguments: the TreeItem that is drawn and its position and size as a Rect2.

[Obsolete("Use 'Godot.TreeItem.SetCustomDrawCallback(int, Callable)' instead.")]
public void SetCustomDraw(int column, GodotObject @object, StringName callback)

Parameters

column int
object GodotObject
callback StringName

SetCustomDrawCallback(int, Callable)

Sets the given column's custom draw callback. Use an empty Callable (Callable()) to clear the custom callback. The cell has to be in Custom to use this feature.

The callback should accept two arguments: the TreeItem that is drawn and its position and size as a Rect2.

public void SetCustomDrawCallback(int column, Callable callback)

Parameters

column int
callback Callable

SetCustomFont(int, Font)

Sets custom font used to draw text in the given column.

public void SetCustomFont(int column, Font font)

Parameters

column int
font Font

SetCustomFontSize(int, int)

Sets custom font size used to draw text in the given column.

public void SetCustomFontSize(int column, int fontSize)

Parameters

column int
fontSize int

SetEditMultiline(int, bool)

If multiline is true, the given column is multiline editable.

Note: This option only affects the type of control (LineEdit or TextEdit) that appears when editing the column. You can set multiline values with SetText(int, string) even if the column is not multiline editable.

public void SetEditMultiline(int column, bool multiline)

Parameters

column int
multiline bool

SetEditable(int, bool)

If enabled is true, the given column is editable.

public void SetEditable(int column, bool enabled)

Parameters

column int
enabled bool

SetExpandRight(int, bool)

If enable is true, the given column is expanded to the right.

public void SetExpandRight(int column, bool enable)

Parameters

column int
enable bool

SetIcon(int, Texture2D)

Sets the given cell's icon Texture2D. The cell has to be in Icon mode.

public void SetIcon(int column, Texture2D texture)

Parameters

column int
texture Texture2D

SetIconMaxWidth(int, int)

Sets the maximum allowed width of the icon in the given column. This limit is applied on top of the default size of the icon and on top of Tree.icon_max_width. The height is adjusted according to the icon's ratio.

public void SetIconMaxWidth(int column, int width)

Parameters

column int
width int

SetIconModulate(int, Color)

Modulates the given column's icon with modulate.

public void SetIconModulate(int column, Color modulate)

Parameters

column int
modulate Color

SetIconRegion(int, Rect2)

Sets the given column's icon's texture region.

public void SetIconRegion(int column, Rect2 region)

Parameters

column int
region Rect2

SetIndeterminate(int, bool)

If indeterminate is true, the given column is marked indeterminate.

Note: If set true from false, then column is cleared of checked status.

public void SetIndeterminate(int column, bool indeterminate)

Parameters

column int
indeterminate bool

SetLanguage(int, string)

Sets language code of item's text used for line-breaking and text shaping algorithms, if left empty current locale is used instead.

public void SetLanguage(int column, string language)

Parameters

column int
language string

SetMetadata(int, Variant)

Sets the metadata value for the given column, which can be retrieved later using GetMetadata(int). This can be used, for example, to store a reference to the original data.

public void SetMetadata(int column, Variant meta)

Parameters

column int
meta Variant

SetRange(int, double)

Sets the value of a Range column.

public void SetRange(int column, double value)

Parameters

column int
value double

SetRangeConfig(int, double, double, double, bool)

Sets the range of accepted values for a column. The column must be in the Range mode.

If expr is true, the edit mode slider will use an exponential scale as with ExpEdit.

public void SetRangeConfig(int column, double min, double max, double step, bool expr = false)

Parameters

column int
min double
max double
step double
expr bool

SetSelectable(int, bool)

If selectable is true, the given column is selectable.

public void SetSelectable(int column, bool selectable)

Parameters

column int
selectable bool

SetStructuredTextBidiOverride(int, StructuredTextParser)

Set BiDi algorithm override for the structured text. Has effect for cells that display text.

public void SetStructuredTextBidiOverride(int column, TextServer.StructuredTextParser parser)

Parameters

column int
parser TextServer.StructuredTextParser

SetStructuredTextBidiOverrideOptions(int, Array)

Set additional options for BiDi override. Has effect for cells that display text.

public void SetStructuredTextBidiOverrideOptions(int column, Array args)

Parameters

column int
args Array

SetSuffix(int, string)

Sets a string to be shown after a column's value (for example, a unit abbreviation).

public void SetSuffix(int column, string text)

Parameters

column int
text string

SetText(int, string)

Sets the given column's text value.

public void SetText(int column, string text)

Parameters

column int
text string

SetTextAlignment(int, HorizontalAlignment)

Sets the given column's text alignment. See HorizontalAlignment for possible values.

public void SetTextAlignment(int column, HorizontalAlignment textAlignment)

Parameters

column int
textAlignment HorizontalAlignment

SetTextDirection(int, TextDirection)

Sets item's text base writing direction.

public void SetTextDirection(int column, Control.TextDirection direction)

Parameters

column int
direction Control.TextDirection

SetTextOverrunBehavior(int, OverrunBehavior)

Sets the clipping behavior when the text exceeds the item's bounding rectangle in the given column.

public void SetTextOverrunBehavior(int column, TextServer.OverrunBehavior overrunBehavior)

Parameters

column int
overrunBehavior TextServer.OverrunBehavior

SetTooltipText(int, string)

Sets the given column's tooltip text.

public void SetTooltipText(int column, string tooltip)

Parameters

column int
tooltip string

UncollapseTree()

Uncollapses all TreeItems necessary to reveal this TreeItem, i.e. all ancestor TreeItems.

public void UncollapseTree()