Container
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
Properties
| 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
| 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. |
getVisibleChildren
Returns a table containing all visible child elements within the container.
Returns
tablevisible children
Click to see example
local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()isChildVisible
Checks whether the specified child element is visible within the container.
Parameters
element(element): The child element to check for visibility
Returns
booleantrue if its visible, otherwise false
Usage
Click to see example
local main = basalt.getMainFrame()
local button = main:addButton()
local isVisible = main:isChildVisible(button)forceVisibleChildrenUpdate
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.
Returns
self
Usage
Click to see example
local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()getChild
Returns the specified child element within the container.
Parameters
stringid - The ID of the element.
Returns
elementThe specified child element.
Usage
Click to see example
local main = basalt.getMainFrame()
main:addButton("Button1")
-- some code
local button = main:getChild("Button1")addChild
Adds a child element to the container.
Parameters
elementThe child element to add.
Returns
elementThe element in use.
Usage
Click to see example
local main = basalt.getMainFrame()
local button = basalt.create("Button1", nil, "Button")
main:addChild(button)removeChild
Removes a child element from the container.
Parameters
elementThe child element to remove.
Returns
selfThe container itself
Usage
Click to see example
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild(button)isEventRegistered
Checks if a certain event is registered for a child
Parameters
stringThe name of the event to check.
Returns
booleanIndicates whether the event is registered for a child
Click to see example
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild("mouse_click")addEvent
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.
Parameters
stringThe name of the event to add.
Returns
selfThe container itself.
Click to see example
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.removeEvent
Removes an event from the container, bound to a child.
Parameters
stringThe name of the event to remove.elementThe child element.
Returns
selfThe container itself.
Click to see example
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeEvent("mouse_click", button) -- button stops listening to click eventsgetVisibleChildrenEvents
Returns all visible children of the container for a certain event.
Parameters
stringThe name of the event.
Returns
selfThe container itself.
Click to see example
local main = basalt.getMainFrame()
local childrenWithClickEvent = main:getVisibleChildrenEvents("mouse_click")updateChild
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.
Parameters
string|elementThe child element to update.
Returns
selfThe container itself.
Click to see example
local main = basalt.getMainFrame()
local button1 = main:addButton()
local button2 = main:addButton()
main:updateChild(button1)setCursor
Sets the cursor position within the container. This method is used by input or textfield elements.
Parameters
booleanIf 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.
Returns
selfThe container itself.
Click to see example
local main = basalt.getMainFrame()
main:setCursor(true, 2, 2, colors.red)add{Element}
Adds a specific type of element (e.g., addButton, addFrame, addInput, addLabel) to the container.
Parameters
string|tableThe name of the element or a table containing default properties.
Returns
selfThe container itself.
Click to see example
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!"})