Files
Basalt/docs/objects/Treeview.md
Robert Jelic 6bab574e8a Treeview Docs
Added Treeview docs
Improved some stuff in the treeview object
2023-05-01 14:56:16 +02:00

2.8 KiB

Treeview objects provide a hierarchical representation of data, allowing users to navigate and interact with items organized in a tree-like structure. They are commonly used in file explorers and other applications that require a hierarchical view of data.

Treeview objects inherit methods from VisualObject and Object. This means that Treeview objects can also use methods from VisualObject and Object.

setOffset Sets the offset for the tree view
getOffset Returns the current offset
setScrollable Sets whether the tree view is scrollable
setSelectionColor Sets the color of the selected item
getSelectionColor Returns the current selection color
isSelectionColorActive Checks if the selection color is active
getRoot Returns the root node of the tree view
setRoot Sets a new root node

Events

This is a list of all available events for treeviews:

onSelect Fires when an item is clicked

Node Methods

getChildren Returns a table of the node's children
getParent Returns the node's parent
addChild Adds a new child node to the current node
setExpanded Sets the expanded state of the node
isExpanded Returns whether the node is expanded
onSelect Fires when a node is clicked
setExpandable Sets whether the node can be expanded or collapsed
isExpandable Returns whether the node is expandable
removeChild Removes a child node from the current node
findChildrenByText Finds child nodes with the specified text
getText Returns the node's text
setText Sets the node's text

Example

Here's an example of how to create a TreeView object and set its properties:

local main = basalt.createFrame()
local treeView = main:addTreeView()

local rootNode = treeView:getRoot()
local childNode = rootNode.addChild("Child Node")

childNode.onSelect(function(self)
    basalt.debug("Node selected:", self.getText())
end)

This example creates a Treeview object within a main frame, sets its properties, and adds a child node to the root node. When the child node is selected, a debug message will be printed with the node's text.