List
_This is the list class. It provides a scrollable list of selectable items with support for _ custom item rendering, separators, and selection handling.
Extends: VisualElement
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| items | table | {} | List of items to display. Items can be tables with properties including selected state |
| selectable | boolean | true | Whether items in the list can be selected |
| multiSelection | boolean | false | Whether multiple items can be selected at once |
| offset | number | 0 | Current scroll offset for viewing long lists |
| selectedBackground | color | blue | Background color for selected items |
| selectedForeground | color | white | Text color for selected items |
Events
| Event | Parameters | Description |
|---|---|---|
| onSelect | index number, item table | Fired when an item is selected |
Functions
| Method | Returns | Description |
|---|---|---|
| List:addItem | List | Adds an item to the list |
| List:removeItem | List | Removes an item from the list |
| List:clear | List | Clears all items from the list |
| List:getSelectedItems | table | Gets the currently selected items |
| List:getSelectedItem | selected | Gets first selected item |
| List:onSelect | List | Registers a callback for the select event |
| List:scrollToBottom | List | Scrolls the list to the bottom |
| List:scrollToTop | List | Scrolls the list to the top |
List:addItem(text)
Adds an item to the list
Parameters
textstring|tableThe item to add (string or item table)
Returns
ListselfThe List instance
Usage
lua
list:addItem("New Item")
list:addItem({text="Item", callback=function() end})List:removeItem(index)
Removes an item from the list
Parameters
indexnumberThe index of the item to remove
Returns
ListselfThe List instance
Usage
lua
list:removeItem(1)List:clear()
Clears all items from the list
Returns
ListselfThe List instance
Usage
lua
list:clear()List:getSelectedItems()
Gets the currently selected items
Returns
tableselectedList of selected items
Usage
lua
local selected = list:getSelectedItems()List:getSelectedItem()
Gets first selected item
Returns
selectedThefirst item
List:onSelect(callback)
Registers a callback for the select event
Parameters
callbackfunctionThe callback function to register
Returns
ListselfThe List instance
Usage
lua
list:onSelect(function(index, item) print("Selected item:", index, item) end)List:scrollToBottom()
Scrolls the list to the bottom
Returns
ListselfThe List instance
List:scrollToTop()
Scrolls the list to the top
Returns
ListselfThe List instance