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.
VisualElement
Section titled “VisualElement”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.
Properties
Section titled “Properties”| 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 |
Element tree
Section titled “Element tree”parent:Add(child: VisualElement)parent:Clear()element:RemoveFromHierarchy()element:Delete(): boolelement: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.
Queries
Section titled “Queries”element:GetChild(name: string): VisualElementelement:GetChildAt(index: number): VisualElementGetChild() recursively searches for a named descendant and returns nil when no match exists. GetChildAt() returns a direct child using a zero-based index.
Classes and name
Section titled “Classes and name”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.
Pointer and events
Section titled “Pointer and events”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(): numberelement: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.
Cursor and border
Section titled “Cursor and border”element:SetBorderColor(color: Color)element:SetCursor(cursorName: string): boolSetCursor() returns false for an unknown name. Supported names are:
arrow, hand, text, move, resize-horizontal, resize-vertical, pipette.
TextElement
Section titled “TextElement”Returned for Label and other text elements.
label.text = "Ready"print(label.text)| Property | Type | Access |
|---|---|---|
text |
string |
get/set |
ImageElement
Section titled “ImageElement”Returned for a UXML Image element.
local icon = root:GetChild("imgIcon")icon.texture = Textures:GetTexture("Icon.png")| Property | Type | Access |
|---|---|---|
texture |
Texture | get/set |
TextFieldElement
Section titled “TextFieldElement”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.
DotViewElement
Section titled “DotViewElement”A specialized multi-dot indicator.
| Property | Type | Access |
|---|---|---|
count |
number |
get/set |
fillToValue |
boolean |
get/set |
value |
number |
get/set |
dots.count = 5dots.value = 3dots.fillToValue = truedots:Reset()Reset() resets the current view state.
ScrollView
Section titled “ScrollView”scroll:CanScrollByDelta(deltaY: number): boolscroll:ScrollByDelta(deltaY: number): boolscroll: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.