5.7 KiB
5.7 KiB
VisualElement : BaseElement
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| x | number | 1 | x position of the element |
| y | number | 1 | y position of the element |
| z | number | 1 | z position of the element |
| width | number | 1 | width of the element |
| height | number | 1 | height of the element |
| background | color | black | background color of the element |
| foreground | color | white | foreground color of the element |
| clicked | boolean | an | false element is currently clicked |
| backgroundEnabled | boolean | true | whether the background is enabled |
| focused | boolean | false | whether the element is focused |
| visible | boolean | true | whether the element is visible |
Combined Properties
| Name | Properties | Description |
|---|---|---|
| position | {x | y} |
| size | {width | height} |
| color | {foreground | background} |
Events
| Event | Parameters | Description |
|---|---|---|
| onMouseClick | button number, x number, y number |
Fired when the element is clicked |
| onMouseUp | button number, x number, y number |
Fired when the mouse is released |
| onMouseRelease | button number, x number, y number |
Fired when the mouse is released |
| onMouseDrag | button number, x number, y number |
Fired when the mouse is dragged |
| onFocus | - |
Fired when the element is focused |
| onBlur | - |
Fired when the element is blurred |
| onKey | key number, code number, isRepeat boolean |
Fired when a key is pressed |
| onKeyUp | key number, code number |
Fired when a key is released |
| onChar | char string |
Fired when a key is pressed |
Functions
| Method | Returns | Description |
|---|---|---|
| VisualElement.new | VisualElement | |
| VisualElement:blit | - | |
| VisualElement:blur | - | |
| VisualElement:focus | - | |
| VisualElement:getAbsolutePosition | - | |
| VisualElement:getRelativePosition | number, | |
| VisualElement:init | - | |
| VisualElement:isInBounds | boolean | |
| VisualElement:mouse_click | boolean | |
| VisualElement:mouse_release | boolean | |
| VisualElement:mouse_up | boolean | |
| VisualElement:render | - | |
| VisualElement:setCursor | - | |
| VisualElement:textBg | - | |
| VisualElement:textFg | - |
VisualElement.new(props, basalt)
Creates a new VisualElement instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
VisualElementobjectThe newly created VisualElement instance
Usage
local element = VisualElement.new("myId", basalt)
VisualElement:blit(x, y, text, fg, bg)
Draws a text character with a foreground and background at the specified position, used in the rendering system
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawfgstringThe foreground colorbgstringThe background color
VisualElement:blur()
Handles a blur event
VisualElement:focus()
Handles a focus event
VisualElement:getAbsolutePosition(x?, y?)
Returns the absolute position of the element or the given coordinates.
Parameters
x(optional)numberx positiony(optional)numbery position
VisualElement:getRelativePosition(x?, y?)
Returns the relative position of the element or the given coordinates.
Parameters
x(optional)numberx positiony(optional)numbery position
Returns
nilnilnil
VisualElement:init()
Initializes the VisualElement instance
VisualElement:isInBounds(x, y)
Checks if the specified coordinates are within the bounds of the element
Parameters
xnumberThe x position to checkynumberThe y position to check
Returns
booleanisInBoundsWhether the coordinates are within the bounds of the element
VisualElement:mouse_click(button, x, y)
Handles a mouse click event
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanclickedWhether the element was clicked
VisualElement:mouse_release(button, x, y)
Handles a mouse release event
Parameters
buttonnumberThe button that was releasedxnumberThe x position of the releaseynumberThe y position of the release
Returns
booleanreleaseWhether the element was released on the element
VisualElement:mouse_up(button, x, y)
Handles a mouse up event
Parameters
buttonnumberThe button that was releasedxnumberThe x position of the releaseynumberThe y position of the release
Returns
booleanreleaseWhether the element was released on the element
VisualElement:render()
Renders the element
VisualElement:setCursor(x, y, blink)
Sets the cursor position
Parameters
xnumberThe x position of the cursorynumberThe y position of the cursorblinkbooleanWhether the cursor should blink
VisualElement:textBg(x, y, text, bg)
Draws a text character with a background at the specified position, used in the rendering system
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawbgcolorThe background color
VisualElement:textFg(x, y, text, fg)
Draws a text character at the specified position, used in the rendering system
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawfgcolorThe foreground color