Skip to content

Tree : VisualElement

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

Properties

PropertyTypeDefaultDescription
nodestable{}The tree structure containing node objects with {text, children} properties
selectedNodetable?nilCurrently selected node
expandedNodestable{}Table of nodes that are currently expanded
scrollOffsetnumber0Current vertical scroll position
horizontalOffsetnumber0Current horizontal scroll position
nodeColorcolorwhiteColor of unselected nodes
selectedColorcolorlightBlueBackground color of selected node

Functions

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

Protected Functions

MethodReturnsDescription
Tree:initTreeInitializes the Tree instance
Tree:mouse_clickbooleanHandles mouse click events for node selection and expansion
Tree:mouse_scrollbooleanHandles mouse scroll events for vertical scrolling
Tree:render-Renders the tree with nodes, selection and scrolling

Tree:collapseNode(node)

Collapses a node

Parameters

  • node table The node to collapse

Returns

  • Tree self The Tree instance

Tree:expandNode(node)

Expands a node

Parameters

  • node table The node to expand

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

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:toggleNode(node)

Toggles a node's expanded state

Parameters

  • node table The node to toggle

Returns

  • Tree self The Tree instance

Released under the MIT License.