Skip to content

ListBox

coding_jackalope edited this page Oct 19, 2020 · 6 revisions
Table of Contents

Overview

A list box is a scrollable region that contains a list of elements that a user can interact with. The API is flexible so that each element in the list can be rendered in any way desired. Below are a few examples on different ways a list box can be used.

local Selected = nil

Slab.BeginWindow('ListBox', {Title = "List Box", AutoSizeWindow = false})

Slab.BeginListBox('ListBoxExample')
for I = 1, 10, 1 do
	Slab.BeginListBoxItem('ListBoxExample_Item_' .. I, {Selected = Selected == I})
	Slab.Text("Item " .. I)

	if Slab.IsListBoxItemClicked() then
		Selected = I
	end

	Slab.EndListBoxItem()
end
Slab.EndListBox()

Slab.EndWindow()

API

Below is a list of function calls associated with the list box API.

BeginListBox

Begins the process of creating a list box. If this function is called, EndListBox must be called after all items have been added.

Parameter Type Description
Id String A string uniquely identifying this list box within the context of the current window.
Options Table List of options controlling the behavior of the list box.
Option Type Description
W Number The width of the list box. If nil, a default value of 150 is used.
H Number The height of the list box. If nil, a default value of 150 is used.
Clear Boolean Clears out the items in the list. It is recommended to only call this if the list items has changed and should not be set to true on every frame.
Rounding Number Amount of rounding to apply to the corners of the list box.
StretchW Boolean Stretch the list box to fill the remaining width of the window.
StretchH Boolean Stretch the list box to fill the remaining height of the window.

EndListBox

Ends the list box container. Will close off the region and properly adjust the cursor.

BeginListBoxItem

Adds an item to the current list box with the given Id. The user can then draw controls however they see fit to display a single item. This allows the user to draw list items such as a texture with a name or just a text to represent the item. If this is called, EndListBoxItem must be called to complete the item.

Parameter Type Description
Id String A string uniquely identifying this item within the context of the current list box.
Options Table List of options that control the behavior of the active list item.
Option Type Description
Selected Boolean If true, will draw the item with a selection background.

IsListBoxItemClicked

Checks to see if a hot list item is clicked. This should only be called within a BeginListBoxLitem/EndListBoxItem block.

Parameter Type Description
Button Number The button to check for the click of the item.
IsDoubleClick Boolean Check for double-click instead of single click.

EndListBoxItem

Ends the current item and commits the bounds of the item to the list.

Clone this wiki locally