8.7 KiB
8.7 KiB
VisualElement
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.
Extends: BaseElement
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 |
Events
| Event | Parameters | Description |
|---|---|---|
| onClick | button string, x number, y number |
Fired on mouse click |
Functions
| Method | Returns | Description |
|---|---|---|
| VisualElement.new | VisualElement | Creates a new visual element |
| VisualElement:VisualElement | - | Initializes a new visual element with properties |
| VisualElement:VisualElement | - | Multi-character drawing with colors |
| VisualElement:VisualElement | - | Draws text with foreground color |
| VisualElement:VisualElement | - | Draws text with background color |
| VisualElement:VisualElement | - | Draws text with both colors |
| VisualElement:VisualElement | boolean | Checks if point is within bounds |
| VisualElement:VisualElement | boolean | Handles a mouse click event |
| VisualElement:VisualElement | boolean | Handles a mouse up event |
| VisualElement:VisualElement | - | Handles a mouse release event |
| VisualElement:VisualElement | boolean | Handles a mouse move event |
| VisualElement:VisualElement | boolean | Handles a mouse scroll event |
| VisualElement:VisualElement | boolean | Handles a mouse drag event |
| VisualElement:VisualElement | - | Handles a focus event |
| VisualElement:VisualElement | - | Handles a blur event |
| VisualElement:VisualElement | - | Handles a key event |
| VisualElement:VisualElement | - | Handles a key up event |
| VisualElement:VisualElement | - | Handles a character event |
| VisualElement:VisualElement | number, number | Calculates the position of the element |
| VisualElement:VisualElement | number, number | Returns the absolute position of the element |
| VisualElement:VisualElement | number, number | Returns the relative position of the element |
| VisualElement:VisualElement | VisualElement | Sets the cursor position |
| VisualElement:VisualElement | VisualElement | Prioritizes the element by moving it to the top of its parent's children |
| VisualElement:VisualElement | - | Renders the element |
| VisualElement:VisualElement | - | Post-rendering function for the element |
VisualElement.new()
Creates a new VisualElement instance
Returns
VisualElementobjectThe newly created VisualElement instance
VisualElement:VisualElement(props, basalt)
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
VisualElement:VisualElement(x, y, width, height, text, fg, bg)
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:VisualElement(x, y, text, fg)
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawfgcolorThe foreground color
VisualElement:VisualElement(x, y, text, bg)
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawbgcolorThe background color
VisualElement:VisualElement(x, y, text, fg, bg)
Parameters
xnumberThe x position to drawynumberThe y position to drawtextstringThe text char to drawfgstringThe foreground colorbgstringThe background color
VisualElement:VisualElement(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:VisualElement(button, x, y)
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanclickedWhether the element was clicked
VisualElement:VisualElement(button, x, y)
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:VisualElement(button, x, y)
Parameters
buttonnumberThe button that was releasedxnumberThe x position of the releaseynumberThe y position of the release
VisualElement:VisualElement(_, x, y)
Parameters
_numberunknownxnumberThe x position of the mouseynumberThe y position of the mouse
Returns
booleanhoverWhether the mouse has moved over the element
VisualElement:VisualElement(direction, x, y)
Parameters
directionnumberThe scroll directionxnumberThe x position of the scrollynumberThe y position of the scroll
Returns
booleanscrollWhether the element was scrolled
VisualElement:VisualElement(button, x, y)
Parameters
buttonnumberThe button that was clicked while draggingxnumberThe x position of the dragynumberThe y position of the drag
Returns
booleandragWhether the element was dragged
VisualElement:VisualElement()
VisualElement:VisualElement()
VisualElement:VisualElement(key)
Parameters
keynumberThe key that was pressed
VisualElement:VisualElement(key)
Parameters
keynumberThe key that was released
VisualElement:VisualElement(char)
Parameters
charstringThe character that was pressed
VisualElement:VisualElement()
Calculates the position of the element relative to its parent
Returns
numberxThe x positionnumberyThe y position
VisualElement:VisualElement(x?, y?)
Returns the absolute position of the element or the given coordinates.
Parameters
x(optional)numberx positiony(optional)numbery position
Returns
numberxThe absolute x positionnumberyThe absolute y position
VisualElement:VisualElement(x?, y?)
Returns the relative position of the element or the given coordinates.
Parameters
x(optional)numberx positiony(optional)numbery position
Returns
numberxThe relative x positionnumberyThe relative y position
VisualElement:VisualElement(x, y, blink, color)
Parameters
xnumberThe x position of the cursorynumberThe y position of the cursorblinkbooleanWhether the cursor should blinkcolornumberThe color of the cursor
Returns
VisualElementselfThe VisualElement instance
VisualElement:VisualElement()
This function is used to prioritize the element by moving it to the top of its parent's children. It removes the element from its parent and adds it back, effectively changing its order.
Returns
VisualElementselfThe VisualElement instance