Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

anchor

Corners a child to a screen edge. Root-only — must be the top-level widget of its registered screen. anchor is one of TopLeft / TopCenter / TopRight / CenterLeft / Center / CenterRight / BottomLeft / BottomCenter / BottomRight. margin is { top, right, bottom, left }.

Exports

This module returns the widget factory directly. There is no returned table.

  • anchor(anchor: AnchorPos, margin: Margin, children: { Node }?, opts: AnchorOpts?) -> Node — build an anchor widget node.

Types:

  • AnchorPos = "TopLeft" | "TopCenter" | "TopRight" | "CenterLeft" | "Center" | "CenterRight" | "BottomLeft" | "BottomCenter" | "BottomRight"
  • Margin = { number } — { top, right, bottom, left }.
  • Node = { [string]: any } — opaque widget node.
  • AnchorOpts = { id: string?, props: { [string]: any }?, style: { [string]: any }? }

Usage

local anchor = require("@builtin::modules.zui.widget.anchor")

local closeBtn = anchor("BottomRight", { 0, 16, 16, 0 }, {
    Z.btn("Close", { onClick = "close" }),
})
ui.registerScreen("close", closeBtn)

Notes

  • The widget MUST be the top-level node of its registered screen — the engine's anchor decoder only resolves at the screen root.
  • margin is injected into props.margin; anchor into props.anchor. opts.props is mutated in place — pass a fresh table if you reuse it across calls.
  • Single-child children (a single widget node) is normalised by node, so callers don't need to wrap a single child in { ... }.