Skip to content

DropDown

A collapsible selection menu that expands to show multiple options when clicked. Supports single and multi-selection modes, custom item styling, separators, and item callbacks.

Extends: List

Examples (Executable)

lua
local basalt = require("basalt")
local main = basalt.getMainFrame()

-- Create a styled dropdown menu
local dropdown = main:addDropDown()
:setPosition(5, 5)
:setSize(20, 1)  -- Height expands when opened
:setSelectedText("Select an option...")

-- Add items with different styles and callbacks
dropdown:setItems({
{
text = "Category A",
background = colors.blue,
foreground = colors.white
},
{ separator = true, text = "-" },  -- Add a separator
{
text = "Option 1",
callback = function(self)
-- Handle selection
basalt.LOGGER.debug("Selected Option 1")
end
},
{
text = "Option 2",
-- Custom colors when selected
selectedBackground = colors.green,
selectedForeground = colors.white
}
})

-- Listen for selections
dropdown:onChange(function(self, value)
basalt.LOGGER.debug("Selected:", value)
end)

basalt.run()

Table Types

ItemTable

PropertyTypeDescription
textstringThe display text for the item
callbackfunctionFunction called when selected
fgcolorNormal text color
bgcolorNormal background color
selectedFgcolorText color when selected
selectedBgcolorBackground when selected

Properties

PropertyTypeDefaultDescription
dropdownHeightnumber5Maximum visible items when expanded
selectedTextstring""Text shown when no selection made
dropSymbolstring"\31"Indicator for dropdown state

Released under the MIT License.