9.8 KiB
9.8 KiB
Container
The Container class serves as a fundamental building block for organizing UI elements. It acts as a parent element that can hold and manage child elements.
Extends: VisualElement
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| children | table | {} | The children of the container |
| childrenSorted | boolean | true | Whether the children are sorted |
| childrenEventsSorted | boolean | true | Whether the children events are sorted |
| childrenEvents | table | {} | The children events of the container |
| eventListenerCount | table | {} | The event listener count of the container |
| focusedChild | table | nil | The focused child of the container |
| visibleChildren | table | {} | The visible children of the container |
| visibleChildrenEvents | table | {} | The visible children events of the container |
| offsetX | number | 0 | Horizontal content offset |
| offsetY | number | 0 | Vertical content offset |
Functions
| Method | Returns | Description |
|---|---|---|
| Container.new | Container | Creates a new Container instance |
| Container:init | - | Initializes the Container instance |
| Container:isChildVisible | boolean | Returns whether a child is visible |
| Container:addChild | Container | Adds a child to the container |
| Container:clear | Container | Clears the container |
| Container:sortChildren | Container | Sorts the children of the container |
| Container:sortChildrenEvents | Container | Sorts the children events of the container |
| Container:registerChildrenEvents | Container | Registers the children events of the container |
| Container:registerChildEvent | Container | Registers the children events of the container |
| 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 from the container |
| Container:getChild | self | Removes a child from the container |
| Container:callChildrenEvent | boolean, child | Calls a event on all children |
| Container:handleEvent | boolean | Default handler for events |
| Container:mouse_click | boolean | Handles mouse click events |
| Container:mouse_up | boolean | Handles mouse up events |
| Container:mouse_release | - | Handles mouse release events |
| Container:mouse_move | boolean | Handles mouse move events |
| Container:mouse_drag | boolean | Handles mouse drag events |
| Container:mouse_scroll | boolean | Handles mouse scroll events |
| Container:key | boolean | Handles key events |
| Container:char | boolean | Handles char events |
| Container:key_up | boolean | Handles key up events |
| Container:multiBlit | Container | Draws multiple lines of text, fg and bg strings |
| Container:textFg | Container | Draws a line of text and fg as color |
| Container:textBg | Container | Draws a line of text and bg as color |
| Container:blit | Container | Draws a line of text and fg and bg as colors |
| Container:render | - | Renders the container |
| Container:destroy | - |
Container.new()
Creates a new Container instance
Returns
ContainerselfThe new container instance
Container:init(props, basalt)
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Container:isChildVisible(child)
Returns whether a child is visible
Parameters
childtableThe child to check
Returns
booleanbooleanthe child is visible
Container:addChild(child)
Adds a child to the container
Parameters
childtableThe child to add
Returns
ContainerselfThe container instance
Container:clear()
Clears the container
Returns
ContainerselfThe container instance
Container:sortChildren()
Sorts the children of the container
Returns
ContainerselfThe container instance
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 the children events of the container
Parameters
childtableThe child to register events foreventNamestringThe event name to register
Returns
ContainerselfThe container instance
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 a child from the container
Parameters
childtableThe child to remove
Returns
ContainerselfThe container instance
Container:getChild(path)
Removes a child from the container
Parameters
pathstringThe path to the child to remove
Returns
selfThecontainer instance
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:handleEvent(event)
Parameters
eventstringThe event to handle
Returns
booleanhandledWhether the event was handled
Container:mouse_click(button, x, y)
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Container:mouse_up(button, x, y)
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Container:mouse_release(button, x, y)
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Container:mouse_move(_, x, y)
Parameters
_numberunknownxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Container:mouse_drag(button, x, y)
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Container:mouse_scroll(direction, x, y)
Parameters
directionnumberThe direction of the scrollxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Container:key(key)
Parameters
keynumberThe key that was pressed
Returns
booleanhandledWhether the event was handled
Container:char(char)
Parameters
charstringThe character that was pressed
Returns
booleanhandledWhether the event was handled
Container:key_up(key)
Parameters
keynumberThe key that was released
Returns
booleanhandledWhether the event was handled
Container:multiBlit(x, y, width, height, text, fg, bg)
Parameters
xnumberThe x position to draw the textynumberThe y position to draw the textwidthnumberThe width of the textheightnumberThe height of the texttextstringThe text to drawfgstringThe foreground color of the textbgstringThe background color of the text
Returns
ContainerselfThe container instance
Container:textFg(x, y, text, fg)
Parameters
xnumberThe x position to draw the textynumberThe y position to draw the texttextstringThe text to drawfgcolorThe foreground color of the text
Returns
ContainerselfThe container instance
Container:textBg(x, y, text, bg)
Parameters
xnumberThe x position to draw the textynumberThe y position to draw the texttextstringThe text to drawbgcolorThe background color of the text
Returns
ContainerselfThe container instance
Container:blit(x, y, text, fg, bg)
Parameters
xnumberThe x position to draw the textynumberThe y position to draw the texttextstringThe text to drawfgstringThe foreground color of the textbgstringThe background color of the text
Returns
ContainerselfThe container instance