7.2 KiB
VisualElement : BaseElement
This is the visual element class. It serves as the base class for all visual UI elements and provides core functionality for positioning, sizing, colors, and rendering.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| x | number | 1 | The horizontal position relative to parent |
| y | number | 1 | The vertical position relative to parent |
| z | number | 1 | The z-index for layering elements |
| width | number | 1 | The width of the element |
| height | number | 1 | The height of the element |
| background | color | black | The background color |
| foreground | color | white | The text/foreground color |
| clicked | boolean | false | Whether the element is currently clicked |
| hover | boolean | false | Whether the mouse is currently hover over the element (Craftos-PC only) |
| backgroundEnabled | boolean | true | Whether to render the background |
| focused | boolean | false | Whether the element has input focus |
| visible | boolean | true | Whether the element is visible |
| ignoreOffset | boolean | false | Whether to ignore the parent's offset |
Combined Properties
| Name | Properties | Description |
|---|---|---|
| position | x y |
Combined x, y position |
| size | width height |
Combined width, height |
| color | foreground background |
Combined foreground, background colors |
Events
| Event | Parameters | Description |
|---|---|---|
| onClick | button, x, y |
Fired on mouse click |
| onMouseUp | button, x, y |
Fired on mouse button release |
| onRelease | button, x, y |
Fired when mouse leaves while clicked |
| onDrag | button, x, y |
Fired when mouse moves while clicked |
| onScroll | direction, x, y |
Fired on mouse scroll |
| onEnter | - |
Fired when mouse enters element |
| onLeave | - |
Fired when mouse leaves element |
| onFocus | - |
Fired when element receives focus |
| onBlur | - |
Fired when element loses focus |
| onKey | key |
Fired on key press |
| onKeyUp | key |
Fired on key release |
| onChar | char |
Fired on character input |
Functions
| Method | Returns | Description |
|---|---|---|
| VisualElement.new | VisualElement | Creates a new visual element |
| VisualElement:blit | - | Draws text with both colors |
| VisualElement:blur | - | Handles a blur event |
| VisualElement:calculatePosition | - | |
| VisualElement:focus | - | Handles a focus event |
| VisualElement:getAbsolutePosition | - | Returns the absolute position of the element |
| VisualElement:getRelativePosition | number, | Returns the relative position of the element |
| VisualElement:init | - | Initializes a new visual element with properties |
| VisualElement:isInBounds | boolean | Checks if point is within bounds |
| VisualElement:mouse_click | boolean | Handles a mouse click event |
| VisualElement:mouse_drag | - | |
| VisualElement:mouse_move | - | |
| VisualElement:mouse_release | - | Handles a mouse release event |
| VisualElement:mouse_scroll | - | |
| VisualElement:mouse_up | boolean | Handles a mouse up event |
| VisualElement:multiBlit | - | Multi-character drawing with colors |
| VisualElement:render | - | Renders the element |
| VisualElement:setCursor | - | Sets the cursor position |
| VisualElement:textBg | - | Draws text with background color |
| VisualElement:textFg | - | Draws text with foreground color |
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 text with both foreground and background colors
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:calculatePosition()
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(props, basalt)
Initializes the VisualElement instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt 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_drag()
VisualElement:mouse_move()
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
VisualElement:mouse_scroll()
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:multiBlit(x, y, width, height, text, fg, bg)
Draws multiple characters at once with colors
Parameters
xnumberThe x position to drawynumberThe y position to drawwidthnumberThe width of the area to drawheightnumberThe height of the area to drawtextstringThe text to drawfgstringThe foreground colorbgstringThe background color
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 text with background color
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawbgcolorThe background color
VisualElement:textFg(x, y, text, fg)
Draws text with foreground color
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawfgcolorThe foreground color