Skip to content

Container

_A fundamental layout element that manages child UI components. Containers handle element organization, event propagation, _ rendering hierarchy, and coordinate space management. They serve as the backbone of Basalt's UI structure by providing:- Child element management and organization- Event bubbling and distribution- Visibility calculations and clipping- Focus management- Coordinate space transformation

Extends: VisualElement

Properties

PropertyTypeDefaultDescription
childrentable{}Collection of all child elements
childrenSortedbooleantrueIndicates if children are sorted by z-index
childrenEventsSortedbooleantrueIndicates if event handlers are properly sorted
childrenEventstable{}Registered event handlers for all children
eventListenerCounttable{}Number of listeners per event type
focusedChildtablenilCurrently focused child element (receives keyboard events)
visibleChildrentable{}Currently visible child elements (calculated based on viewport)
visibleChildrenEventstable{}Event handlers for currently visible children
offsetXnumber0Horizontal scroll/content offset
offsetYnumber0Vertical scroll/content offset

Functions

MethodReturnsDescription
Container:isChildVisiblebooleanChecks if a child element is visible
Container:addChildContainerAdds a child element to the container
Container:clearContainerRemoves all children and resets container
Container:sortChildrenContainerUpdates child element ordering
Container:sortChildrenEventsContainerSorts the children events of the container
Container:registerChildrenEventsContainerRegisters the children events of the container
Container:registerChildEventContainerSets up event handling for a child
Container:removeChildrenEventsContainerUnregisters the children events of the container
Container:unregisterChildEventContainerUnregisters the children events of the container
Container:removeChildContainerRemoves a child element from the container
Container:getChildchildFinds a child element by its path
Container:callChildrenEventboolean, childCalls a event on all children

Container:isChildVisible(child)

Tests whether a child element is currently visible within the container's viewport

Parameters

  • child table The child element to check

Returns

  • boolean isVisible Whether the child is within view bounds

Container:addChild(child)

Adds a new element to this container's hierarchy

Parameters

  • child table The element to add as a child

Returns

  • Container self For method chaining

Container:clear()

Removes all child elements and resets the container's state

Returns

  • Container self For method chaining

Container:sortChildren()

Re-sorts children by their z-index and updates visibility

Returns

  • Container self For method chaining

Container:sortChildrenEvents(eventName)

Sorts the children events of the container

Parameters

  • eventName string The event name to sort

Returns

  • Container self The container instance

Container:registerChildrenEvents(child)

Registers the children events of the container

Parameters

  • child table The child to register events for

Returns

  • Container self The container instance

Container:registerChildEvent(child, eventName)

Registers an event handler for a specific child element

Parameters

  • child table The child element to register events for
  • eventName string The name of the event to register

Returns

  • Container self For method chaining

Container:removeChildrenEvents(child)

Unregisters the children events of the container

Parameters

  • child table The child to unregister events for

Returns

  • Container self The container instance

Container:unregisterChildEvent(child, eventName)

Unregisters the children events of the container

Parameters

  • child table The child to unregister events for
  • eventName string The event name to unregister

Returns

  • Container self The container instance

Container:removeChild(child)

Removes an element from this container's hierarchy and cleans up its events

Parameters

  • child table The element to remove

Returns

  • Container self For method chaining

Container:getChild(path)

Locates a child element using a path-like syntax (e.g. "panel/button1")

Parameters

  • path string Path to the child (e.g. "panel/button1", "header/title")

Returns

  • child The found element or nil if not found

Container:callChildrenEvent(visibleOnly, event)

Calls a event on all children

Parameters

  • visibleOnly boolean Whether to only call the event on visible children
  • event string The event to call

Returns

  • boolean handled Whether the event was handled
  • child The child that handled the event

Released under the MIT License.