Skip to content

Elements

Client only Elements are created and loaded through UI.

Creating or finding an element does not display anything new by itself. An element is visible only while it belongs to a root tree placed on screen through one of the UI methods and its visible property is enabled. RemoveFromHierarchy() hides it while keeping the object reusable; Delete() removes it permanently.

The base type of every UI element. Depending on the actual UXML element, query methods automatically return a more specific type: TextElement, ImageElement, TextFieldElement, ScrollView, or DotViewElement.

Property Access Description
childCount get Number of direct children
hasChildren get Whether the element has children
height get Resolved on-screen height
name get Name from UXML or SetName()
style get ElementStyle object
visible get/set Whether the element participates in rendering
width get Resolved on-screen width
windowScale get Scale of the HUD window containing the element
parent:Add(child: VisualElement)
parent:Clear()
element:RemoveFromHierarchy()
element:Delete(): bool
element:SendToBack()
  • Add() adds an element to a container;
  • Clear() detaches all direct children;
  • RemoveFromHierarchy() detaches the element without permanently deleting it;
  • Delete() permanently deletes the element and its wrappers;
  • SendToBack() moves the element behind its siblings.
element:GetChild(name: string): VisualElement
element:GetChildAt(index: number): VisualElement

GetChild() recursively searches for a named descendant and returns nil when no match exists. GetChildAt() returns a direct child using a zero-based index.

element:AddToClassList(className: string)
element:EnableInClassList(className: string, enabled: boolean)
element:SetName(name: string)

USS selectors use classes. EnableInClassList() is convenient for states such as active, warning, or disabled.

Absolute UI may ignore the pointer by default. Enable interaction before registering events:

button:EnableMouseEvents()
button:OnClick(function(clickCount)
print("Clicks: " .. tostring(clickCount))
end)
button:OnMouseEnter(function()
button:EnableInClassList("hover", true)
end)
button:OnMouseLeave(function()
button:EnableInClassList("hover", false)
end)
Method Callback argument Purpose
OnClick(callback) clickCount Completed click
OnPointerDown(callback) clickCount Pointer button press
OnMouseEnter(callback) none Pointer entered the element
OnMouseLeave(callback) none Pointer left the element

Registering again replaces the previous callback for the same event. Pass nil to remove the handler.

element:GetPickingMode(): number
element:SetPickingMode(mode: number)
Mode Number Behavior
Position 0 The element participates in pointer handling
Ignore 1 The element ignores the pointer

EnableMouseEvents() is a shortcut for enabling Position mode.

element:SetBorderColor(color: Color)
element:SetCursor(cursorName: string): bool

SetCursor() returns false for an unknown name. Supported names are:

arrow, hand, text, move, resize-horizontal, resize-vertical, pipette.

Returned for Label and other text elements.

label.text = "Ready"
print(label.text)
Property Type Access
text string get/set

Returned for a UXML Image element.

local icon = root:GetChild("imgIcon")
icon.texture = Textures:GetTexture("Icon.png")
Property Type Access
texture Texture get/set
local input = root:GetChild("txtSearch")
input.value = "query"
input:Focus()
Property Type Access
IsFocused boolean get
value string get/set

Focus() gives the field keyboard focus.

A specialized multi-dot indicator.

Property Type Access
count number get/set
fillToValue boolean get/set
value number get/set
dots.count = 5
dots.value = 3
dots.fillToValue = true
dots:Reset()

Reset() resets the current view state.

scroll:CanScrollByDelta(deltaY: number): bool
scroll:ScrollByDelta(deltaY: number): bool
scroll:ScrollToTop()
scroll:ScrollToBottom()
scroll:EnableAutoScroll()
scroll:DisableAutoScroll()
scroll:RefreshVerticalScrollerVisibility()
  • CanScrollByDelta() checks whether content can move in the requested direction;
  • ScrollByDelta() performs a scroll step and reports whether the position changed;
  • auto-scroll keeps the view at the end when content is added;
  • RefreshVerticalScrollerVisibility() recalculates vertical scrollbar visibility.