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
CustomMinimumHeight
The custom minimum height.
public int CustomMinimumHeight { get; set; }
Property Value
DisableFolding
If true, folding is disabled for this TreeItem.
public bool DisableFolding { get; set; }
Property Value
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
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
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
StringNameargs
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
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
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
GetButton(int, int)
Returns the Texture2D of the button at index buttonIndex
in column column
.
public Texture2D GetButton(int column, int buttonIndex)
Parameters
Returns
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
Returns
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
Returns
GetButtonCount(int)
Returns the number of buttons in column column
.
public int GetButtonCount(int column)
Parameters
column
int
Returns
GetButtonId(int, int)
Returns the ID for the button at index buttonIndex
in column column
.
public int GetButtonId(int column, int buttonIndex)
Parameters
Returns
GetButtonTooltipText(int, int)
Returns the tooltip text for the button at index buttonIndex
in column column
.
public string GetButtonTooltipText(int column, int buttonIndex)
Parameters
Returns
GetCellMode(int)
Returns the column's cell mode.
public TreeItem.TreeCellMode GetCellMode(int column)
Parameters
column
int
Returns
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
GetChildCount()
Returns the number of child items.
public int GetChildCount()
Returns
GetChildren()
Returns an array of references to the item's children.
public Array<TreeItem> GetChildren()
Returns
GetCustomBgColor(int)
Returns the custom background color of column column
.
public Color GetCustomBgColor(int column)
Parameters
column
int
Returns
GetCustomColor(int)
Returns the custom color of column column
.
public Color GetCustomColor(int column)
Parameters
column
int
Returns
GetCustomDrawCallback(int)
Returns the custom callback of column column
.
public Callable GetCustomDrawCallback(int column)
Parameters
column
int
Returns
GetCustomFont(int)
Returns custom font used to draw text in the column column
.
public Font GetCustomFont(int column)
Parameters
column
int
Returns
GetCustomFontSize(int)
Returns custom font size used to draw text in the column column
.
public int GetCustomFontSize(int column)
Parameters
column
int
Returns
GetExpandRight(int)
Returns true if expand_right
is set.
public bool GetExpandRight(int column)
Parameters
column
int
Returns
GetFirstChild()
Returns the TreeItem's first child.
public TreeItem GetFirstChild()
Returns
GetIcon(int)
Returns the given column's icon Texture2D. Error if no icon is set.
public Texture2D GetIcon(int column)
Parameters
column
int
Returns
GetIconMaxWidth(int)
Returns the maximum allowed width of the icon in the given column
.
public int GetIconMaxWidth(int column)
Parameters
column
int
Returns
GetIconModulate(int)
Returns the Color modulating the column's icon.
public Color GetIconModulate(int column)
Parameters
column
int
Returns
GetIconRegion(int)
public Rect2 GetIconRegion(int column)
Parameters
column
int
Returns
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
GetLanguage(int)
Returns item's text language code.
public string GetLanguage(int column)
Parameters
column
int
Returns
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
GetNext()
Returns the next sibling TreeItem in the tree or a null object if there is none.
public TreeItem GetNext()
Returns
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
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
GetParent()
Returns the parent TreeItem or a null object if there is none.
public TreeItem GetParent()
Returns
GetPrev()
Returns the previous sibling TreeItem in the tree or a null object if there is none.
public TreeItem GetPrev()
Returns
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
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
GetRange(int)
Returns the value of a Range column.
public double GetRange(int column)
Parameters
column
int
Returns
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
GetStructuredTextBidiOverride(int)
Returns the BiDi algorithm override set for this cell.
public TextServer.StructuredTextParser GetStructuredTextBidiOverride(int column)
Parameters
column
int
Returns
GetStructuredTextBidiOverrideOptions(int)
Returns the additional BiDi options set for this cell.
public Array GetStructuredTextBidiOverrideOptions(int column)
Parameters
column
int
Returns
GetSuffix(int)
Gets the suffix string shown after the column value.
public string GetSuffix(int column)
Parameters
column
int
Returns
GetText(int)
Returns the given column's text.
public string GetText(int column)
Parameters
column
int
Returns
GetTextAlignment(int)
Returns the given column's text alignment.
public HorizontalAlignment GetTextAlignment(int column)
Parameters
column
int
Returns
GetTextDirection(int)
Returns item's text base writing direction.
public Control.TextDirection GetTextDirection(int column)
Parameters
column
int
Returns
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
GetTooltipText(int)
Returns the given column's tooltip text.
public string GetTooltipText(int column)
Parameters
column
int
Returns
GetTree()
Returns the Tree that owns this TreeItem.
public Tree GetTree()
Returns
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsAnyCollapsed(bool)
public bool IsAnyCollapsed(bool onlyVisible = false)
Parameters
onlyVisible
bool
Returns
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
Returns
IsChecked(int)
Returns true if the given column
is checked.
public bool IsChecked(int column)
Parameters
column
int
Returns
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
IsEditMultiline(int)
Returns true if the given column
is multiline editable.
public bool IsEditMultiline(int column)
Parameters
column
int
Returns
IsEditable(int)
Returns true if the given column
is editable.
public bool IsEditable(int column)
Parameters
column
int
Returns
IsIndeterminate(int)
Returns true if the given column
is indeterminate.
public bool IsIndeterminate(int column)
Parameters
column
int
Returns
IsSelectable(int)
Returns true if the given column
is selectable.
public bool IsSelectable(int column)
Parameters
column
int
Returns
IsSelected(int)
Returns true if the given column
is selected.
public bool IsSelected(int column)
Parameters
column
int
Returns
IsVisibleInTree()
public bool IsVisibleInTree()
Returns
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
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
intautowrapMode
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
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
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
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
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
intmode
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
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)
public void SetCustomAsButton(int column, bool enable)
Parameters
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
SetCustomColor(int, Color)
Sets the given column's custom color.
public void SetCustomColor(int column, Color color)
Parameters
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
intobject
GodotObjectcallback
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
SetCustomFont(int, Font)
Sets custom font used to draw text in the given column
.
public void SetCustomFont(int column, Font font)
Parameters
SetCustomFontSize(int, int)
Sets custom font size used to draw text in the given column
.
public void SetCustomFontSize(int column, int fontSize)
Parameters
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
SetEditable(int, bool)
If enabled
is true, the given column
is editable.
public void SetEditable(int column, bool enabled)
Parameters
SetExpandRight(int, bool)
If enable
is true, the given column
is expanded to the right.
public void SetExpandRight(int column, bool enable)
Parameters
SetIcon(int, Texture2D)
public void SetIcon(int column, Texture2D texture)
Parameters
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
SetIconModulate(int, Color)
Modulates the given column's icon with modulate
.
public void SetIconModulate(int column, Color modulate)
Parameters
SetIconRegion(int, Rect2)
Sets the given column's icon's texture region.
public void SetIconRegion(int column, Rect2 region)
Parameters
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
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
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
SetRange(int, double)
Sets the value of a Range column.
public void SetRange(int column, double value)
Parameters
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
SetSelectable(int, bool)
If selectable
is true, the given column
is selectable.
public void SetSelectable(int column, bool selectable)
Parameters
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
intparser
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
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
SetText(int, string)
Sets the given column's text value.
public void SetText(int column, string text)
Parameters
SetTextAlignment(int, HorizontalAlignment)
Sets the given column's text alignment. See HorizontalAlignment for possible values.
public void SetTextAlignment(int column, HorizontalAlignment textAlignment)
Parameters
column
inttextAlignment
HorizontalAlignment
SetTextDirection(int, TextDirection)
Sets item's text base writing direction.
public void SetTextDirection(int column, Control.TextDirection direction)
Parameters
column
intdirection
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
intoverrunBehavior
TextServer.OverrunBehavior
SetTooltipText(int, string)
Sets the given column's tooltip text.
public void SetTooltipText(int column, string tooltip)
Parameters
UncollapseTree()
public void UncollapseTree()