Skip to content

Collection ​

This is the Collection class. It provides a collection of items

Extends: VisualElement

Properties ​

PropertyTypeDefaultDescription
itemstable{}Collection of items in the collection.
selectablebooleantrueWhether items can be selected
multiSelectionbooleanfalseWhether multiple items can be selected at once
selectedBackgroundcolorblueBackground color for selected items
selectedForegroundcolorwhiteText color for selected items

Events ​

EventParametersDescription
onSelectindex number, item tableFired when an item is selected

Functions ​

MethodReturnsDescription
Collection:addItemCollectionAdds an item to the Collection
Collection:removeItemCollectionRemoves an item from the Collection
Collection:clearCollectionClears all items from the Collection
Collection:getSelectedItemstableGets the currently selected items
Collection:getSelectedItemselectedGets first selected item
Collection:getSelectedIndexindexGets the index of the first selected item
Collection:selectNextCollectionSelects the next item
Collection:selectPreviousCollectionSelects the previous item
Collection:onSelectCollectionRegisters a callback for the select event

Collection:addItem(text) ​

Adds an item to the Collection

Parameters ​

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

Returns ​

  • Collection self The Collection instance

Usage ​

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

Collection:removeItem(index) ​

Removes an item from the Collection

Parameters ​

  • index number The index of the item to remove

Returns ​

  • Collection self The Collection instance

Usage ​

lua
Collection:removeItem(1)

Collection:clear() ​

Clears all items from the Collection

Returns ​

  • Collection self The Collection instance

Usage ​

lua
Collection:clear()

Collection:getSelectedItems() ​

Gets the currently selected items

Returns ​

  • table selected Collection of selected items

Usage ​

lua
local selected = Collection:getSelectedItems()

Collection:getSelectedItem() ​

Gets first selected item

Returns ​

  • selected The first item

Collection:getSelectedIndex() ​

Gets the index of the first selected item

Returns ​

  • index The index of the first selected item, or nil if none selected

Usage ​

lua
local index = Collection:getSelectedIndex()

Collection:selectNext() ​

Selects the next item in the collection

Returns ​

  • Collection self The Collection instance

Collection:selectPrevious() ​

Selects the previous item in the collection

Returns ​

  • Collection self The Collection instance

Collection:onSelect(callback) ​

Registers a callback for the select event

Parameters ​

  • callback function The callback function to register

Returns ​

  • Collection self The Collection instance

Usage ​

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

Released under the MIT License.