Container
A fundamental layout element that manages child UI components. Containers handle element organization, event propagation, rendering hierarchy, and coordinate space management.
Extends: VisualElement
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| children | table | {} | Collection of all child elements |
| childrenSorted | boolean | true | Indicates if children are sorted by z-index |
| childrenEventsSorted | boolean | true | Indicates if event handlers are properly sorted |
| childrenEvents | table | {} | Registered event handlers for all children |
| eventListenerCount | table | {} | Number of listeners per event type |
| focusedChild | table | nil | Currently focused child element (receives keyboard events) |
| visibleChildren | table | {} | Currently visible child elements (calculated based on viewport) |
| visibleChildrenEvents | table | {} | Event handlers for currently visible children |
| offsetX | number | 0 | Horizontal scroll/content offset |
| offsetY | number | 0 | Vertical scroll/content offset |
Functions
| Method | Returns | Description |
|---|---|---|
| Container:isChildVisible | boolean | Checks if a child element is visible |
| Container:addChild | Container | Adds a child element to the container |
| Container:clear | Container | Removes all children and resets container |
| Container:sortChildren | Container | Updates child element ordering |
| Container:sortChildrenEvents | Container | Sorts the children events of the container |
| Container:registerChildrenEvents | Container | Registers the children events of the container |
| Container:registerChildEvent | Container | Sets up event handling for a child |
| Container:removeChildrenEvents | Container | Unregisters the children events of the container |
| Container:unregisterChildEvent | Container | Unregisters the children events of the container |
| Container:removeChild | Container | Removes a child element from the container |
| Container:getChild | child | Finds a child element by its path |
| Container:callChildrenEvent | boolean, child | Calls a event on all children |
| Container:applyLayout | Container | Applies a layout to the container |
| Container:updateLayout | Container | Updates the layout |
| Container:clearLayout | Container | Clears the layout |
Container:isChildVisible(child)
Tests whether a child element is currently visible within the container's viewport
Parameters
childtableThe child element to check
Returns
booleanisVisibleWhether the child is within view bounds
Container:addChild(child)
Adds a new element to this container's hierarchy
Parameters
childtableThe element to add as a child
Returns
ContainerselfFor method chaining
Container:clear()
Removes all child elements and resets the container's state
Returns
ContainerselfFor method chaining
Container:sortChildren()
Re-sorts children by their z-index and updates visibility
Returns
ContainerselfFor method chaining
Container:sortChildrenEvents(eventName)
Sorts the children events of the container
Parameters
eventNamestringThe event name to sort
Returns
ContainerselfThe container instance
Container:registerChildrenEvents(child)
Registers the children events of the container
Parameters
childtableThe child to register events for
Returns
ContainerselfThe container instance
Container:registerChildEvent(child, eventName)
Registers an event handler for a specific child element
Parameters
childtableThe child element to register events foreventNamestringThe name of the event to register
Returns
ContainerselfFor method chaining
Container:removeChildrenEvents(child)
Unregisters the children events of the container
Parameters
childtableThe child to unregister events for
Returns
ContainerselfThe container instance
Container:unregisterChildEvent(child, eventName)
Unregisters the children events of the container
Parameters
childtableThe child to unregister events foreventNamestringThe event name to unregister
Returns
ContainerselfThe container instance
Container:removeChild(child)
Removes an element from this container's hierarchy and cleans up its events
Parameters
childtableThe element to remove
Returns
ContainerselfFor method chaining
Container:getChild(path)
Locates a child element using a path-like syntax (e.g. "panel/button1")
Parameters
pathstringPath to the child (e.g. "panel/button1", "header/title")
Returns
childThefound element or nil if not found
Container:callChildrenEvent(visibleOnly, event)
Calls a event on all children
Parameters
visibleOnlybooleanWhether to only call the event on visible childreneventstringThe event to call
Returns
booleanhandledWhether the event was handledchildThechild that handled the event
Container:applyLayout(layoutPath, options?)
Applies a layout from a file to this container
Parameters
layoutPathstringPath to the layout file (e.g. "layouts/grid")options(optional)tableOptional layout-specific options
Returns
ContainerselfFor method chaining
Container:updateLayout()
Updates the current layout (recalculates positions)
Returns
ContainerselfFor method chaining
Container:clearLayout()
Removes the current layout
Returns
ContainerselfFor method chaining