import{_ as o,C as t,o as p,c as r,k as a,a as s,H as l,Q as e}from"./chunks/framework.4313453f.js";const ls=JSON.parse('{"title":"Container","description":"","frontmatter":{},"headers":[],"relativePath":"references/container.md","filePath":"references/container.md","lastUpdated":null}'),c={name:"references/container.md"},i=e('
Container is the base class for all frame types. It provides the basic structure and functionality for all frame elements. Container elements can contain other container elements, thus forming the foundation for the hierarchy of frame elements.
Container inherit from VisualElement and BasicElement
| Property | Type | Description |
|---|---|---|
| children | table | A list containing all child elements within the container. |
| childrenByName | table | A mapping of child elements by their respective names. |
| childrenEvents | table | A collection of events associated with child elements. |
| cursorBlink | bool | Indicates if the cursor blinks when a container is focused. |
| cursorColor | color | The color of the cursor within the container. |
| cursorX | number | The X-coordinate of the cursor within the container. |
| cursorY | number | The Y-coordinate of the cursor within the container. |
| focusedChild | element | The currently focused child element within the container. |
| elementsSorted | bool | Indicates if the child elements in the container are sorted. |
| xOffset | number | Horizontal offset for positioning child elements within the container. |
| yOffset | number | Vertical offset for positioning child elements within the container. |
| Methods | Returns | Description |
|---|---|---|
| getVisibleChildren | table | Returns a table containing all visible child elements within the container. |
| isChildVisible | boolean | Returns a boolean value indicating whether the specified child element is visible within the container. |
| forceVisibleChildrenUpdate | self | Forces to update all child elements within the container. |
| getChild | element | Returns the specified child element within the container. |
| addChild | self | Adds a child element to the container. |
| removeChild | self | Removes a child element from the container. |
| isEventRegistered | self | Checks if a certain event is registered for a child. |
| addEvent | self | Adds an event for a child. |
| removeEvent | self | Removes an event from the container, bound to a child. |
| getVisibleChildrenEvents | table | Returns all visible children of the container for a certain event. |
| updateChild | self | Updates the z-position of a specific child element. |
| setCursor | self | Sets the cursor position within the container. |
| add{Element} | element | Adds a specific type of element (e.g., addButton, addFrame, addInput, addLabel) to the container. |
Returns a table containing all visible child elements within the container.
table visible childrenlocal main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()Checks whether the specified child element is visible within the container.
element (element): The child element to check for visibilityboolean true if its visible, otherwise falselocal main = basalt.getMainFrame()
local button = main:addButton()
local isVisible = main:isChildVisible(button)local main = basalt.getMainFrame()
local button = main:addButton()
local isVisible = main:isChildVisible(button)Forces an update of the render-data for all child elements within the container. Elements won't re-render if nothing has changed, this would force them to re-render.
selflocal main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()Returns the specified child element within the container.
string id - The ID of the element.element The specified child element.local main = basalt.getMainFrame()
main:addButton("Button1")
-- some code
local button = main:getChild("Button1")local main = basalt.getMainFrame()
main:addButton("Button1")
-- some code
local button = main:getChild("Button1")Adds a child element to the container.
element The child element to add.element The element in use.local main = basalt.getMainFrame()
local button = basalt.create("Button1", nil, "Button")
main:addChild(button)local main = basalt.getMainFrame()
local button = basalt.create("Button1", nil, "Button")
main:addChild(button)Removes a child element from the container.
element The child element to remove.self The container itselflocal main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild(button)local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild(button)Checks if a certain event is registered for a child
string The name of the event to check.boolean Indicates whether the event is registered for a childlocal main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild("mouse_click")local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild("mouse_click")Adds an event for a child. This will tell the container to send certain events to a children element.
WARNING
Basalt automatically registers children events for you.
string The name of the event to add.self The container itself.local main = basalt.getMainFrame()
local button = main:addButton()
main:addEvent("mouse_scroll") -- Button will start to listen to mouse_scroll events, but there is no mouse_scroll handler for buttons.local main = basalt.getMainFrame()
local button = main:addButton()
main:addEvent("mouse_scroll") -- Button will start to listen to mouse_scroll events, but there is no mouse_scroll handler for buttons.Removes an event from the container, bound to a child.
string The name of the event to remove.element The child element.self The container itself.local main = basalt.getMainFrame()
local button = main:addButton()
main:removeEvent("mouse_click", button) -- button stops listening to click eventslocal main = basalt.getMainFrame()
local button = main:addButton()
main:removeEvent("mouse_click", button) -- button stops listening to click eventsReturns all visible children of the container for a certain event.
string The name of the event.self The container itself.local main = basalt.getMainFrame()
local childrenWithClickEvent = main:getVisibleChildrenEvents("mouse_click")local main = basalt.getMainFrame()
local childrenWithClickEvent = main:getVisibleChildrenEvents("mouse_click")Updates the z-position of a specific child element. If certain elements have the same z-position, this method will remove and re-add the specific element in the same z-index table.
string|element The child element to update.self The container itself.local main = basalt.getMainFrame()
local button1 = main:addButton()
local button2 = main:addButton()
main:updateChild(button1)local main = basalt.getMainFrame()
local button1 = main:addButton()
local button2 = main:addButton()
main:updateChild(button1)Sets the cursor position within the container. This method is used by input or textfield elements.
boolean If the cursor should be active.number? The x-coordinate of the cursor.number? The x-coordinate of the cursor.color? The color of the cursor.self The container itself.local main = basalt.getMainFrame()
main:setCursor(true, 2, 2, colors.red)local main = basalt.getMainFrame()
main:setCursor(true, 2, 2, colors.red)Adds a specific type of element (e.g., addButton, addFrame, addInput, addLabel) to the container.
string|table The name of the element or a table containing default properties.self The container itself.local main = basalt.getMainFrame()
local button1 = main:addButton("Button1")
local button2 = main:addButton({name="Button2",x=3,y=4,width=16,height=3,text="Click me!"})local main = basalt.getMainFrame()
local button1 = main:addButton("Button1")
local button2 = main:addButton({name="Button2",x=3,y=4,width=16,height=3,text="Click me!"})