Skip to content

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

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

Combined Properties

NamePropertiesDescription
positionx number, y numberCombined x, y position
sizewidth number, height numberCombined width, height
colorforeground number, background numberCombined foreground, background colors

Events

EventParametersDescription
onClickbutton string, x number, y numberFired on mouse click
onMouseUpbutton, x, yFired on mouse button release
onReleasebutton, x, yFired when mouse leaves while clicked
onDragbutton, x, yFired when mouse moves while clicked
onScrolldirection, x, yFired 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
onKeykeyFired on key press
onKeyUpkeyFired on key release
onCharcharFired on character input

Functions

MethodReturnsDescription
VisualElement:calculatePositionnumberCalculates the position of the element
VisualElement:drawBg-
VisualElement:drawFg-
VisualElement:drawText-
VisualElement:getAbsolutePositionnumberReturns the absolute position of the element
VisualElement:getRelativePositionnumberReturns the relative position of the element
VisualElement:isInBoundsbooleanChecks if point is within bounds
VisualElement:prioritizeVisualElementPrioritizes the element by moving it to the top of its parent's children

Protected Functions

MethodReturnsDescription
VisualElement:blit-Draws text with both colors
VisualElement:blur-Handles a blur event
VisualElement:char-Handles a character event
VisualElement:focus-Handles a focus event
VisualElement:init-Initializes a new visual element with properties
VisualElement:key-Handles a key event
VisualElement:key_up-Handles a key up event
VisualElement:mouse_clickbooleanHandles a mouse click event
VisualElement:mouse_dragbooleanHandles a mouse drag event
VisualElement:mouse_movebooleanHandles a mouse move event
VisualElement:mouse_release-Handles a mouse release event
VisualElement:mouse_scrollbooleanHandles a mouse scroll event
VisualElement:mouse_upbooleanHandles a mouse up event
VisualElement:multiBlit-Multi-character drawing with colors
VisualElement:postRender-Post-rendering function for the element
VisualElement:render-Renders the element
VisualElement:setCursorVisualElementSets the cursor position
VisualElement:textBg-Draws text with background color
VisualElement:textFg-Draws text with foreground color

VisualElement:calculatePosition()

Calculates the position of the element relative to its parent

Returns

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

VisualElement:drawBg()

VisualElement:drawFg()

VisualElement:drawText()

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: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: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.