Skip to content

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

PropertyTypeDefaultDescription
xnumber1The horizontal position relative to parent
ynumber1The vertical position relative to parent
znumber1The z-index for layering elements
widthnumber1The width of the element
heightnumber1The height of the element
backgroundcolorblackThe background color
foregroundcolorwhiteThe text/foreground color
backgroundEnabledbooleantrueWhether to render the background
borderTopbooleanfalseDraw top border
borderBottombooleanfalseDraw bottom border
borderLeftbooleanfalseDraw left border
borderRightbooleanfalseDraw right border
borderColorcolorwhiteBorder color
visiblebooleantrueWhether the element is visible
ignoreOffsetbooleanfalseWhether to ignore the parent's offset

Events

EventParametersDescription
onClickbutton string, x number, y numberFired on mouse click

Functions

MethodReturnsDescription
VisualElement:setConstraintVisualElementSets a constraint on a property relative to another element's property
VisualElement:resolveAllConstraintsVisualElementResolves all constraints for the element
VisualElement:removeConstraintVisualElementRemoves a constraint from the element
VisualElement:updateConstraintsVisualElementUpdates all constraints, recalculating positions and sizes
VisualElement:alignRightVisualElementAligns the element's right edge to the target's right edge with optional offset
VisualElement:alignLeftVisualElementAligns the element's left edge to the target's left edge with optional offset
VisualElement:alignTopVisualElementAligns the element's top edge to the target's top edge with optional offset
VisualElement:alignBottomVisualElementAligns the element's bottom edge to the target's bottom edge with optional offset
VisualElement:centerHorizontalVisualElementCenters the element horizontally relative to the target with optional offset
VisualElement:centerVerticalVisualElementCenters the element vertically relative to the target with optional offset
VisualElement:centerInVisualElementCenters the element both horizontally and vertically relative to the target
VisualElement:rightOfVisualElementPositions the element to the right of the target with optional gap
VisualElement:leftOfVisualElementPositions the element to the left of the target with optional gap
VisualElement:belowVisualElementPositions the element below the target with optional gap
VisualElement:aboveVisualElementPositions the element above the target with optional gap
VisualElement:stretchWidthVisualElementStretches the element to match the target's width with optional margin
VisualElement:stretchHeightVisualElementStretches the element to match the target's height with optional margin
VisualElement:stretchVisualElementStretches the element to match the target's width and height with optional margin
VisualElement:widthPercentVisualElementSets the element's width as a percentage of the target's width
VisualElement:heightPercentVisualElementSets the element's height as a percentage of the target's height
VisualElement:matchWidthVisualElementMatches the element's width to the target's width with optional offset
VisualElement:matchHeightVisualElementMatches the element's height to the target's height with optional offset
VisualElement:fillParentVisualElementStretches the element to fill its parent's width and height with optional margin
VisualElement:fillWidthVisualElementStretches the element to fill its parent's width with optional margin
VisualElement:fillHeightVisualElementStretches the element to fill its parent's height with optional margin
VisualElement:centerVisualElementCenters the element within its parent both horizontally and vertically
VisualElement:toRightVisualElementAligns the element's right edge to its parent's right edge with optional gap
VisualElement:toLeftVisualElementAligns the element's left edge to its parent's left edge with optional gap
VisualElement:toTopVisualElementAligns the element's top edge to its parent's top edge with optional gap
VisualElement:toBottomVisualElementAligns the element's bottom edge to its parent's bottom edge with optional gap
VisualElement:isInBoundsbooleanChecks if point is within bounds
VisualElement:setFocusedVisualElementSets focus state
VisualElement:isFocusedbooleanChecks if element is focused
VisualElement:isFocusedbooleanChecks if element is focused
VisualElement:addBorderVisualElementAdds 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:removeBorderVisualElementRemoves the previously added border (if any)
VisualElement:calculatePositionnumber, numberCalculates the position of the element
VisualElement:getAbsolutePositionnumber, numberReturns the absolute position of the element
VisualElement:getRelativePositionnumber, numberReturns the relative position of the element
VisualElement:prioritizeVisualElementPrioritizes 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

  • property string The property to constrain (x, y, width, height, left, right, top, bottom, centerX, centerY)
  • targetElement BaseElement|string The target element or "parent"
  • targetProperty string The target property to constrain to (left, right, top, bottom, centerX, centerY, width, height)
  • offset number The offset to apply (negative = inside, positive = outside, fractional = percentage)

