3.3 KiB
3.3 KiB
TextBox : VisualElement
A multi-line text editor component with cursor support and text manipulation features
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| lines | table | {} | Array of text lines |
| cursorX | number | 1 | Cursor X position |
| cursorY | number | 1 | Cursor Y position (line number) |
| scrollX | number | 0 | Horizontal scroll offset |
| scrollY | number | 0 | Vertical scroll offset |
| editable | boolean | true | Whether text can be edited |
| syntaxPatterns | table | {} | Syntax highlighting patterns |
| cursorColor | number | nil | Color of the cursor |
Functions
| Method | Returns | Description |
|---|---|---|
| TextBox.new | TextBox | Creates a new TextBox instance |
| TextBox:addSyntaxPattern | - | Adds a new syntax highlighting pattern |
| TextBox:char | boolean | Handles character input |
| TextBox:getText | string | Gets the text of the TextBox |
| TextBox:init | TextBox | Initializes the TextBox instance |
| TextBox:key | boolean | Handles key events |
| TextBox:mouse_click | boolean | Handles mouse click events |
| TextBox:mouse_scroll | boolean | Handles mouse scroll events |
| TextBox:render | - | Renders the TextBox with syntax highlighting |
| TextBox:setText | TextBox | Sets the text of the TextBox |
| TextBox:updateViewport | TextBox | Updates the viewport to keep the cursor in view |
TextBox.new()
Creates a new TextBox instance
Returns
TextBoxselfThe newly created TextBox instance
TextBox:addSyntaxPattern(pattern, color)
Adds a new syntax highlighting pattern
Parameters
patternstringThe regex pattern to matchcolorcolorsThe color to apply
TextBox:char(char)
Handles character input
Parameters
charstringThe character that was typed
Returns
booleanhandledWhether the event was handled
TextBox:getText()
Gets the text of the TextBox
Returns
stringtextThe text of the TextBox
TextBox:init(props, basalt)
Initializes the TextBox instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
TextBoxselfThe initialized instance
TextBox:key(key)
Handles key events
Parameters
keynumberThe key that was pressed
Returns
booleanhandledWhether the event was handled
TextBox: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
TextBox:mouse_scroll(direction, x, y)
Handles mouse scroll events
Parameters
directionnumberThe scroll directionxnumberThe x position of the scrollynumberThe y position of the scroll
Returns
booleanhandledWhether the event was handled
TextBox:render()
Renders the TextBox
TextBox:setText(text)
Sets the text of the TextBox
Parameters
textstringThe text to set
Returns
TextBoxselfThe TextBox instance
TextBox:updateViewport()
Updates the viewport to keep the cursor in view
Returns
TextBoxselfThe TextBox instance