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

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

PropertyTypeDescription
childrentableA list containing all child elements within the container.
childrenByNametableA mapping of child elements by their respective names.
childrenEventstableA collection of events associated with child elements.
cursorBlinkboolIndicates if the cursor blinks when a container is focused.
cursorColorcolorThe color of the cursor within the container.
cursorXnumberThe X-coordinate of the cursor within the container.
cursorYnumberThe Y-coordinate of the cursor within the container.
focusedChildelementThe currently focused child element within the container.
elementsSortedboolIndicates if the child elements in the container are sorted.
xOffsetnumberHorizontal offset for positioning child elements within the container.
yOffsetnumberVertical offset for positioning child elements within the container.

Methods

MethodsReturnsDescription
getVisibleChildrentableReturns a table containing all visible child elements within the container.
isChildVisiblebooleanReturns a boolean value indicating whether the specified child element is visible within the container.
forceVisibleChildrenUpdateselfForces to update all child elements within the container.
getChildelementReturns the specified child element within the container.
addChildselfAdds a child element to the container.
removeChildselfRemoves a child element from the container.
isEventRegisteredselfChecks if a certain event is registered for a child.
addEventselfAdds an event for a child.
removeEventselfRemoves an event from the container, bound to a child.
getVisibleChildrenEventstableReturns all visible children of the container for a certain event.
updateChildselfUpdates the z-position of a specific child element.
setCursorselfSets the cursor position within the container.
add{Element}elementAdds a specific type of element (e.g., addButton, addFrame, addInput, addLabel) to the container.
',7),d={id:"getvisiblechildren",tabindex:"-1"},h=a("a",{class:"header-anchor",href:"#getvisiblechildren","aria-label":'Permalink to "getVisibleChildren "'},"​",-1),y=e(`

Returns a table containing all visible child elements within the container.

Returns

  1. table visible children
Click to see example
lua
local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()
local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()
`,4),E={id:"ischildvisible",tabindex:"-1"},u=a("a",{class:"header-anchor",href:"#ischildvisible","aria-label":'Permalink to "isChildVisible "'},"​",-1),m=e(`

Checks whether the specified child element is visible within the container.

Parameters

  1. element (element): The child element to check for visibility

Returns

  1. boolean true if its visible, otherwise false

Usage

Click to see example
lua
local 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)
`,7),b={id:"forcevisiblechildrenupdate",tabindex:"-1"},C=a("a",{class:"header-anchor",href:"#forcevisiblechildrenupdate","aria-label":'Permalink to "forceVisibleChildrenUpdate "'},"​",-1),_=e(`

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

  1. self

Usage

Click to see example
lua
local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()
local main = basalt.getMainFrame()
main:addButton()
local visibleChildren = main:getVisibleChildren()
`,5),F={id:"getchild",tabindex:"-1"},g=a("a",{class:"header-anchor",href:"#getchild","aria-label":'Permalink to "getChild "'},"​",-1),v=e(`

Returns the specified child element within the container.

Parameters

  1. string id - The ID of the element.

Returns

  1. element The specified child element.

Usage

Click to see example
lua
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")
`,7),f={id:"addchild",tabindex:"-1"},k=a("a",{class:"header-anchor",href:"#addchild","aria-label":'Permalink to "addChild "'},"​",-1),B=e(`

Adds a child element to the container.

Parameters

  1. element The child element to add.

Returns

  1. element The element in use.

Usage

Click to see example
lua
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)
`,7),A={id:"removechild",tabindex:"-1"},T=a("a",{class:"header-anchor",href:"#removechild","aria-label":'Permalink to "removeChild "'},"​",-1),q=e(`

Removes a child element from the container.

Parameters

  1. element The child element to remove.

Returns

  1. self The container itself

Usage

Click to see example
lua
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild(button)
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild(button)
`,7),P={id:"iseventregistered",tabindex:"-1"},D=a("a",{class:"header-anchor",href:"#iseventregistered","aria-label":'Permalink to "isEventRegistered "'},"​",-1),x=e(`

Checks if a certain event is registered for a child

Parameters

  1. string The name of the event to check.

Returns

  1. boolean Indicates whether the event is registered for a child
Click to see example
lua
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild("mouse_click")
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeChild("mouse_click")
`,6),V={id:"addevent",tabindex:"-1"},R=a("a",{class:"header-anchor",href:"#addevent","aria-label":'Permalink to "addEvent "'},"​",-1),S=e(`

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

  1. string The name of the event to add.

