Files
Basalt2/docs/references/elements/ComboBox.md
2025-09-14 10:34:44 +00:00

96 lines
2.6 KiB
Markdown

# ComboBox
_This is the ComboBox class. It extends the dropdown functionality with editable text input,_
_allowing users to either select from a list or type their own custom text._
Extends: `DropDown`
## Properties
|Property|Type|Default|Description|
|---|---|---|---|
|editable|boolean|true|Whether the ComboBox allows text input|
|text|string|""|The current text content of the ComboBox|
|cursorPos|number|1|The current cursor position in the text|
|viewOffset|number|0|The horizontal scroll offset for viewing long text|
|placeholder|string|"..."|Text to display when input is empty|
|placeholderColor|color|gray|Color of the placeholder text|
|focusedBackground|color|blue|Background color when ComboBox is focused|
|focusedForeground|color|white|Foreground color when ComboBox is focused |
|autoComplete|boolean|false|Whether to enable auto-complete filtering when typing|
|manuallyOpened|boolean|false|Whether the dropdown was manually opened (not by auto-complete)|
## Functions
|Method|Returns|Description|
|---|---|---|
|[ComboBox.new](#combobox-new)|ComboBox|Creates a new ComboBox instance|
|[ComboBox:setText](#combobox-settext-text)|ComboBox|Sets the text content|
|[ComboBox:getText](#combobox-gettext)|string|Gets the text content|
|[ComboBox:setEditable](#combobox-seteditable-editable)|ComboBox|Sets editable state|
|[ComboBox:char](#combobox-char-char)|-|Handles character input|
|[ComboBox:key](#combobox-key-key-held)|-|Handles key input|
|[ComboBox:render](#combobox-render)|-|Renders the ComboBox|
|[ComboBox:focus](#combobox-focus)|-|Called when gaining focus|
|[ComboBox:blur](#combobox-blur)|-|Called when losing focus|
## ComboBox.new()
Creates a new ComboBox instance
### Returns
* `ComboBox` `self` The newly created ComboBox instance
## ComboBox:setText(text)
Sets the text content of the ComboBox
### Parameters
* `text` `string` The text to set
### Returns
* `ComboBox` self
## ComboBox:getText()
Gets the current text content
### Returns
* `string` `text` The current text
## ComboBox:setEditable(editable)
Sets whether the ComboBox is editable
### Parameters
* `editable` `boolean` Whether the ComboBox should be editable
### Returns
* `ComboBox` self
## 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
## ComboBox:render()
Renders the ComboBox
## ComboBox:focus()
Called when the ComboBox gains focus
## ComboBox:blur()
Called when the ComboBox loses focus