Skip to content

List : VisualElement

This is the list class. It provides a scrollable list of selectable items with support for custom item rendering, separators, and selection handling.

Properties

PropertyTypeDefaultDescription
itemstable{}List of items to display. Items can be tables with properties including selected state
selectablebooleantrueWhether items in the list can be selected
multiSelectionbooleanfalseWhether multiple items can be selected at once
offsetnumber0Current scroll offset for viewing long lists
selectedBackgroundcolorblueBackground color for selected items
selectedForegroundcolorwhiteText color for selected items

Events

EventParametersDescription
onSelectindex number, item tableFired when an item is selected

Functions

MethodReturnsDescription
List:addItemListAdds an item to the list
List:clearListClears all items from the list
List:getSelectedItemtable?Gets first selected item
List:getSelectedItemstableGets the currently selected items
List:onSelectListRegisters a callback for the select event
List:removeItemListRemoves an item from the list
List:scrollToBottomListScrolls the list to the bottom
List:scrollToTopListScrolls the list to the top

Protected Functions

MethodReturnsDescription
List:initListInitializes the List instance
List:mouse_clickbooleanHandles mouse click events
List:mouse_scrollbooleanHandles mouse scroll events
List:render-Renders the list

List:addItem(text)

Adds an item to the list

Parameters

  • text string|table The item to add (string or item table)

Returns

  • List self The List instance

Usage

lua
list:addItem("New Item")
list:addItem({text="Item", callback=function() end})
list:addItem("New Item")
list:addItem({text="Item", callback=function() end})

List:clear()

Clears all items from the list

Returns

  • List self The List instance

Usage

lua
list:clear()
list:clear()

List:getSelectedItem()

Gets first selected item

Returns

  • table? selected The first item

List:getSelectedItems()

Gets the currently selected items

Returns

  • table selected List of selected items

Usage

lua
local selected = list:getSelectedItems()
local selected = list:getSelectedItems()

List:onSelect(callback)

Registers a callback for the select event

Parameters

  • callback function The callback function to register

Returns

  • List self The List instance

Usage

lua
list:onSelect(function(index, item) print("Selected item:", index, item) end)
list:onSelect(function(index, item) print("Selected item:", index, item) end)

List:removeItem(index)

Removes an item from the list

Parameters

  • index number The index of the item to remove

Returns

  • List self The List instance

Usage

lua
list:removeItem(1)
list:removeItem(1)

List:scrollToBottom()

Scrolls the list to the bottom

Returns

  • List self The List instance

List:scrollToTop()

Scrolls the list to the top

Returns

  • List self The List instance

Released under the MIT License.