• Studio

  • Studio API

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • 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
    

    name

    string

    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
    

    visible

    boolean

    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)
    

    style

    IStyle

    The style of the element.

    local myElement = VisualElement.new()
    myElement.style = IStyle.new()
    

    tooltip

    string

    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

    string

    Register a callback.

    local myElement = VisualElement.new()
    local myCallback = function()
      -- Do something
    end
    
    myElement:RegisterCallback(myCallback, function()
      print("Callback called")
    end)
    

    Returns

    string

    Register a press callback.

    local myElement = VisualElement.new()
    local myCallback = function()
      -- Do something
    end
    
    myElement:RegisterPressCallback(function()
      print("Press callback called")
    end)
    

    Returns

    void

    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

    void

    Focus the element.

    local myElement = VisualElement.new()
    myElement:Focus()
    

    Returns

    void

    Set the enabled state of the element.

    local myElement = VisualElement.new()
    myElement:SetEnabled(true) -- Or false
    

    Parameters

    value

    boolean

    Returns

    void

    Mark the element as dirty for repaint.

    local myElement = VisualElement.new()
    myElement:MarkDirtyRepaint()
    

    Returns

    void

    Check if the element contains a point.

    local myElement = VisualElement.new()
    local containsPoint = myElement:ContainsPoint(Vector2.new(0, 0))
    

    Parameters

    localPoint
    Vector2

    Returns

    boolean

    Check if the element overlaps with another element.

    local myElement = VisualElement.new()
    local otherElement = VisualElement.new()
    local overlaps = myElement:Overlaps(otherElement)
    

    Parameters

    rectangle
    Rect

    Returns

    boolean

    Clear the class list of the element.

    local myElement = VisualElement.new()
    myElement:ClearClassList()
    

    Returns

    void

    Add a class to the class list of the

    local myElement = VisualElement.new()
    myElement:AddToClassList("myClass")
    

    Parameters

    className

    string

    Returns

    void

    Remove a class from the class list of the element.

    local myElement = VisualElement.new()
    myElement:RemoveFromClassList("myClass")
    

    Parameters

    className

    string

    Returns

    void

    Toggle a class in the class list of the element.

    local myElement = VisualElement.new()
    myElement:ToggleInClassList("myClass")
    

    Parameters

    className

    string

    Returns

    void

    Enable a class in the class list of the element.

    local myElement = VisualElement.new()
    myElement:EnableInClassList("myClass")
    

    Parameters

    className

    string

    enable

    boolean

    Returns

    void

    Check if the class list of the element contains a class.

    local myElement = VisualElement.new()
    local classListContains = myElement:ClassListContains("myClass")
    

    Parameters

    cls

    string

    Returns

    boolean

    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

    Returns

    void

    Insert a child at a specific index.

    local myElement = VisualElement.new()
    local child = VisualElement.new()
    myElement:Insert(0, child)
    

    Parameters

    index

    number

    Returns

    void

    Removes a specified child element from this element's hierarchy.

    local myElement = VisualElement.new()
    local child = VisualElement.new()
    myElement:Remove(child)
    

    Parameters

    Returns

    void

    Remove a child at a specific index.

    local myElement = VisualElement.new()
    myElement:RemoveAt(0)
    

    Parameters

    index

    number

    Returns

    void

    Clear all children of the element.

    local myElement = VisualElement.new()
    myElement:Clear()
    

    Returns

    void

    Get a child at a specific index.

    local myElement = VisualElement.new()
    local element = myElement:ElementAt(0)
    

    Parameters

    index

    number

    Get the index of a child.

    local myElement = VisualElement.new()
    local index = myElement:IndexOf(VisualElement.new())
    

    Parameters

    Returns

    number

    Bring the element to the front.

    local myElement = VisualElement.new()
    myElement:BringToFront()
    

    Returns

    void

    Send the element to the back.

    local myElement = VisualElement.new()
    myElement:SendToBack()
    

    Returns

    void

    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

    Returns

    void

    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

    Returns

    void

    Detaches this element from its parent, removing it from the visual tree.

    local myElement = VisualElement.new()
    myElement:RemoveFromHierarchy()
    

    Returns

    void

    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

    Returns

    boolean

    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)
    

    Parameters

    Updated about 1 month ago

    PocketWorlds Icon

    © 2024 Pocket Worlds. All rights reserved.