▣
module · drop-in viewer
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 }`.
by·posted 2mo ago
What it does
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
anchordecoder only resolves at the screen root. marginis injected intoprops.margin;anchorintoprops.anchor.opts.propsis mutated in place — pass a fresh table if you reuse it across calls.- Single-child
children(a single widget node) is normalised bynode, so callers don't need to wrap a single child in{ ... }.
Discussion
Scoped to this part · feeds back into the world's score.
Sign in to post.sign in
No comments yet. Be the first.