VisualElement
Creates a new instance of VisualElement. This is the basic building block for UI elements, offering foundational features like layout, styling, and rendering.
Properties
A unique identifier for storing view-related data associated with this element.
local myElement = VisualElement.new()
myElement.viewDataKey = "myElement"
Indicates whether the element can capture user focus. This is useful for determining if the element is interactive.
local myElement = VisualElement.new()
myElement.canGrabFocus = true
Defines the layout type of the element, which influences how it arranges its children.
local myElement = VisualElement.new()
myElement.layout = Layout.Flex
Represents the rectangular area that contains the element's content, typically used for layout calculations.
local myElement = VisualElement.new()
myElement.contentRect = Rect.new(0, 0, 100, 100)
The global (world) bounds of the element, indicating its position and size within the overall UI.
local myElement = VisualElement.new()
local worldBound = myElement.worldBound
The local bounds of the element, representing its position and size relative to its parent.
local myElement = VisualElement.new()
local localBound = myElement.localBound
The world transform of the element.
local myElement = VisualElement.new()
local worldTransform = myElement.worldTransform
The name of the element.
local myElement = VisualElement.new()
myElement.name = "myElement"
Determines if the element is enabled in the hierarchy.
local myElement = VisualElement.new()
local enabledInHierarchy = myElement.enabledInHierarchy
Determines if the element is enabled.
local myElement = VisualElement.new()
myElement.enabledSelf = true
Determines if the element is visible.
local myElement = VisualElement.new()
myElement.visible = true
The parent of the element.
local myElement = VisualElement.new()
local parent = myElement.parent
The content container of the element.
local myElement = VisualElement.new()
local contentContainer = myElement.contentContainer
The number of children of the element.
local myElement = VisualElement.new()
local childCount = myElement.childCount
print(childCount)
The style of the element.
local myElement = VisualElement.new()
myElement.style = IStyle.new()
The tooltip of the element.
local myElement = VisualElement.new()
myElement.tooltip = "This is a tooltip"
Methods
Query the element.
local myElement = VisualElement.new()
local query = myElement:Q("myQuery")
Parameters
name
Returns
Register a callback.
local myElement = VisualElement.new()
local myCallback = function()
-- Do something
end
myElement:RegisterCallback(myCallback, function()
print("Callback called")
end)
Returns
Register a press callback.
local myElement = VisualElement.new()
local myCallback = function()
-- Do something
end
myElement:RegisterPressCallback(function()
print("Press callback called")
end)
Returns
Register a long press callback.
local myElement = VisualElement.new()
local myCallback = function()
-- Do something
end
myElement:RegisterLongPressCallback(function()
print("Long press callback called")
end)
Returns
Focus the element.
local myElement = VisualElement.new()
myElement:Focus()
Returns
Set the enabled state of the element.
local myElement = VisualElement.new()
myElement:SetEnabled(true) -- Or false
Parameters
value
Returns
Mark the element as dirty for repaint.
local myElement = VisualElement.new()
myElement:MarkDirtyRepaint()
Returns
Check if the element contains a point.
local myElement = VisualElement.new()
local containsPoint = myElement:ContainsPoint(Vector2.new(0, 0))
Parameters
localPoint
Vector2Returns
Check if the element overlaps with another element.
local myElement = VisualElement.new()
local otherElement = VisualElement.new()
local overlaps = myElement:Overlaps(otherElement)
Parameters
rectangle
RectReturns
Clear the class list of the element.
local myElement = VisualElement.new()
myElement:ClearClassList()
Returns
Add a class to the class list of the
local myElement = VisualElement.new()
myElement:AddToClassList("myClass")
Parameters
className
Returns
Remove a class from the class list of the element.
local myElement = VisualElement.new()
myElement:RemoveFromClassList("myClass")
Parameters
className
Returns
Toggle a class in the class list of the element.
local myElement = VisualElement.new()
myElement:ToggleInClassList("myClass")
Parameters
className
Returns
Enable a class in the class list of the element.
local myElement = VisualElement.new()
myElement:EnableInClassList("myClass")
Parameters
className
enable
Returns
Check if the class list of the element contains a class.
local myElement = VisualElement.new()
local classListContains = myElement:ClassListContains("myClass")
Parameters
cls
Returns
Adds a child element to this element's hierarchy, making it a part of the visual tree.
local myElement = VisualElement.new()
local child = VisualElement.new()
myElement:Add(child)
Parameters
child
VisualElementReturns
Insert a child at a specific index.
local myElement = VisualElement.new()
local child = VisualElement.new()
myElement:Insert(0, child)
Parameters
index
element
VisualElementReturns
Removes a specified child element from this element's hierarchy.
local myElement = VisualElement.new()
local child = VisualElement.new()
myElement:Remove(child)
Parameters
element
VisualElementReturns
Remove a child at a specific index.
local myElement = VisualElement.new()
myElement:RemoveAt(0)
Parameters
index
Returns
Clear all children of the element.
local myElement = VisualElement.new()
myElement:Clear()
Returns
Get a child at a specific index.
local myElement = VisualElement.new()
local element = myElement:ElementAt(0)
Parameters
index
Returns
Get the index of a child.
local myElement = VisualElement.new()
local index = myElement:IndexOf(VisualElement.new())
Parameters
element
VisualElementReturns
Bring the element to the front.
local myElement = VisualElement.new()
myElement:BringToFront()
Returns
Send the element to the back.
local myElement = VisualElement.new()
myElement:SendToBack()
Returns
Positions this element immediately behind a specified sibling element within the same parent.
local myElement = VisualElement.new()
local sibling = VisualElement.new()
myElement:PlaceBehind(sibling)
Parameters
sibling
VisualElementReturns
Positions this element immediately in front of a specified sibling element within the same parent.
local myElement = VisualElement.new()
local sibling = VisualElement.new()
myElement:PlaceInFront(sibling)
Parameters
sibling
VisualElementReturns
Detaches this element from its parent, removing it from the visual tree.
local myElement = VisualElement.new()
myElement:RemoveFromHierarchy()
Returns
Checks if this element includes a specified child element within its hierarchy.
local myElement = VisualElement.new()
local child = VisualElement.new()
local contains = myElement:Contains(child)
Parameters
child
VisualElementReturns
Finds the closest common ancestor shared by this element and another specified element.
local myElement = VisualElement.new()
local otherElement = VisualElement.new()
local commonAncestor = myElement:FindCommonAncestor(otherElement)