3.7 KiB
3.7 KiB
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 | Creates a new ComboBox instance |
| ComboBox:init | ComboBox | Initializes the ComboBox instance |
| ComboBox:setText | ComboBox | Sets the text content |
| ComboBox:getText | string | Gets the text content |
| ComboBox:setEditable | ComboBox | Sets editable state |
| ComboBox:getFilteredItems | - | Filters items for auto-complete |
| ComboBox:updateFilteredDropdown | - | Updates dropdown with filtered items |
| ComboBox:updateViewport | - | Updates the viewport |
| ComboBox:char | - | Handles character input |
| ComboBox:key | - | Handles key input |
| ComboBox:mouse_click | boolean | Handles mouse clicks |
| ComboBox:render | - | Renders the ComboBox |
| ComboBox:focus | - | Called when gaining focus |
| ComboBox:blur | - | Called when losing focus |
ComboBox.new()
Creates a new ComboBox instance
Returns
ComboBoxselfThe newly created ComboBox instance
ComboBox:init(props, basalt)
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
ComboBoxselfThe initialized instance
ComboBox:setText(text)
Sets the text content of the ComboBox
Parameters
textstringThe text to set
Returns
ComboBoxself
ComboBox:getText()
Gets the current text content
Returns
stringtextThe current text
ComboBox:setEditable(editable)
Sets whether the ComboBox is editable
Parameters
editablebooleanWhether the ComboBox should be editable
Returns
ComboBoxself
ComboBox:getFilteredItems()
Filters items based on current text for auto-complete
ComboBox:updateFilteredDropdown()
Updates the dropdown with filtered items
ComboBox:updateViewport()
ComboBox:char(char)
Handles character input when editable
Parameters
charstringThe character that was typed
ComboBox:key(key, held)
Handles key input when editable
Parameters
keynumberThe key code that was pressedheldbooleanWhether the key is being held
ComboBox:mouse_click(button, x, y)
Handles mouse clicks
Parameters
buttonnumberThe mouse button (1 = left, 2 = right, 3 = middle)xnumberThe x coordinate of the clickynumberThe y coordinate of the click
Returns
booleanhandledWhether the event was handled
ComboBox:render()
Renders the ComboBox
ComboBox:focus()
Called when the ComboBox gains focus
ComboBox:blur()
Called when the ComboBox loses focus