-
-
Notifications
You must be signed in to change notification settings - Fork 26
Tree
Trees allow data to be viewed in a hierarchy. Trees can also contain leaf nodes which have no children.
Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})
if Slab.BeginTree('Root 1') then
if Slab.BeginTree('Child 1') then
Slab.EndTree()
end
Slab.BeginTree('Leaf 1', {IsLeaf = true})
Slab.EndTree()
end
if Slab.BeginTree('Root_2', {Label = "Root 2"}) then
Slab.BeginTree('Leaf_2', {Label = "Leaf 2", IsLeaf = true})
if Slab.BeginTree('Child_2', {Label = "Child 2"}) then
Slab.BeginTree('Leaf_3', {Label = "Leaf 3", IsLeaf = true})
Slab.EndTree()
end
Slab.EndTree()
end
Slab.EndWindow()
Trees can be configured to only open when the arrow is clicked instead of the row.
Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})
if Slab.BeginTree('Root 1', {OpenWithHighlight = false}) then
Slab.BeginTree('Leaf 1', {IsLeaf = true})
Slab.EndTree()
end
Slab.EndWindow()
The Ids of trees can either be a string or a table. If a table is used, the tree will keep a weak reference to the table. If the table is garbage collected, the tree instance is removed from the cached entry within Slab. This will help keep the memory footprint of tree instances to a minimum. The below example shows five table instances being created and slowly being removed over time.
local Ids = {}
function love.load(args)
love.graphics.setBackgroundColor(0.4, 0.88, 1.0)
Slab.Initialize(args)
for I = 1, 5, 1 do
table.insert(Ids, {Label = "Table " .. I})
end
end
local Time = -2
function love.update(dt)
Slab.Update(dt)
Time = Time + dt
if Time > 2 then
table.remove(Ids, 1)
Time = 0
end
Slab.BeginWindow('Tree_Example', {Title = "Tree Ids"})
for I, V in ipairs(Ids) do
Slab.BeginTree(V, {Label = V.Label, IsLeaf = true})
end
Slab.EndWindow()
end
Below is a list of functions associated with the Tree API.
This function will render a tree item with an optional label. The tree can be expanded or collapsed based on whether the user clicked on the tree item. This function can also be nested to create a hierarchy of tree items. This function will return false when collapsed and true when expanded. If this function returns true, Slab.EndTree must be called in order for this tree item to behave properly. The hot zone of this tree item will be the height of the label and the width of the window by default.
Parameter | Type | Description |
---|---|---|
Id | String/Table | A string or table uniquely identifying this tree item within the context of the window. If the given Id is a table, then the internal Tree entry for this table will be removed once the table has been garbage collected. |
Options | Table | List of options for how this tree item will behave. |
Option | Type | Description |
---|---|---|
Label | String | The text to be rendered for this tree item. |
Tooltip | String | The text to be rendered when the user hovers over this tree item. |
IsLeaf | Boolean | If this is true, this tree item will not be expandable/collapsable. |
OpenWithHighlight | Boolean | If this is true, the tree will be expanded/collapsed when the user hovers over the hot zone of this tree item. If this is false, the user must click the expand/collapse icon to interact with this tree item. Default is true
|
Icon | Table | List of options to use for drawing the icon. Refer to the 'Image' documentation for more information. |
IsSelected | Boolean | If true, will render a highlight rectangle around the tree item. |
IsOpen | Boolean | Will force the tree item to be expanded. |
NoSavedSettings | Boolean | Flag to disable saving this tree's settings to the state INI file. |
Return | Description |
---|---|
Boolean | Returns true if this tree item is expanded. Slab.EndTree must be called if this returns true. |
Finishes up any BeginTree calls if those functions return true.