TreeItem
An internal control for a single item inside Tree
.
class TreeItem
A single item of a Tree
control. It can contain other TreeItem
s 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(parent:index:)
or createChild(index:)
. To remove a TreeItem
, use Object/free()
.
Superclasses
class Object
Base class for all other classes in the engine.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
var collapsed: Bool
If
true
, the TreeItem is collapsed.var customMinimumHeight: Int32
The custom minimum height.
var disableFolding: Bool
If
true
, folding is disabled for this TreeItem.var visible: Bool
If
true
, theTreeItem
is visible (default).func addChild(TreeItem?
) Adds a previously unparented
TreeItem
as a direct child of this one. Thechild
item must not be a part of anyTree
or parented to anyTreeItem
. See alsoremoveChild(_:)
.func callRecursive(method: StringName, Variant...
) Calls the
method
on the actual TreeItem and its children recursively. Pass parameters as a comma separated list.func clearCustomBgColor(column: Int32
) Resets the background color for the given column to default.
func clearCustomColor(column: Int32
) Resets the color for the given column to default.
func createChild(index: Int32
) -> TreeItem? Creates an item and adds it as a child.
func deselect(column: Int32
) Deselects the given column.
func getAutowrapMode(column: Int32
) -> TextServer.AutowrapMode Returns the text autowrap mode in the given
column
. By default it isTextServer/AutowrapMode/autowrapOff
.func getButtonById(column: Int32, id: Int32
) -> Int32 Returns the button index if there is a button with ID
id
in columncolumn
, otherwise returns -1.func getButtonCount(column: Int32
) -> Int32 Returns the number of buttons in column
column
.func getCellMode(column: Int32
) -> TreeItem.TreeCellMode Returns the column’s cell mode.
func getChild(index: Int32
) -> TreeItem? Returns a child item by its
index
(seegetChildCount
). This method is often used for iterating all children of an item.func getChildCount(
) -> Int32 Returns the number of child items.
func getChildren(
) -> ObjectCollection<TreeItem> Returns an array of references to the item’s children.
func getCustomBgColor(column: Int32
) -> Color Returns the custom background color of column
column
.func getCustomColor(column: Int32
) -> Color Returns the custom color of column
column
.func getCustomFont(column: Int32
) -> Font? Returns custom font used to draw text in the column
column
.func getCustomFontSize(column: Int32
) -> Int32 Returns custom font size used to draw text in the column
column
.func getExpandRight(column: Int32
) -> Bool Returns
true
ifexpand_right
is set.func getFirstChild(
) -> TreeItem? Returns the TreeItem’s first child.
func getIcon(column: Int32
) -> Texture2D? Returns the given column’s icon
Texture2D
. Error if no icon is set.func getIconMaxWidth(column: Int32
) -> Int32 Returns the maximum allowed width of the icon in the given
column
.func getIconModulate(column: Int32
) -> Color Returns the
Color
modulating the column’s icon.func getIconRegion(column: Int32
) -> Rect2 Returns the icon
Texture2D
region asRect2
.func getIndex(
) -> Int32 Returns the node’s order in the tree. For example, if called on the first child item the position is
0
.func getLanguage(column: Int32
) -> String Returns item’s text language code.
func getMetadata(column: Int32
) -> Variant Returns the metadata value that was set for the given column using
setMetadata(column:meta:)
.func getNext(
) -> TreeItem? Returns the next sibling TreeItem in the tree or a null object if there is none.
func getNextInTree(wrap: Bool
) -> TreeItem? Returns the next TreeItem in the tree (in the context of a depth-first search) or a
null
object if there is none.func getNextVisible(wrap: Bool
) -> TreeItem? Returns the next visible TreeItem in the tree (in the context of a depth-first search) or a
null
object if there is none.func getParent(
) -> TreeItem? Returns the parent TreeItem or a null object if there is none.
func getPrev(
) -> TreeItem? Returns the previous sibling TreeItem in the tree or a null object if there is none.
func getPrevInTree(wrap: Bool
) -> TreeItem? Returns the previous TreeItem in the tree (in the context of a depth-first search) or a
null
object if there is none.func getPrevVisible(wrap: Bool
) -> TreeItem? 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.func getRange(column: Int32
) -> Double Returns the value of a .cellModeRange column.
func getRangeConfig(column: Int32
) -> GDictionary Returns a dictionary containing the range parameters for a given column. The keys are “min”, “max”, “step”, and “expr”.
func getStructuredTextBidiOverride(column: Int32
) -> TextServer.StructuredTextParser func getStructuredTextBidiOverrideOptions(column: Int32
) -> GArray func getSuffix(column: Int32
) -> String Gets the suffix string shown after the column value.
func getText(column: Int32
) -> String Returns the given column’s text.
func getTextAlignment(column: Int32
) -> HorizontalAlignment Returns the given column’s text alignment.
func getTextDirection(column: Int32
) -> Control.TextDirection Returns item’s text base writing direction.
func getTextOverrunBehavior(column: Int32
) -> TextServer.OverrunBehavior Returns the clipping behavior when the text exceeds the item’s bounding rectangle in the given
column
. By default it isTextServer/OverrunBehavior/overrunTrimEllipsis
.func getTooltipText(column: Int32
) -> String Returns the given column’s tooltip text.
func getTree(
) -> Tree? Returns the
Tree
that owns this TreeItem.func isAnyCollapsed(onlyVisible: Bool
) -> Bool Returns
true
if thisTreeItem
, or any of its descendants, is collapsed.func isChecked(column: Int32
) -> Bool Returns
true
if the givencolumn
is checked.func isCustomSetAsButton(column: Int32
) -> Bool func isEditMultiline(column: Int32
) -> Bool Returns
true
if the givencolumn
is multiline editable.func isEditable(column: Int32
) -> Bool Returns
true
if the givencolumn
is editable.func isIndeterminate(column: Int32
) -> Bool Returns
true
if the givencolumn
is indeterminate.func isSelectable(column: Int32
) -> Bool Returns
true
if the givencolumn
is selectable.func isSelected(column: Int32
) -> Bool Returns
true
if the givencolumn
is selected.func moveAfter(item: TreeItem?
) Moves this TreeItem right after the given
item
.func moveBefore(item: TreeItem?
) Moves this TreeItem right before the given
item
.func propagateCheck(column: Int32, emitSignal: 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 [signal Tree.check_propagated_to_item]. 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. IfemitSignal
isfalse
, then [signal Tree.check_propagated_to_item] will not be emitted.func removeChild(TreeItem?
) Removes the given child
TreeItem
and all its children from theTree
. Note that it doesn’t free the item from memory, so it can be reused later (seeaddChild(_:)
). To completely remove aTreeItem
useObject/free()
.func select(column: Int32
) Selects the given
column
.func setAutowrapMode(column: Int32, autowrapMode: TextServer.AutowrapMode
) Sets the autowrap mode in the given
column
. If set to something other thanTextServer/AutowrapMode/autowrapOff
, the text gets wrapped inside the cell’s bounding rectangle.func setCellMode(column: Int32, mode: TreeItem.TreeCellMode
) Sets the given column’s cell mode to
mode
. SeeTreeCellMode
constants.func setChecked(column: Int32, checked: Bool
) If
checked
istrue
, the givencolumn
is checked. Clears column’s indeterminate status.func setCollapsedRecursive(enable: Bool
) Collapses or uncollapses this
TreeItem
and all the descendants of this item.func setCustomAsButton(column: Int32, enable: Bool
) func setCustomBgColor(column: Int32, color: Color, justOutline: Bool
) Sets the given column’s custom background color and whether to just use it as an outline.
func setCustomColor(column: Int32, color: Color
) Sets the given column’s custom color.
func setCustomDraw(column: Int32, object: Object?, callback: StringName
) Sets the given column’s custom draw callback to
callback
method onobject
.func setCustomFont(column: Int32, font: Font?
) Sets custom font used to draw text in the given
column
.func setCustomFontSize(column: Int32, fontSize: Int32
) Sets custom font size used to draw text in the given
column
.func setEditMultiline(column: Int32, multiline: Bool
) If
multiline
istrue
, the givencolumn
is multiline editable.func setEditable(column: Int32, enabled: Bool
) If
enabled
istrue
, the givencolumn
is editable.func setExpandRight(column: Int32, enable: Bool
) If
enable
istrue
, the givencolumn
is expanded to the right.func setIcon(column: Int32, texture: Texture2D?
) Sets the given column’s icon
Texture2D
.func setIconMaxWidth(column: Int32, width: Int32
) 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 [theme_item Tree.icon_max_width]. The height is adjusted according to the icon’s ratio.func setIconModulate(column: Int32, modulate: Color
) Modulates the given column’s icon with
modulate
.func setIconRegion(column: Int32, region: Rect2
) Sets the given column’s icon’s texture region.
func setIndeterminate(column: Int32, indeterminate: Bool
) If
indeterminate
istrue
, the givencolumn
is marked indeterminate.func setLanguage(column: Int32, language: String
) Sets language code of item’s text used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
func setMetadata(column: Int32, meta: Variant
) Sets the metadata value for the given column, which can be retrieved later using
getMetadata(column:)
. This can be used, for example, to store a reference to the original data.func setRange(column: Int32, value: Double
) Sets the value of a .cellModeRange column.
func setRangeConfig(column: Int32, min: Double, max: Double, step: Double, expr: Bool
) Sets the range of accepted values for a column. The column must be in the .cellModeRange mode.
func setSelectable(column: Int32, selectable: Bool
) If
selectable
istrue
, the givencolumn
is selectable.func setStructuredTextBidiOverride(column: Int32, parser: TextServer.StructuredTextParser
) func setStructuredTextBidiOverrideOptions(column: Int32, args: GArray
) func setSuffix(column: Int32, text: String
) Sets a string to be shown after a column’s value (for example, a unit abbreviation).
func setText(column: Int32, text: String
) Sets the given column’s text value.
func setTextAlignment(column: Int32, textAlignment: HorizontalAlignment
) Sets the given column’s text alignment. See
HorizontalAlignment
for possible values.func setTextDirection(column: Int32, direction: Control.TextDirection
) Sets item’s text base writing direction.
func setTextOverrunBehavior(column: Int32, overrunBehavior: TextServer.OverrunBehavior
) Sets the clipping behavior when the text exceeds the item’s bounding rectangle in the given
column
.func setTooltipText(column: Int32, tooltip: String
) Sets the given column’s tooltip text.
func uncollapseTree(
)