Skip to content
coding_jackalope edited this page Jun 18, 2019 · 12 revisions
Table of Contents

Overview

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()

API

Below is a list of functions associated with the Tree API.

BeginTree

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 A string uniquely identifying this tree item within the context of the window.
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.
Icon Object A user supplied image. This must be a valid Love image or the call will assert.
IconPath String If the Icon option is nil, then a path can be specified. Slab will load and manage the image resource.
IsSelected Boolean If true, will render a highlight rectangle around the tree item.
IsOpen Boolean Will force the tree item to be expanded.
Return Description
Boolean Returns true if this tree item is expanded. Slab.EndTree must be called if this returns true.

EndTree

Finishes up any BeginTree calls if those functions return true.

Clone this wiki locally