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
clickedbooleanfalseWhether the element is currently clicked
hoverbooleanfalseWhether the mouse is currently hover over the element (Craftos-PC only)
backgroundEnabledbooleantrueWhether to render the background
focusedbooleanfalseWhether the element has input focus
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:isInBoundsbooleanChecks if point is within bounds
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: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: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.