Skip to content

ComboBox

_A hybrid input element that combines a text input field with a dropdown list. Users can either type directly or select from predefined options. _ Supports auto-completion, custom styling, and both single and multi-selection modes.

Extends: DropDown

Usage

lua
-- Create a searchable country selector
local combo = main:addComboBox()
:setPosition(5, 5)
:setSize(20, 1)  -- Height will expand when opened
:setItems({
{text = "Germany"},
{text = "France"},
{text = "Spain"},
{text = "Italy"}
})
:setPlaceholder("Select country...")
:setAutoComplete(true)  -- Enable filtering while typing

-- Handle selection changes
combo:onChange(function(self, value)
-- value will be the selected country
basalt.debug("Selected:", value)
end)

Properties

PropertyTypeDefaultDescription
editablebooleantrueEnables direct text input in the field
textstring""The current text value of the input field
cursorPosnumber1Current cursor position in the text input
viewOffsetnumber0Horizontal scroll position for viewing long text
placeholderstring"..."Text shown when the input is empty
placeholderColorcolorgrayColor used for placeholder text
autoCompletebooleanfalseEnables filtering dropdown items while typing
manuallyOpenedbooleanfalseIndicates if dropdown was opened by user action

Functions

MethodReturnsDescription
ComboBox.newComboBoxCreates a new ComboBox instance
ComboBox:char-Handles character input
ComboBox:key-Handles key input

ComboBox.new()

Creates a new ComboBox instance

Returns

  • ComboBox self The newly created ComboBox instance

ComboBox:char(char)

Handles character input when editable

Parameters

  • char string The character that was typed

ComboBox:key(key, held)

Handles key input when editable

Parameters

  • key number The key code that was pressed
  • held boolean Whether the key is being held

Released under the MIT License.