3.1 KiB
3.1 KiB
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
| Property | Type | Default | Description |
|---|---|---|---|
| nodes | table | {} | The tree structure containing node objects with {text, children} properties |
| expandedNodes | table | {} | Table of nodes that are currently expanded |
| scrollOffset | number | 0 | Current vertical scroll position |
| horizontalOffset | number | 0 | Current horizontal scroll position |
| nodeColor | color | white | Color of unselected nodes |
| selectedColor | color | lightBlue | Background color of selected node |
Functions
| Method | Returns | Description |
|---|---|---|
| Tree.new | Tree | Creates a new Tree instance |
| Tree:Tree | Tree | Initializes the Tree instance |
| Tree:Tree | Tree | Expands a node to show its children |
| Tree:Tree | Tree | Collapses a node to hide its children |
| Tree:Tree | Tree | Toggles between expanded and collapsed state |
| Tree:Tree | boolean | Handles mouse click events for node selection and expansion |
| Tree:Tree | Tree | Registers a callback for when a node is selected |
| Tree:Tree | boolean | Handles mouse scroll events for vertical scrolling |
| Tree:Tree | number, number | Gets the size of the tree |
| Tree:Tree | - | Renders the tree with nodes, selection and scrolling |
Tree.new()
Creates a new Tree instance
Returns
TreeselfThe newly created Tree instance
Tree:Tree(props, basalt)
Initializes the Tree instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
TreeselfThe initialized instance
Tree:Tree(node)
Expands a node
Parameters
nodetableThe node to expand
Returns
TreeselfThe Tree instance
Tree:Tree(node)
Collapses a node
Parameters
nodetableThe node to collapse
Returns
TreeselfThe Tree instance
Tree:Tree(node)
Toggles a node's expanded state
Parameters
nodetableThe node to toggle
Returns
TreeselfThe Tree instance
Tree:Tree(button, x, y)
Handles mouse click events
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Tree:Tree(callback)
Registers a callback for when a node is selected
Parameters
callbackfunctionThe callback function
Returns
TreeselfThe Tree instance
Tree:Tree(direction, x, y)
Parameters
directionnumberThe scroll direction (1 for up, -1 for down)xnumberThe x position of the scrollynumberThe y position of the scroll
Returns
booleanhandledWhether the event was handled
Tree:Tree()
Gets the size of the tree
Returns
numberwidthThe width of the treenumberheightThe height of the tree