Returns

  • VisualElement self The element instance

VisualElement:resolveAllConstraints()

Resolves all constraints for the element

Returns

  • VisualElement self The element instance

VisualElement:removeConstraint(property)

Removes a constraint from the element

Parameters

  • property string The property of the constraint to remove

Returns

  • VisualElement self The element instance

VisualElement:updateConstraints()

Updates all constraints, recalculating positions and sizes

Returns

  • VisualElement self The element instance

VisualElement:alignRight(target, offset?)

Aligns the element's right edge to the target's right edge with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Offset from the edge (negative = inside, positive = outside, default: 0)

Returns

  • VisualElement self

VisualElement:alignLeft(target, offset?)

Aligns the element's left edge to the target's left edge with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Offset from the edge (negative = inside, positive = outside, default: 0)

Returns

  • VisualElement self

VisualElement:alignTop(target, offset?)

Aligns the element's top edge to the target's top edge with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Offset from the edge (negative = inside, positive = outside, default: 0)

Returns

  • VisualElement self

VisualElement:alignBottom(target, offset?)

Aligns the element's bottom edge to the target's bottom edge with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Offset from the edge (negative = inside, positive = outside, default: 0)

Returns

  • VisualElement self

VisualElement:centerHorizontal(target, offset?)

Centers the element horizontally relative to the target with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Horizontal offset from center (default: 0)

Returns

  • VisualElement self

VisualElement:centerVertical(target, offset?)

Centers the element vertically relative to the target with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Vertical offset from center (default: 0)

Returns

  • VisualElement self

VisualElement:centerIn(target)

Centers the element both horizontally and vertically relative to the target

Parameters

  • target BaseElement|string The target element or "parent"

Returns

  • VisualElement self

VisualElement:rightOf(target, gap?)

Positions the element to the right of the target with optional gap

Parameters

  • target BaseElement|string The target element or "parent"
  • gap (optional) number Gap between elements (default: 0)

Returns

  • VisualElement self

VisualElement:leftOf(target, gap?)

Positions the element to the left of the target with optional gap

Parameters

  • target BaseElement|string The target element or "parent"
  • gap (optional) number Gap between elements (default: 0)

Returns

  • VisualElement self

VisualElement:below(target, gap?)

Positions the element below the target with optional gap

Parameters

  • target BaseElement|string The target element or "parent"
  • gap (optional) number Gap between elements (default: 0)

Returns

  • VisualElement self

VisualElement:above(target, gap?)

Positions the element above the target with optional gap

Parameters

  • target BaseElement|string The target element or "parent"
  • gap (optional) number Gap between elements (default: 0)

Returns

  • VisualElement self

VisualElement:stretchWidth(target, margin?)

Stretches the element to match the target's width with optional margin

Parameters

  • target BaseElement|string The target element or "parent"
  • margin (optional) number Margin on each side (default: 0)

Returns

  • VisualElement self

VisualElement:stretchHeight(target, margin?)

Stretches the element to match the target's height with optional margin

Parameters

  • target BaseElement|string The target element or "parent"
  • margin (optional) number Margin on top and bottom (default: 0)

Returns

  • VisualElement self

VisualElement:stretch(target, margin?)

Stretches the element to match the target's width and height with optional margin

Parameters

  • target BaseElement|string The target element or "parent"
  • margin (optional) number Margin on all sides (default: 0)

Returns

  • VisualElement self

VisualElement:widthPercent(target, percent)

