Skip to content

Tree

This is the tree class. It provides a hierarchical view of nodes that can be expanded and collapsed,with support for selection and scrolling.

Extends: VisualElement

Properties

PropertyTypeDefaultDescription
nodestable{}The tree structure containing node objects with {text, children} properties
expandedNodestable{}Table of nodes that are currently expanded
offsetnumber0Current vertical scroll position
horizontalOffsetnumber0Current horizontal scroll position
selectedForegroundColorcolorwhiteforeground color of selected node
selectedBackgroundColorcolorlightBluebackground color of selected node
showScrollBarbooleantrueWhether to show the scrollbar when nodes exceed height
scrollBarSymbolstring"" Symbol used for the scrollbar handle
scrollBarBackgroundstring"\127"Symbol used for the scrollbar background
scrollBarColorcolorlightGrayColor of the scrollbar handle
scrollBarBackgroundColorcolorgrayBackground color of the scrollbar

Functions

MethodReturnsDescription
Tree:expandNodeTreeExpands a node to show its children
Tree:collapseNodeTreeCollapses a node to hide its children
Tree:toggleNodeTreeToggles between expanded and collapsed state
Tree:onSelectTreeRegisters a callback for when a node is selected
Tree:getNodeSizenumber, numberGets the size of the tree

Tree:expandNode(node)

Expands a node

Parameters

  • node table The node to expand

Returns

  • Tree self The Tree instance

Tree:collapseNode(node)

Collapses a node

Parameters

  • node table The node to collapse

Returns

  • Tree self The Tree instance

Tree:toggleNode(node)

Toggles a node's expanded state

Parameters

  • node table The node to toggle

Returns

  • Tree self The Tree instance

Tree:onSelect(callback)

Registers a callback for when a node is selected

Parameters

  • callback function The callback function

Returns

  • Tree self The Tree instance

Tree:getNodeSize()

Gets the size of the tree

Returns

  • number width The width of the tree
  • number height The height of the tree

Released under the MIT License.