2.6 KiB
2.6 KiB
Input : VisualElement
This is the input class. It provides a text input field that can handle user input with various features like cursor movement, text manipulation, placeholder text, and input validation.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| text | string | - | The current text content of the input |
| cursorPos | number | 1 | The current cursor position in the text |
| viewOffset | number | 0 | The horizontal scroll offset for viewing long text |
| maxLength | number? | nil | Maximum length of input text (optional) |
| placeholder | string | ... | Text to display when input is empty |
| placeholderColor | color | gray | Color of the placeholder text |
| focusedColor | color | blue | Background color when input is focused |
| pattern | string? | nil | Regular expression pattern for input validation |
| cursorColor | number | nil | Color of the cursor |
Functions
| Method | Returns | Description |
|---|---|---|
| Input.new | Input | Creates a new Input instance |
| Input:blur | - | Handles blur events |
| Input:char | boolean | Handles char events |
| Input:focus | - | Handles focus events |
| Input:init | Input | Initializes the Input instance |
| Input:key | boolean | Handles key events |
| Input:mouse_click | boolean | Handles mouse click events |
| Input:render | - | Renders the input element |
| Input:updateViewport | - | Updates the input's viewport |
Input.new()
Creates a new Input instance
Returns
InputobjectThe newly created Input instance
Usage
local element = Input.new("myId", basalt)
Input:blur()
Handles blur events
Input:char(char)
Handles char events
Parameters
charstringThe character that was typed
Returns
booleanhandledWhether the event was handled
Input:focus()
Handles focus events
Input:init(props, basalt)
Initializes the Input instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
InputselfThe initialized instance
Input:key(key)
Handles key events
Parameters
keynumberThe key that was pressed
Returns
booleanhandledWhether the event was handled
Input:mouse_click(button, x, y)
Handles mouse click events
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Input:render()
Renders the input element
Input:updateViewport()
Updates the input's viewport