Sets the element's width as a percentage of the target's width

Parameters

  • target BaseElement|string The target element or "parent"
  • percent number Percentage of target's width (0-100)

Returns

  • VisualElement self

VisualElement:heightPercent(target, percent)

Sets the element's height as a percentage of the target's height

Parameters

  • target BaseElement|string The target element or "parent"
  • percent number Percentage of target's height (0-100)

Returns

  • VisualElement self

VisualElement:matchWidth(target, offset?)

Matches the element's width to the target's width with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Offset to add to target's width (default: 0)

Returns

  • VisualElement self

VisualElement:matchHeight(target, offset?)

Matches the element's height to the target's height with optional offset

Parameters

  • target BaseElement|string The target element or "parent"
  • offset (optional) number Offset to add to target's height (default: 0)

Returns

  • VisualElement self

VisualElement:fillParent(margin?)

Stretches the element to fill its parent's width and height with optional margin

Parameters

  • margin (optional) number Margin on all sides (default: 0)

Returns

  • VisualElement self

VisualElement:fillWidth(margin?)

Stretches the element to fill its parent's width with optional margin

Parameters

  • margin (optional) number Margin on left and right (default: 0)

Returns

  • VisualElement self

VisualElement:fillHeight(margin?)

Stretches the element to fill its parent's height with optional margin

Parameters

  • margin (optional) number Margin on top and bottom (default: 0)

Returns

  • VisualElement self

VisualElement:center()

Centers the element within its parent both horizontally and vertically

Returns

  • VisualElement self

VisualElement:toRight(gap?)

Aligns the element's right edge to its parent's right edge with optional gap

Parameters

  • gap (optional) number Gap from the edge (default: 0)

Returns

  • VisualElement self

VisualElement:toLeft(gap?)

Aligns the element's left edge to its parent's left edge with optional gap

Parameters

  • gap (optional) number Gap from the edge (default: 0)

Returns

  • VisualElement self

VisualElement:toTop(gap?)

Aligns the element's top edge to its parent's top edge with optional gap

Parameters

  • gap (optional) number Gap from the edge (default: 0)

Returns

  • VisualElement self

VisualElement:toBottom(gap?)

Aligns the element's bottom edge to its parent's bottom edge with optional gap

Parameters

  • gap (optional) number Gap from the edge (default: 0)

Returns

  • VisualElement self

VisualElement:isInBounds(x, y)

Checks if the specified coordinates are within the bounds of the element

Parameters

  • x number The x position to check
  • y number The y position to check

Returns

  • boolean isInBounds Whether the coordinates are within the bounds of the element

VisualElement:setFocused(focused, internal?)

Sets or removes focus from this element

Parameters

  • focused boolean Whether to focus or blur
  • internal (optional) boolean Internal flag to prevent parent notification

Returns

  • VisualElement self

VisualElement:isFocused()

Gets whether this element is focused

Returns

  • boolean isFocused

VisualElement:isFocused()

Gets whether this element is focused

Returns

  • boolean isFocused

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

  • colorOrOptions any Border color or options table
  • sideOptions (optional) table Side options table (if color is provided as first argument)

Returns

  • VisualElement self

VisualElement:removeBorder()

Removes the previously added border (if any)

Returns

  • VisualElement self

VisualElement:calculatePosition()

Calculates the position of the element relative to its parent

Returns

  • number x The x position
  • number y The y position

VisualElement:getAbsolutePosition(x?, y?)

Returns the absolute position of the element or the given coordinates.

Parameters

  • x (optional) number x position
  • y (optional) number y position

Returns

  • number x The absolute x position
  • number y The absolute y position

VisualElement:getRelativePosition(x?, y?)

Returns the relative position of the element or the given coordinates.

Parameters

  • x (optional) number x position
  • y (optional) number y position

Returns

  • number x The relative x position
  • number y The 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

  • VisualElement self The VisualElement instance

Released under the MIT License.