VisualElement
This is the visual element class. It serves as the base class for all visual UI elementsand 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 |
| backgroundEnabled | boolean | true | Whether to render the background |
| borderTop | boolean | false | Draw top border |
| borderBottom | boolean | false | Draw bottom border |
| borderLeft | boolean | false | Draw left border |
| borderRight | boolean | false | Draw right border |
| borderColor | color | white | Border color |
| 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:setConstraint | VisualElement | Sets a constraint on a property relative to another element's property |
| VisualElement:resolveAllConstraints | VisualElement | Resolves all constraints for the element |
| VisualElement:removeConstraint | VisualElement | Removes a constraint from the element |
| VisualElement:updateConstraints | VisualElement | Updates all constraints, recalculating positions and sizes |
| VisualElement:alignRight | VisualElement | Aligns the element's right edge to the target's right edge with optional offset |
| VisualElement:alignLeft | VisualElement | Aligns the element's left edge to the target's left edge with optional offset |
| VisualElement:alignTop | VisualElement | Aligns the element's top edge to the target's top edge with optional offset |
| VisualElement:alignBottom | VisualElement | Aligns the element's bottom edge to the target's bottom edge with optional offset |
| VisualElement:centerHorizontal | VisualElement | Centers the element horizontally relative to the target with optional offset |
| VisualElement:centerVertical | VisualElement | Centers the element vertically relative to the target with optional offset |
| VisualElement:centerIn | VisualElement | Centers the element both horizontally and vertically relative to the target |
| VisualElement:rightOf | VisualElement | Positions the element to the right of the target with optional gap |
| VisualElement:leftOf | VisualElement | Positions the element to the left of the target with optional gap |
| VisualElement:below | VisualElement | Positions the element below the target with optional gap |
| VisualElement:above | VisualElement | Positions the element above the target with optional gap |
| VisualElement:stretchWidth | VisualElement | Stretches the element to match the target's width with optional margin |
| VisualElement:stretchHeight | VisualElement | Stretches the element to match the target's height with optional margin |
| VisualElement:stretch | VisualElement | Stretches the element to match the target's width and height with optional margin |
| VisualElement:widthPercent | VisualElement | Sets the element's width as a percentage of the target's width |
| VisualElement:heightPercent | VisualElement | Sets the element's height as a percentage of the target's height |
| VisualElement:matchWidth | VisualElement | Matches the element's width to the target's width with optional offset |
| VisualElement:matchHeight | VisualElement | Matches the element's height to the target's height with optional offset |
| VisualElement:fillParent | VisualElement | Stretches the element to fill its parent's width and height with optional margin |
| VisualElement:fillWidth | VisualElement | Stretches the element to fill its parent's width with optional margin |
| VisualElement:fillHeight | VisualElement | Stretches the element to fill its parent's height with optional margin |
| VisualElement:center | VisualElement | Centers the element within its parent both horizontally and vertically |
| VisualElement:toRight | VisualElement | Aligns the element's right edge to its parent's right edge with optional gap |
| VisualElement:toLeft | VisualElement | Aligns the element's left edge to its parent's left edge with optional gap |
| VisualElement:toTop | VisualElement | Aligns the element's top edge to its parent's top edge with optional gap |
| VisualElement:toBottom | VisualElement | Aligns the element's bottom edge to its parent's bottom edge with optional gap |
| VisualElement:isInBounds | boolean | Checks if point is within bounds |
| VisualElement:setFocused | VisualElement | Sets focus state |
| VisualElement:isFocused | boolean | Checks if element is focused |
| VisualElement:isFocused | boolean | Checks if element is focused |
| VisualElement:addBorder | VisualElement | Adds or updates a drawable character border around the element. The border will automatically adapt to size/background changes because the command reads current properties each render. |
| VisualElement:removeBorder | VisualElement | Removes the previously added border (if any) |
| VisualElement:calculatePosition | number, number | Calculates the position of the element |
| VisualElement:getAbsolutePosition | number, number | Returns the absolute position of the element |
| VisualElement:getRelativePosition | number, number | Returns the relative position of the element |
| VisualElement:prioritize | VisualElement | Prioritizes the element by moving it to the top of its parent's children |
VisualElement:setConstraint(property, targetElement, targetProperty, offset)
Sets a constraint on a property relative to another element's property
Parameters
propertystringThe property to constrain (x, y, width, height, left, right, top, bottom, centerX, centerY)targetElementBaseElement|stringThe target element or "parent"targetPropertystringThe target property to constrain to (left, right, top, bottom, centerX, centerY, width, height)offsetnumberThe offset to apply (negative = inside, positive = outside, fractional = percentage)
Returns
VisualElementselfThe element instance
VisualElement:resolveAllConstraints()
Resolves all constraints for the element
Returns
VisualElementselfThe element instance
VisualElement:removeConstraint(property)
Removes a constraint from the element
Parameters
propertystringThe property of the constraint to remove
Returns
VisualElementselfThe element instance
VisualElement:updateConstraints()
Updates all constraints, recalculating positions and sizes
Returns
VisualElementselfThe element instance
VisualElement:alignRight(target, offset?)
Aligns the element's right edge to the target's right edge with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberOffset from the edge (negative = inside, positive = outside, default: 0)
Returns
VisualElementself
VisualElement:alignLeft(target, offset?)
Aligns the element's left edge to the target's left edge with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberOffset from the edge (negative = inside, positive = outside, default: 0)
Returns
VisualElementself
VisualElement:alignTop(target, offset?)
Aligns the element's top edge to the target's top edge with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberOffset from the edge (negative = inside, positive = outside, default: 0)
Returns
VisualElementself
VisualElement:alignBottom(target, offset?)
Aligns the element's bottom edge to the target's bottom edge with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberOffset from the edge (negative = inside, positive = outside, default: 0)
Returns
VisualElementself
VisualElement:centerHorizontal(target, offset?)
Centers the element horizontally relative to the target with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberHorizontal offset from center (default: 0)
Returns
VisualElementself
VisualElement:centerVertical(target, offset?)
Centers the element vertically relative to the target with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberVertical offset from center (default: 0)
Returns
VisualElementself
VisualElement:centerIn(target)
Centers the element both horizontally and vertically relative to the target
Parameters
targetBaseElement|stringThe target element or "parent"
Returns
VisualElementself
VisualElement:rightOf(target, gap?)
Positions the element to the right of the target with optional gap
Parameters
targetBaseElement|stringThe target element or "parent"gap(optional)numberGap between elements (default: 0)
Returns
VisualElementself
VisualElement:leftOf(target, gap?)
Positions the element to the left of the target with optional gap
Parameters
targetBaseElement|stringThe target element or "parent"gap(optional)numberGap between elements (default: 0)
Returns
VisualElementself
VisualElement:below(target, gap?)
Positions the element below the target with optional gap
Parameters
targetBaseElement|stringThe target element or "parent"gap(optional)numberGap between elements (default: 0)
Returns
VisualElementself
VisualElement:above(target, gap?)
Positions the element above the target with optional gap
Parameters
targetBaseElement|stringThe target element or "parent"gap(optional)numberGap between elements (default: 0)
Returns
VisualElementself
VisualElement:stretchWidth(target, margin?)
Stretches the element to match the target's width with optional margin
Parameters
targetBaseElement|stringThe target element or "parent"margin(optional)numberMargin on each side (default: 0)
Returns
VisualElementself
VisualElement:stretchHeight(target, margin?)
Stretches the element to match the target's height with optional margin
Parameters
targetBaseElement|stringThe target element or "parent"margin(optional)numberMargin on top and bottom (default: 0)
Returns
VisualElementself
VisualElement:stretch(target, margin?)
Stretches the element to match the target's width and height with optional margin
Parameters
targetBaseElement|stringThe target element or "parent"margin(optional)numberMargin on all sides (default: 0)
Returns
VisualElementself
VisualElement:widthPercent(target, percent)
Sets the element's width as a percentage of the target's width
Parameters
targetBaseElement|stringThe target element or "parent"percentnumberPercentage of target's width (0-100)
Returns
VisualElementself
VisualElement:heightPercent(target, percent)
Sets the element's height as a percentage of the target's height
Parameters
targetBaseElement|stringThe target element or "parent"percentnumberPercentage of target's height (0-100)
Returns
VisualElementself
VisualElement:matchWidth(target, offset?)
Matches the element's width to the target's width with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberOffset to add to target's width (default: 0)
Returns
VisualElementself
VisualElement:matchHeight(target, offset?)
Matches the element's height to the target's height with optional offset
Parameters
targetBaseElement|stringThe target element or "parent"offset(optional)numberOffset to add to target's height (default: 0)
Returns
VisualElementself
VisualElement:fillParent(margin?)
Stretches the element to fill its parent's width and height with optional margin
Parameters
margin(optional)numberMargin on all sides (default: 0)
Returns
VisualElementself
VisualElement:fillWidth(margin?)
Stretches the element to fill its parent's width with optional margin
Parameters
margin(optional)numberMargin on left and right (default: 0)
Returns
VisualElementself
VisualElement:fillHeight(margin?)
Stretches the element to fill its parent's height with optional margin
Parameters
margin(optional)numberMargin on top and bottom (default: 0)
Returns
VisualElementself
VisualElement:center()
Centers the element within its parent both horizontally and vertically
Returns
VisualElementself
VisualElement:toRight(gap?)
Aligns the element's right edge to its parent's right edge with optional gap
Parameters
gap(optional)numberGap from the edge (default: 0)
Returns
VisualElementself
VisualElement:toLeft(gap?)
Aligns the element's left edge to its parent's left edge with optional gap
Parameters
gap(optional)numberGap from the edge (default: 0)
Returns
VisualElementself
VisualElement:toTop(gap?)
Aligns the element's top edge to its parent's top edge with optional gap
Parameters
gap(optional)numberGap from the edge (default: 0)
Returns
VisualElementself
VisualElement:toBottom(gap?)
Aligns the element's bottom edge to its parent's bottom edge with optional gap
Parameters
gap(optional)numberGap from the edge (default: 0)
Returns
VisualElementself
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:setFocused(focused, internal?)
Sets or removes focus from this element
Parameters
focusedbooleanWhether to focus or blurinternal(optional)booleanInternal flag to prevent parent notification
Returns
VisualElementself
VisualElement:isFocused()
Gets whether this element is focused
Returns
booleanisFocused
VisualElement:isFocused()
Gets whether this element is focused
Returns
booleanisFocused
VisualElement:addBorder(colorOrOptions, sideOptions?)
Adds or updates a drawable character border around the element. The border will automatically adapt to size/background changes because the command reads current properties each render.
Parameters
colorOrOptionsanyBorder color or options tablesideOptions(optional)tableSide options table (if color is provided as first argument)
Returns
VisualElementself
VisualElement:removeBorder()
Removes the previously added border (if any)
Returns
VisualElementself
VisualElement:calculatePosition()
Calculates the position of the element relative to its parent
Returns
numberxThe x positionnumberyThe y position
VisualElement:getAbsolutePosition(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:getRelativePosition(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:prioritize()
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