import{_ as s,c as i,o as a,a4 as t}from"./chunks/framework.nQaBHiNx.js";const y=JSON.parse('{"title":"List","description":"","frontmatter":{"outline":"deep"},"headers":[],"relativePath":"references/list.md","filePath":"references/list.md","lastUpdated":null}'),e={name:"references/list.md"},h=t(`
Lists are objects that allow you to create a collection of entries from which the user can make a selection.
| Property | Type | Description |
|---|---|---|
| items | table | A collection of entries to be displayed in the list |
| selectedIndex | number | he index of the currently selected item in the list |
| selectionBackground | color | Background color of the selected item |
| selectionForeground | color | Foreground/text color of the selected item |
| scrollIndex | number | Indicates the first visible item in a scrollable list |
Here's an example showcasing how to create a List object, populate it with items, and retrieve the selected item:
local main = basalt.addFrame()
local myList = main:addList()
-- Adding items to the list
myList:setItems({"Item 1", "Item 2", "Item 3", "Item 4"})
-- Retrieving the selected item's value
local selectedItem = myList.items[myList.selectedIndex]
basalt.debug(selectedItem)Adds a item into the list.
string The entry nameobject The object in uselocal mainFrame = basalt.addFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry")
aList:addItem("3. Entry")Removes an item from the list
string The name of the itemobject The object in uselocal mainFrame = basalt.addFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry")
aList:addItem("3. Entry")
aList:removeItem("2. Entry")Removes an item from the list by its id
number The id of the itemobject The object in uselocal mainFrame = basalt.addFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry")
aList:addItem("3. Entry")
aList:removeItemByIndex(2)Selects an item from the list
string The name of the itemobject The object in uselocal mainFrame = basalt.addFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry")
aList:addItem("3. Entry")
aList:selectItem("2. Entry")Selects an item from the list by its id
number The id of the itemobject The object in uselocal mainFrame = basalt.addFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry")
aList:addItem("3. Entry")
aList:selectItemByIndex(2)Returns the currently selected item
string The name of the itemlocal mainFrame = basalt.addFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry")
aList:addItem("3. Entry")
basalt.debug(aList:getSelectedItem())