Returns

  1. self The container itself.
Click to see example
lua
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.
`,7),I={id:"removeevent",tabindex:"-1"},w=a("a",{class:"header-anchor",href:"#removeevent","aria-label":'Permalink to "removeEvent "'},"​",-1),M=e(`

Removes an event from the container, bound to a child.

Parameters

  1. string The name of the event to remove.
  2. element The child element.

Returns

  1. self The container itself.
Click to see example
lua
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeEvent("mouse_click", button) -- button stops listening to click events
local main = basalt.getMainFrame()
local button = main:addButton()
main:removeEvent("mouse_click", button) -- button stops listening to click events
`,6),N={id:"getvisiblechildrenevents",tabindex:"-1"},U=a("a",{class:"header-anchor",href:"#getvisiblechildrenevents","aria-label":'Permalink to "getVisibleChildrenEvents "'},"​",-1),z=e(`

Returns all visible children of the container for a certain event.

Parameters

  1. string The name of the event.

Returns

  1. self The container itself.
Click to see example
lua
local main = basalt.getMainFrame()
local childrenWithClickEvent = main:getVisibleChildrenEvents("mouse_click")
local main = basalt.getMainFrame()
local childrenWithClickEvent = main:getVisibleChildrenEvents("mouse_click")
`,6),$={id:"updatechild",tabindex:"-1"},O=a("a",{class:"header-anchor",href:"#updatechild","aria-label":'Permalink to "updateChild "'},"​",-1),W=e(`

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

  1. string|element The child element to update.

Returns

  1. self The container itself.
Click to see example
lua
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)
`,6),H={id:"setcursor",tabindex:"-1"},L=a("a",{class:"header-anchor",href:"#setcursor","aria-label":'Permalink to "setCursor "'},"​",-1),X=e(`

Sets the cursor position within the container. This method is used by input or textfield elements.

Parameters

  1. boolean If the cursor should be active.
  2. number? The x-coordinate of the cursor.
  3. number? The x-coordinate of the cursor.
  4. color? The color of the cursor.

Returns

  1. self The container itself.
Click to see example
lua
local main = basalt.getMainFrame()
main:setCursor(true, 2, 2, colors.red)
local main = basalt.getMainFrame()
main:setCursor(true, 2, 2, colors.red)
`,6),Y={id:"add-element",tabindex:"-1"},G=a("a",{class:"header-anchor",href:"#add-element","aria-label":'Permalink to "add\\{Element\\} "'},"​",-1),J=e(`

Adds a specific type of element (e.g., addButton, addFrame, addInput, addLabel) to the container.

Parameters

  1. string|table The name of the element or a table containing default properties.

Returns

  1. self The container itself.
Click to see example
lua
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!"})
`,6);function Q(j,K,Z,ss,as,es){const n=t("C");return p(),r("div",null,[i,a("h2",d,[s("getVisibleChildren "),l(n,{content:"getVisibleChildren"}),s(),h]),y,a("h2",E,[s("isChildVisible "),l(n,{content:"getVisibleChildren"}),s(),u]),m,a("h2",b,[s("forceVisibleChildrenUpdate "),l(n,{content:"forceVisibleChildrenUpdate"}),s(),C]),_,a("h2",F,[s("getChild "),l(n,{content:"getChild"}),s(),g]),v,a("h2",f,[s("addChild "),l(n,{content:"addChild"}),s(),k]),B,a("h2",A,[s("removeChild "),l(n,{content:"removeChild"}),s(),T]),q,a("h2",P,[s("isEventRegistered "),l(n,{content:"isEventRegistered"}),s(),D]),x,a("h2",V,[s("addEvent "),l(n,{content:"addEvent"}),s(),R]),S,a("h2",I,[s("removeEvent "),l(n,{content:"removeEvent"}),s(),w]),M,a("h2",N,[s("getVisibleChildrenEvents "),l(n,{content:"getVisibleChildrenEvents"}),s(),U]),z,a("h2",$,[s("updateChild "),l(n,{content:"updateChild"}),s(),O]),W,a("h2",H,[s("setCursor "),l(n,{content:"setCursor"}),s(),L]),X,a("h2",Y,[s("add{Element} "),l(n,{content:"addButton"}),s(),G]),J])}const os=o(c,[["render",Q]]);export{ls as __pageData,os as default};