Skip to content

Container

extends Element

Container: an element that owns and renders child elements.

Types

ContainerScrollbarMode

lua
ContainerScrollbarMode = "auto"|"always"|"hidden"

ContainerScrollbarGeometry

FieldTypeDescription
showXbooleanWhether the horizontal scrollbar is visible
showYbooleanWhether the vertical scrollbar is visible
horizontalLengthnumberHorizontal scrollbar track length
verticalLengthnumberVertical scrollbar track length
horizontalThumbSizenumberHorizontal thumb size
horizontalThumbPosnumberHorizontal thumb offset
verticalThumbSizenumberVertical thumb size
verticalThumbPosnumberVertical thumb offset
maxXnumberMaximum horizontal scroll offset
maxYnumberMaximum vertical scroll offset

ContainerScrollInfo

extends ContainerScrollbarGeometry

FieldTypeDescription
xnumberCurrent horizontal scroll offset
ynumberCurrent vertical scroll offset
contentWidthnumberLaid-out content width
contentHeightnumberLaid-out content height

Properties

PropertyTypeDefaultDescription
scrollablebooleanfalseEnables content scrolling for this container
scrollbarContainerScrollbarMode"auto""auto", "always" or "hidden"
scrollXEnabledbooleantrueAllow horizontal scrolling
scrollYEnabledbooleantrueAllow vertical scrolling
scrollStepnumber3Cells scrolled per mouse wheel tick
scrollbarColornumbercolors.grayScrollbar track color
scrollbarThumbColornumbercolors.lightGrayScrollbar thumb color

Events

EventRegistrarDescription
scrollChange:onScrollChange(fn)Fired when the scroll offset changes, with (x, y)

Methods

Container:setup()

Initializes per-instance state and input handlers.

Container:getScroll()

Returns the current horizontal and vertical scroll offsets.

  • returns x (number)
  • returns y (number)

Container:getContentSize()

Returns cached content bounds after the latest layout pass.

  • returns width (number)
  • returns height (number)

Container:getScrollInfo()

Returns scrollbar visibility, ranges, offsets and content size.

  • returns info (ContainerScrollInfo)

Container:scrollTo(x, y)

Scrolls to absolute content offsets.

  • x (number, optional) Horizontal offset, default 0

  • y (number, optional) Vertical offset, default 0

  • returns (self)

Container:scrollBy(dx, dy)

Scrolls relative to the current offsets.

  • dx (number, optional) Horizontal delta, default 0

  • dy (number, optional) Vertical delta, default 0

  • returns (self)

Container:scrollToElement(el)

Aligns a descendant's top-left corner with the viewport.

  • el (Element) Descendant element

  • returns (self)

Container:ensureVisible(el)

Applies the smallest scroll needed to reveal a descendant.

  • el (Element) Descendant element

  • returns (self)

Container:addChild(child)

Attaches an existing element as the final child.

  • child (T) Element to attach

  • returns child (T)

Container:removeChild(child)

Detaches a direct child and releases its interaction state.

  • child (Element) Child to remove

  • returns removed (boolean)

Container:destroy()

Recursively destroys every descendant before detaching this container. This is important for stateful children such as Program: merely removing their parent frame would otherwise leave their scheduled coroutines alive.

  • returns (self)

Container:getChildren()

Returns the live direct-child array.

  • returns children (Element[])

Container:find(childName)

Finds a descendant element by its name property (depth-first).

  • childName (string) Element name

  • returns element (Element|nil)

Container:render(buf)

Renders the element into the buffer.

  • buf (Render) The render buffer (local coordinates, pre-clipped)

Container:handleMouse(event, btn, x, y)

Routes a mouse event to children (topmost first), falling back to self.

  • event (string) Mouse event name

  • btn (number) Mouse button or scroll direction

  • x (number) Local x coordinate

  • y (number) Local y coordinate

  • returns consumer (Element|nil) The consuming element, or nil

Container:findAt(x, y)

Returns the deepest visible element at a point, regardless of handlers.

  • x (number) Local x coordinate

  • y (number) Local y coordinate

  • returns element (Element)

Container.register(elementName, elementClass)

Registers an element class: creates Container:add<Name>(props).

  • elementName (string) Public element name
  • elementClass ({ new: fun(props?: table): T }) Element class

Last updated:

Released under the MIT License.