# _axes
Shared tick generation + axes + gridline drawing helpers for
canvas-hosted charts. Used by `Z.plot` for axes/gridlines/ticks and by
`Z.graph` for the optional axis labels + gridlines. Single source of
truth for the nice-tick algorithm so both widgets render identical-
looking tick scales. Underscore prefix marks it as a package-internal
helper — not exported from `zui.widget` and not part of the `Z.*`
surface.
## Exports
- `M.computeTicks(minV: number, maxV: number, nTicks: number?, customFormat: TickFormatter?) -> TickResult` — D3-style nice ticks. Snaps step to `{1, 2, 5} × 10^n`. `nTicks` default 5.
- `M.axisCommands(viewport: Viewport, bounds: Bounds, opts: AxesOpts?) -> { CanvasCommand }` — axes + tick marks + tick labels.
- `M.gridCommands(viewport: Viewport, bounds: Bounds, opts: AxesOpts?) -> { CanvasCommand }` — gridlines, one per major tick.
Types:
- `Viewport = { x: number, y: number, width: number, height: number }` — canvas-local pixel rect.
- `Bounds = { xMin: number, xMax: number, yMin: number, yMax: number }` — data-space range.
- `TickResult = { ticks: { number }, labels: { string } }`
- `TickFormatter = (number) -> string` — custom label formatter.
- `AxesOpts` — visibility + styling (`showXAxis`, `axisColor`, `labelSize`,
`tickLength`, `xTickFormat`, etc.).
- `CanvasCommand = { [string]: any }` — opaque canvas-renderer command.
## Usage
```luau
local Axes = require("@builtin::modules.zui.widget._axes")
local viewport = { x = 0, y = 0, width = 200, height = 120 }
local bounds = { xMin = 0, xMax = 100, yMin = 0, yMax = 1 }
local axisCmds = Axes.axisCommands(viewport, bounds, {})
local gridCmds = Axes.gridCommands(viewport, bounds, { gridY = false })
local r = Axes.computeTicks(0, 100) -- nice ticks: {0, 20, 40, ...}
-- Custom formatter:
Axes.axisCommands(viewport, bounds, {
xTickFormat = function(v) return "$" .. v end,
})
```
## Notes
- Coordinate convention matches canvas: origin top-left, `+y` down. Y
values from `bounds` are flipped at render time so `yMax` is drawn at
the top of the viewport, matching plot conventions.
- `mergedOpts` overlays caller opts on `DEFAULTS` and passes unknown keys
through — additive opts (`xTickFormat`, `yTickFormat`, future ones)
don't need bookkeeping in `DEFAULTS`.
- `computeTicks` caps iteration at 64 ticks to avoid pathological loops
on degenerate input.
- Out-of-range ticks (after the data → pixel mapping) are filtered
silently so neither labels nor lines bleed past the viewport.
# _markers
Marker-shape canvas command generators used by `Z.plot.points`. Mirrors
the marker shapes that the deleted `egui_plot::MarkerShape` enum
exposed: `circle`, `square`, `diamond`, `cross`, `plus`, `up`, `down`,
`left`, `right`, `asterisk`. Unknown shapes fall back to circle with a
console warning (parity with the deleted Rust path).
## Exports
- `M.commands(shape: MarkerShape, cx: number, cy: number, radius: number, opts: MarkerOpts?) -> { CanvasCommand }` — list of canvas commands rendering the marker.
Types:
- `MarkerShape = "circle" | "square" | "diamond" | "cross" | "plus" | "up" | "down" | "left" | "right" | "asterisk" | string` — `string` fallthrough warns and falls back to circle.
- `MarkerOpts = { fill: string?, stroke: string?, strokeWidth: number? }`
- `CanvasCommand = { [string]: any }` — opaque canvas-renderer command.
## Usage
```luau
local Markers = require("@builtin::modules.zui.widget._markers")
local cmds = Markers.commands("diamond", 50, 50, 4, { fill = "#fff" })
-- cmds is a list of canvas commands ready to splice into a canvas.
```
## Notes
- Each shape returns one or more canvas commands centered at `(cx, cy)`
with bounding-circle radius `radius`.
- `cross`, `plus`, `asterisk`, `up/down/left/right` are stroke-based and
fall back to `opts.fill` (or `"#FFFFFF"`) for the line color when no
`stroke` is supplied.
- Unknown shapes warn via `log.warn` (when available) and fall back to
the circle marker — parity with the deleted Rust enum's default arm.
- Pure module — no engine state, no state owned here. Safe to call from
any context.
# _rowCanvas
Shared selectable-row factory used by `Z.radioGroup` and
`Z.selectableList`. Each row is a single focusable `canvas` widget that
draws its background + optional radio glyph + label in widget-local
coords. Because the whole row is one canvas (not a composition of
glyph-canvas + label + container with click handlers), Tab cycles
row-by-row naturally via egui's focus chain, click commits selection via
the canvas's `onClick` prop, and arrow keys reach the parent group's nav
handler via the canvas's `onKey` prop. Underscore prefix marks it as a
package-internal helper — not exported from `zui.widget` and not part of
the `Z.*` surface.
## Exports
This module returns the row factory function directly. There is no
returned table.
- `rowCanvas(opts: RowOpts?) -> Node` — build a selectable-row canvas node.
Types:
- `RowOpts = { groupId?: string, index?: number, label?: string,
selected?: boolean, kind?: "radio" | "option", width?: number,
height?: number, bg?: string, fg?: string, selectedBg?: string,
selectedFg?: string }`
- `Node = { [string]: any }` — opaque canvas widget node.
## Usage
```luau
local rowCanvas = require("@builtin::modules.zui.widget._rowCanvas")
return Z.vbox{
rowCanvas{ groupId = "themes", index = 1, label = "Dark", selected = true, kind = "radio" },
rowCanvas{ groupId = "themes", index = 2, label = "Light", selected = false, kind = "radio" },
}
```
## Notes
- Click commits selection via `onClick = <groupId>:select:<index>`; the
parent group's callback subscribes to that event.
- Arrow keys raise `onKey = <groupId>:nav` so the parent group handles
keyboard navigation in one place.
- The whole row is a single canvas — focus moves row-by-row through
egui's focus chain naturally (no manual focus management needed).
- DOM mirror sees `<canvas role="radio"|"option"
aria-selected="true|false">` via the generic `role` + `aria*`
pass-through on canvas.
- Defaults: `200 × 22` row, `"#00000000"` bg, `"#dcdcdc"` fg, selected
`"#3a4a64"` bg + `"#ffffff"` fg.
# _viewport
Pan/zoom viewport helper for canvas-hosted charts. Persists
`{ xMin, xMax, yMin, yMax }` in `ui.widgetState(plotId, "viewport")` so
the bounds survive across renders; the first render seeds from
`defaultBounds`. Subsequent renders read the cached state; pan/zoom
handlers (`viewport:pan`, `viewport:zoom`) mutate the state in place and
write it back to widgetState. Underscore prefix marks it as a
package-internal helper — not exported from `zui.widget` and not part of
the `Z.*` surface.
## Exports
- `Viewport.make(plotId: string?, rect: Rect?, defaultBounds: Bounds?) -> ViewportInstance` — construct a viewport over `rect`. `plotId` enables widgetState persistence.
- `vp:dataToScreen(x: number, y: number) -> (number, number)` — data → canvas-local pixels.
- `vp:screenToData(sx: number, sy: number) -> (number, number)` — canvas-local pixels → data.
- `vp:pan(dxScreen: number, dyScreen: number, axisAllow: AxisFilter?)` — pan and write-back.
- `vp:zoom(factor: number, anchorScreen: ScreenPoint?, axisAllow: AxisFilter?)` — zoom around anchor and write-back.
- `vp:setBounds(bounds: Bounds)` — replace bounds and write-back.
- `Viewport.bounds(vp) -> Bounds` — snapshot bounds as a fresh table.
Types:
- `Rect = { x: number, y: number, width: number, height: number }` — canvas-local plot body.
- `Bounds = { xMin: number, xMax: number, yMin: number, yMax: number }` — data-space.
- `ScreenPoint = { x: number, y: number }`
- `AxisFilter = { x: boolean?, y: boolean? }`
- `ViewportInstance` — instance shape; carries `rect`, bounds fields,
`invertX/Y`, and the bound methods.
## Usage
```luau
local Viewport = require("@builtin::modules.zui.widget._viewport")
local vp = Viewport.make("plot1",
{ x = 0, y = 0, width = 200, height = 100 },
{ xMin = 0, xMax = 100, yMin = 0, yMax = 1 })
-- Inside onDrag handler:
vp:pan(dragDx, dragDy)
-- Inside onScroll handler:
vp:zoom(1 + scrollAmount * 0.1, { x = mx, y = my })
-- Reset:
vp:setBounds({ xMin = 0, xMax = 100, yMin = 0, yMax = 1 })
```
## Notes
- Coordinate convention: origin top-left, `+y` down. yMax in data space
maps to `rect.y` (top of viewport) so the cursor sits above the data
point during pan.
- Persistence is opt-in — passing `plotId = nil` skips widgetState reads
/ writes; bounds live only on the instance for the duration of the
call.
- Caller can reset by clearing widgetState explicitly:
`ui.widgetStateSet(plotId, "viewport", nil)`.
- `Viewport.bounds(vp)` is a free function (no colon) — it's a thin
snapshot helper, useful when you want a fresh bounds table without
mutating the instance.
- `invertX` / `invertY` flip the axis mapping in both `dataToScreen` and
`screenToData`; default `false` for both.
# 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
```luau
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 `{ ... }`.
# area
Free-positioned area. Root-only — must be the top-level widget of its
registered screen. The `pos` field is at the widget root level (not
inside `props`) because that's what the engine's `area` decoder expects.
Pass `movable = true` to let the user drag the area; the dragged
position is held in egui's persistent memory.
## Exports
This module returns the widget factory directly. There is no returned
table.
- `area(children: { Node }?, opts: AreaOpts?) -> Node` — build a free-positioned area node.
Types:
- `Pos = { number }` — `{ x, y }` in screen pixels.
- `Pivot = string` — engine-defined anchor name (`"center"`, `"topleft"`, ...).
- `Node = { [string]: any }` — opaque widget node.
- `AreaOpts = { id: string?, pos: Pos?, pivot: Pivot?, movable: boolean?,
interactable: boolean?, style: { [string]: any }? }`
## Usage
```luau
local area = require("@builtin::modules.zui.widget.area")
local hud = area({
Z.btn("Drag me"),
}, {
pos = { 100, 100 },
movable = true,
interactable = true,
})
ui.registerScreen("draggable", hud)
```
## Notes
- The widget MUST be the top-level node of its registered screen.
- `pos`, `pivot`, `movable`, `interactable`, `style` are written at the
widget root level (NOT inside `props`) — the engine's `area` decoder
reads them from there.
- Lua-side read-back of dragged position for movable areas is a planned
Rust extension; today the dragged position is held in egui's persistent
memory and is not exposed back to Luau.
- Each `nil` field is omitted from the resulting node so the engine sees
only the fields the caller explicitly set.
# args
Shared argument resolver for zui container builders (`panel`, `vbox`, `hbox`, `grid`, …). Container builders historically took `(children, opts)` with children first, but the intuitive call is a single options table `Z.panel({ style = …, children = {…} })`. Passed to a `(children, opts)` builder, that table landed in the children slot and its `children` key was silently dropped. `resolve` removes that pit: it accepts every unambiguous shape and routes it correctly, and raises a precise error when a call is genuinely ambiguous instead of silently dropping content.
## Exports
- `resolve(builderName: string, a: any, b: any) -> ({ any }, { [string]: any })` — returns `(children, opts)` — an array of child widget tables (possibly empty) and an options table (possibly empty).
## Accepted shapes
```luau
resolve("panel", { childA, childB }, opts?) -- canonical array + opts
resolve("panel", singleChildNode, opts?) -- a lone widget (auto-wrapped)
resolve("panel", { style = …, children = {…} }) -- single options table
resolve("panel", { style = … }) -- options only (no children)
resolve("panel", nil, opts?) -- no children
```
## Errors (never silent)
- a children array that ALSO carries a `children` key
- an options-shaped first argument passed alongside a 2nd options argument
- `opts.children` that isn't an array
## Usage
```luau
local resolve = require("@builtin::modules.zui.widget.args")
local children, opts = resolve("panel", a, b)
```
# badge
Alias for chip — kept as its own module for vocabulary clarity. Pick
whichever name reads better at the call site; both compile to the same
widget under the hood.
## Exports
This module re-exports `modules.zui.widget.chip` directly. There are no
typed functions or types declared here — the public surface is whatever
`chip` exposes.
- `badge(...) -> Node` — identical to `chip(...)`.
## Usage
```luau
local badge = require("@builtin::modules.zui.widget.badge")
local newBadge = badge("New", { variant = "info" })
```
## Notes
- This module is a thin re-export — `badge == chip` (same function
reference). Hot-reloading either reloads both.
- See `modules.zui.widget.chip` for the full argument / option surface
and type signature.
- The alias exists purely so call sites can say `badge` when that reads
better (e.g. "new feature" badge) and `chip` when that reads better
(e.g. a removable tag chip). There is no behavioural difference.
# bottomPanel
Bottom-docked panel. Root-only — must be the top-level widget of its
registered screen. Pairs with `centralPanel` (and optionally `topPanel` /
`leftPanel` / `rightPanel`) for a docked app shell — register each as
its own screen with appropriate layer ordering.
## Exports
This module returns the widget factory directly. There is no returned
table.
- `bottomPanel(children: { Node }?, opts: PanelOpts?) -> Node` — build a bottom-docked panel node.
Types:
- `Node = { [string]: any }` — opaque widget node.
- `PanelOpts = { id: string?, classes: ({ string } | string)?,
class: ({ string } | string)?, props: { [string]: any }?,
style: { [string]: any }? }`
## Usage
```luau
local bottomPanel = require("@builtin::modules.zui.widget.bottomPanel")
local statusBar = bottomPanel({
Z.hbox{ Z.lbl("Status: OK"), Z.flex(), Z.lbl("v0.1.0") },
}, { id = "status" })
ui.registerScreen("statusBar", statusBar)
```
## Notes
- Root-only — the widget MUST be the top-level node of its registered
screen.
- Children can be a single Node or an array; `node` normalises a single
child to `{ child }` so callers don't have to wrap manually.
- `classes` / `class` accept either an array of strings or a single
space-separated string — `node` normalises both forms.
- Pairs with the other panel widgets for a docked app shell; register
each on its own screen so layer ordering / visibility can be controlled
independently.
# button
Clickable button widget. Emits a callback id (string) routed by the
engine to `component.onCallback`, or wires up a closure when called
inside a `Z.app` builder. Accepts top-level style shortcuts (bg,
color, fontSize, bold, padding, border, borderWidth, minWidth,
minHeight, tooltip, enabled).
## Exports
- `button(text: string?, callbackId: any?, opts: ButtonOpts?) -> WidgetNode` — build a button widget node. The 2nd arg may be a string callback id, a closure (auto-wired in `Z.app`), or an options table when no 3rd argument is provided.
Types:
- `ButtonOpts = { id?, classes?, class?, style?, onClick?, bg?, color?, fontSize?, bold?, padding?, border?, borderWidth?, minWidth?, minHeight?, tooltip?, enabled?, paint? }`
## Usage
```luau
local btn = require("@builtin::modules.zui.widget.button")
btn("Save", "save:click") -- string callback id
btn("Save", function() print("clicked") end) -- closure (inside Z.app)
btn("Save", { onClick = "save:click", bg = "#222" }) -- JS-style opts shape
```
## Notes
- Passing a closure outside a `Z.app` builder errors at builder time — closures can't cross the Luau↔Rust FFI boundary, so they only auto-wire inside an app router.
- The 2-arg `Z.btn(text, opts)` shape is supported: if slot 2 is a table and slot 3 is missing, the callback is pulled from `opts.onClick`. Guards against the silent-dead-button bug tracked by #3059.
- See `docs/guides/zui-cheatsheet.md` for the three callback patterns.
# canvas
Immediate-mode 2D-paint widget. The body is a sequence of paint
commands (`line`, `bezier`, `polyline`, `rect`, `circle`, `text`)
drawn in widget-local coordinates with origin at the top-left and +y
going down (egui-standard, opposite of plot). Wires through pointer,
drag, double-click, key, and scroll handlers, and forwards `role` /
`tag` / `aria*` props for accessibility.
## Exports
- `canvas(id: string?, opts: CanvasOpts?) -> WidgetNode` — build a canvas widget node from a list of paint commands plus optional interaction handlers.
Types:
- `CanvasOpts = { commands?, width?, height?, onClick?, onPointerDown?, onPointerUp?, onPointerMove?, onDrag?, onDoubleClick?, onKey?, onScroll?, role?, tag?, style?, class?, classes? }`
## Usage
```luau
local canvas = require("@builtin::modules.zui.widget.canvas")
canvas("my-canvas", {
commands = {
{ kind = "line", a = {10,10}, b = {200,150}, color = "#7AA8FF", width = 2 },
{ kind = "circle", center = {100,100}, radius = 30, fill = "#FF8855" },
{ kind = "text", pos = {10,180}, text = "hello", color = "#fff", fontSize = 14 },
},
onClick = "canvas:click",
style = { width = 600, height = 400, background = "#161B22" },
})
```
## Notes
- Pointer events surface widget-local cursor coords as either a `"x,y"` string (legacy) or a structured Luau table (modern handlers).
- `onClick` / `onPointerDown` / `onPointerUp` carry `data.button` (0 = left, 1 = right, 2 = middle) identifying which mouse button triggered the event.
- `onKey` fires only while the canvas has keyboard focus; `onScroll` fires while it is hovered.
- Any `opts.aria*` key passes through verbatim — no wrapper-side allowlist needed.
- Command kinds and per-kind fields are defined in `crates/zero_ui_protocol/src/canvas.rs`.
# card
Card composite — title + description + optional image placeholder +
arbitrary children inside a styled panel, built from `panel` + `label`
primitives. Pure Luau composition; the engine has no dedicated `card`
arm.
## Exports
- `card(opts: CardOpts?) -> WidgetNode` — build a card widget node.
Types:
- `CardOpts = { id?, classes?, class?, title?, titleColor?, description?, descriptionColor?, image?, children?, bg?, border?, borderWidth?, padding?, gap? }`
## Usage
```luau
local card = require("@builtin::modules.zui.widget.card")
card({
title = "Card title",
description = "muted secondary text",
image = "asset/path", -- optional 100px tall placeholder bar
children = { ... }, -- arbitrary widgets below
id = "myCard",
padding = 8,
})
```
## Notes
- Click handling is not exposed directly — wrap in a clickable wrapper (e.g. an outer `Z.btn` with empty text) if needed.
- The image slot currently renders a `panel_alt`-coloured placeholder rect; once an image-loader pipeline lands, callers can pass a real `Z.image` instead.
- Theme defaults (`panel`, `border`, `text`, `text_dim`) come from `modules.zui.theme`'s `default` table.
# centralPanel
Central panel that fills the area not consumed by the docked edge
panels. Root-only — must be the body of a docked-shell layout, with
edge panels (e.g. `topPanel`, `bottomPanel`, `leftPanel`, `rightPanel`)
docked around it.
## Exports
- `centralPanel(children: { any }?, opts: { [string]: any }?) -> WidgetNode` — build a centralPanel widget node wrapping the given children.
## Usage
```luau
local centralPanel = require("@builtin::modules.zui.widget.centralPanel")
centralPanel({
heading("Body"),
-- ...
})
```
## Notes
- Root-only — the renderer expects it at the top level of a screen, alongside any docked edge panels.
- Passes `opts` straight through to the underlying `node` constructor; no widget-specific shortcuts.
# checkbox
Check-mark style boolean input with a trailing label.
## Exports
- `checkbox(label: string?, id: string?, checked: any?, opts: CheckboxOpts?) -> WidgetNode` — build a checkbox widget node.
Types:
- `CheckboxOpts = { props?, onChange?, style? }`
## Usage
```luau
local checkbox = require("@builtin::modules.zui.widget.checkbox")
checkbox("Enabled", "cb1", true, { onChange = "cb1:change" })
```
## Notes
- Initial `checked` is coerced via `value == true` — anything that isn't strictly `true` becomes `false`.
- `onChange` receives a `ValueChanged(boolean)` event when the user toggles the box.
# chip
Compact tag/badge. Variants (`"info"`, `"success"`, `"warning"`,
`"error"`) pick a foreground/background colour pair from the active
theme. Built as a `panel + label` composition so the engine has no
dedicated arm for what is fundamentally a coloured rounded text-box.
## Exports
- `chip(text: string?, opts: ChipOpts?) -> WidgetNode` — build a chip widget node.
Types:
- `ChipVariant = "info" | "success" | "warning" | "warn" | "error" | "danger"`
- `ChipOpts = { id?, variant?, bg?, color?, fontSize?, padding?, borderRadius? }`
## Usage
```luau
local chip = require("@builtin::modules.zui.widget.chip")
chip("New", { variant = "success" })
chip("Beta", { bg = "#222", color = "#fff" })
```
## Notes
- `bg` and `color` per-call override the variant-selected colours.
- Defaults: `fontSize = 11`, `padding = { 1, 6, 1, 6 }`, `borderRadius = 4`.
- Colours pull from `Theme.default` (`success`, `warn`, `danger`, `info`, `bg_deep`).
# codeEditor
Code-editing variant of `input`. Defaults `multiline = true`,
`codeEditor = true`, `language = "lua"`, `lineNumbers = true`. The
`language` opt dispatches to a Luau highlighter from `zui.highlight.*`;
the resulting segments are passed to TextInput as `props.segments` so
the renderer builds a coloured LayoutJob without a Rust-side
highlighter call.
## Exports
- `codeEditor(id: string?, value: any?, opts: CodeEditorOpts?) -> WidgetNode` — build a code-editor widget node.
Types:
- `CodeEditorOpts = { multiline?, codeEditor?, lineNumbers?, folding?, language?, foldLanguage?, segments?, ... }` — accepts any opts the underlying `input` widget supports.
## Usage
```luau
local codeEditor = require("@builtin::modules.zui.widget.codeEditor")
codeEditor("editor1", "local x = 1\n", { language = "lua" })
codeEditor("editor1", code, { language = "lua", folding = true })
```
## Notes
- Folding is opt-in via `folding = true`. When combined with `language = "lua"`, the wrapper sets `foldLanguage = "lua"` so the gutter UI runs the Rust-side fold detector on the editor's live text. Other languages can't fold (no detector implemented yet).
- `opts.language` is consumed by the wrapper and never reaches `input.module`; the highlighter output lands in `opts.segments` instead.
- The engine's built-in highlighters have been deleted — language→segments mapping lives entirely in Luau.
# collapsible
Collapsible section with a header bar. Click the header to expand or
collapse the children. Controlled by Luau — the wrapper auto-stashes
open/closed state via `ui.widgetState(id, "open")` and registers a
one-time click handler with the surrounding `Z.app` so existing demos
that pass `defaultOpen = true` keep working unchanged.
## Exports
- `collapsible(header: any?, children: { any }?, opts: CollapsibleOpts?) -> WidgetNode` — build a collapsible widget node with the supplied header and children.
Types:
- `CollapsibleOpts = { id?, props?, style?, defaultOpen?, app? }`
## Usage
```luau
local collapsible = require("@builtin::modules.zui.widget.collapsible")
collapsible(label("Advanced"), {
-- collapsible children here
}, { id = "advanced-section", defaultOpen = false })
```
## Notes
- Inside `Z.app`: state is auto-managed via `ui.widgetState` + a one-time `app:on` handler keyed off `id`.
- Outside `Z.app`: falls back to a static render keyed off `defaultOpen`; the caller must drive `props.open` and react to `ValueChanged(new_open)` themselves.
- State APIs are flat top-level FFI functions — `ui.widgetState(id, key)` and `ui.widgetStateSet(id, key, value)`, **not** `ui.widgetState.set`.
- `id` is required for cross-frame state to persist. Without an id, the widget renders but the toggle won't reflect — the wrapper logs no warning, just degrades gracefully.
# colorSwatch
Click-only coloured swatch — a small (default 24×24) coloured rect
with a white border. Used as a click target for material chips,
palette swatches, or any visual indicator that doubles as a click
target. Implemented as an empty-text `button` so the engine has no
dedicated arm.
## Exports
- `colorSwatch(color: any?, callbackId: any?, opts: ColorSwatchOpts?) -> WidgetNode` — build a coloured-swatch widget node.
Types:
- `ColorSwatchOpts = { id?, size?, style?, border?, borderWidth?, tooltip? }`
## Usage
```luau
local colorSwatch = require("@builtin::modules.zui.widget.colorSwatch")
colorSwatch("#ff8855", "swatch:click", { id = "row5" })
colorSwatch("#5588ff", "pick", { size = 32, tooltip = "Pick blue" })
```
## Notes
- Defaults: `size = 24`, `border = "#ffffff"`, `borderWidth = 1`, `borderRadius = 4`, `padding = 0`.
- Click handling reuses the button widget — same callback-id semantics, same closure auto-wiring inside `Z.app`.
- Per-swatch routing pattern: encode the swatch identity into the callback id (e.g. `"swatch-" .. hex`) and match with `app:on("^swatch%-(.+)$", ...)`.
# contextMenu
Convenience wrapper over `Z.popup` for the context-menu pattern — a
popup pinned to a widget you typically open on right-click. Same
ordering constraint as `Z.popup`: the anchor must render before the
menu in tree order.
## Exports
- `contextMenu(anchorId: string?, items: { any }?, opts: ContextMenuOpts?) -> WidgetNode` — build a context-menu popup attached to the anchor widget.
Types:
- `ContextMenuOpts = { id?, open?, onDismiss?, pivot?, focusable?, style? }`
## Usage
```luau
local contextMenu = require("@builtin::modules.zui.widget.contextMenu")
-- in your Z.app builder:
Z.btn("Item", "row1"), -- anchor
Z.contextMenu("row1", {
Z.btn("Cut", "ctx:cut"),
Z.btn("Copy", "ctx:copy"),
Z.btn("Paste", "ctx:paste"),
}, { open = menuOpen, onDismiss = "ctx:dismiss" })
```
## Notes
- Wave 3 ships caller-managed `open` state. Right-click sensing on interactive widgets (and self-toggling menus) is future work — for now, drive `open` yourself in `onClick` / `onCallback` handlers.
- Default pivot is `"belowLeft"`.
- The wrapper is a thin pass-through; any popup-supported field can be reached by adding it to the surrounding popup directly if needed.
# dataView
Filterable, multi-selectable data list bound to a named
`modules.api.editor.selection` scope. `props.mode` ("list" | "table" |
"grid", default "list") selects the rendering strategy:
- **list** — one focusable canvas row per visible item (icon + label +
badge) inside a virtualized `scrollArea`.
- **table** — the same focusable-row shape extended to multiple
columns, with a sortable header.
- **grid** — a wrapping `Z.grid` of selectable thumbnail cells, for
asset browsers.
## Exports
- `dataView(props: Props?) -> any` — build a DataView widget. The
module returns this function directly.
Types:
- `Props = { id: string?, items: { any }?, key: ((any) -> string)?, row: ((any) -> RowSpec)?, selection: Scope?, onActivate: string?, filter: string?, rowHeight: number?, rowWidth: number?, maxHeight: number?, mode: string?, app: any?, columns: { ColumnSpec }?, gridColumns: number?, commands: { string }? }`
- `RowSpec = { label: string, icon: string?, badge: string?, columns: { [string]: string }?, thumb: string? }`
- `ColumnSpec = { id: string, label: string, width: number?, align: ("left" | "right" | "center")?, sort: boolean? }`
- `Scope = { name: string }` — matches `editorSelection.Scope`.
`id`, `key`, `row`, and `selection` are required at runtime (a missing
one raises an `error`); `columns` is additionally required for table
mode. Every `Props` field is typed optional so `props or {}` at the
registration boundary stays well-typed.
## Usage
```luau
local dataView = require("@builtin::modules.zui.widget.dataView")
local Selection = require("@builtin::modules.api.editor.selection")
local scope = Selection.scope("asset")
-- list mode
dataView{
id = "assets", items = assets, selection = scope,
key = function(a) return a.guid end,
row = function(a) return { label = a.name, icon = a.icon } end,
onActivate = "assets:open",
filter = state.filterText,
}
-- table mode
dataView{
id = "assetsTable", mode = "table", items = assets, selection = scope,
key = function(a) return a.guid end,
row = function(a) return { columns = { name = a.name, type = a.assetType, size = tostring(a.size) } } end,
columns = {
{ id = "name", label = "Name", width = 160, sort = true },
{ id = "type", label = "Type", width = 100, sort = true },
{ id = "size", label = "Size", width = 80, align = "right", sort = true },
},
}
-- grid mode
dataView{
id = "assetsGrid", mode = "grid", items = assets, selection = scope,
key = function(a) return a.guid end,
row = function(a) return { label = a.name, thumb = a.path .. "/preview.png" } end,
gridColumns = 4,
}
-- right-click command menu (list/table mode)
local Commands = require("@builtin::modules.api.editor.commands")
Commands.declare({ id = "asset.rename", title = "Rename", category = "Assets", run = function(ctx) ... end })
dataView{
id = "assets", items = assets, selection = scope,
key = function(a) return a.guid end,
row = function(a) return { label = a.name } end,
commands = { "asset.rename", "-", "asset.delete" },
}
```
## Notes
- Selection is read from and written to `props.selection` in every
mode — the widget holds no selected-ids of its own, so every other
view sharing the scope always agrees with what's drawn. Only the
click anchor, keyboard focus position, and (table mode) sort
key/direction live in `ui.widgetState`, because none of them has a
home in the selection model.
- Row click resolves through `selectionModel.resolveClick` (plain /
ctrl / shift semantics) using positions in the CURRENT filtered/
sorted view, not indices into `props.items` — a shift-range always
spans what's visually between the anchor and the click.
- The canvas `onClick` payload carries only the cursor position and
button, never modifier keys, so ctrl/shift state is read from
`input.isDown("ControlLeft" | "ControlRight" | "ShiftLeft" | "ShiftRight")`
at the moment of the click — the same substrate `modules.zinput.rebind`
polls for modifier-aware interactions.
- Keyboard nav (list/table row canvas `onKey`): `ArrowDown` / `ArrowUp`
move focus and single-select the new row, `Home` / `End` jump to the
first/last visible row, `Enter` dispatches `props.onActivate` for the
focused row. Double-clicking a row also dispatches `props.onActivate`.
Grid cells are panels (generic `onClick` only) — they select but
don't carry keyboard nav or double-click.
- Table mode's column header cells dispatch a `<id>:sort:<colId>`
click for any column with `sort = true`, cycling
none/other-column -> ascending -> descending -> none. Sort compares
`row(item).columns[col.id]` (the same text shown in the cell), so a
numeric-looking column sorts lexicographically unless the cell text
is itself a plain unpadded number.
- Every scrollable body (`virtual = true` list/table rows, the grid's
wrapping `Z.grid`) is wrapped with BOTH `maxHeight` and `minHeight`
set to the same value. Without `minHeight`, nesting the scrollArea
under a header (table mode) or wrapping `Z.grid` directly (grid mode)
makes its column an indefinite-height ancestor, and the viewport
collapses to a sliver well under the intended bound.
- Grid cells set `width` / `height` (not `minWidth` / `minHeight`) on
the panel — `Z.grid`'s content-driven column sizing reads each
child's `width` style to pick a cell size, and a `minWidth`-only cell
measures as 0 there.
- An empty filtered view renders a single muted "No items" label
instead of an empty scroll area (table mode keeps the header above
it).
- Handlers (click, double-click, keyboard nav, column sort) are
registered once per widget id (deduped via `app._dataViewHandlers`);
item list, filter, column and callback swaps land without
re-registering, mirroring `selectableList`'s handler dedup.
- `props.commands` (list/table mode only — see below) adds a right-
click command menu, driven by `modules.api.editor.commands`. Each
entry is a command id (`Commands.get(id).title` labels it,
`Commands.isEnabled(id, ctx)` gates it); a `"-"` entry is a
separator. Right-clicking a row selects it alone first if it wasn't
already part of the selection, then opens the menu anchored to that
row. `ctx` passed to `enabledWhen`/`run` is `Selection.context()`
(this DataView's selection scope, since selecting the row focuses
it) plus `view` (this widget's id) and `item` (the row's underlying
item). Clicking an entry runs the command and closes the menu;
clicking elsewhere or Escape also closes it (`Z.popup` auto-dismiss).
- Grid mode does not support `props.commands` — its cells are `Z.panel`s
(generic `onClick` only), and `onPointerDown` (right-click sensing)
is decoded by the Canvas widget type alone.
# datePicker
Calendar-popup date picker. Wraps `egui_extras::DatePickerButton`
(egui_extras 0.34 with the `datepicker` feature, enabled in
`crates/zero_ui/Cargo.toml`). Value flows as an ISO-style date string;
format defaults to `"%Y-%m-%d"` and can be overridden with a jiff
strftime spec.
## Exports
- `datePicker(id: string?, value: any?, opts: DatePickerOpts?) -> WidgetNode` — build a date-picker widget node.
Types:
- `DatePickerOpts = { id?, props?, style?, format?, onChange?, enabled?, focusable?, tooltip? }`
## Usage
```luau
local datePicker = require("@builtin::modules.zui.widget.datePicker")
datePicker("startDate", "2026-05-03", {
onChange = "startDateChanged",
})
datePicker("birthday", "1990/01/15", {
format = "%Y/%m/%d",
onChange = "birthdayChanged",
focusable = true, -- Wave 5 (#2416) prep; informational today
})
```
## Notes
- `onChange` receives the newly-formatted date string as `value`.
- The widget id falls back to `opts.id` when the `id` positional is nil.
- Date format follows the jiff strftime specifier syntax (e.g. `"%Y-%m-%d"`, `"%Y/%m/%d"`).
# dialogueBox
Narrative dialogue panel — speaker name + dialogue text + per-option
response buttons inside a styled panel. Built as a primitive
composition (`panel + label + btn`), so the engine has no dedicated
arm.
## Exports
- `dialogueBox(opts: DialogueBoxOpts?) -> WidgetNode` — build a dialogue widget node.
Types:
- `DialogueOption = { text?, enabled?, tooltip? }`
- `DialogueBoxOpts = { id?, speaker?, dialogue?, options?, bg?, border?, borderWidth?, padding?, gap? }`
## Usage
```luau
local dialogueBox = require("@builtin::modules.zui.widget.dialogueBox")
dialogueBox({
id = "dlg1",
speaker = "Captain",
dialogue = "We've got incoming. Pick your move.",
options = {
{ text = "Engage" },
{ text = "Retreat", enabled = false },
{ text = "Hail", enabled = true },
},
})
```
## Notes
- Each option emits a click event keyed `<id>-<index>` (1-based), so a single pattern handler captures every response:
```luau
app:on("^dlg1%-(%d+)$", function(_, _, idx)
handleResponse(tonumber(idx))
end)
```
- When `opts.id` is omitted, the callback prefix falls back to `"dialogueBox"`.
- `option.enabled` defaults to `true` (the wrapper checks `option.enabled ~= false`).
- Styling defaults pull from `Theme.default` (`panel`, `border`, `text`, `text_bright`).
# dndList
Drag-and-drop reorderable list. Each child renders inside a vbox of
two stacked nodes — the original child plus an overlay canvas sized to
the row that captures drag and pointer-move events. Built on `onDrag`
+ `onPointerMove` canvas interactions; the engine has no dedicated
dnd-list arm.
## Exports
- `dndList(id: string?, children: { any }?, opts: DndListOpts?) -> WidgetNode` — build a drag-reorderable list widget node.
Types:
- `DndListOpts = { rowHeight?, rowWidth?, style?, app?, onReorder?, classes?, barColor?, dragStroke?, label? }`
## Usage
```luau
local dndList = require("@builtin::modules.zui.widget.dndList")
dndList("playlist", {
Z.lbl("Track 1"),
Z.lbl("Track 2"),
Z.lbl("Track 3"),
}, { onReorder = "playlist:reorder" })
-- Then in `onCallback`:
-- data.value = { from = 1, to = 3, value = "1,3" }
-- Caller re-renders with the children rearranged.
```
## Notes
- Reorder events fire only on drag stop (`dragStopped = true`) and only when `from ≠ to`. The payload includes both numeric `from` / `to` and a legacy `"from,to"` string that the engine test suite asserts on.
- Defaults: `rowHeight = 28`, `rowWidth = 240`, `barColor = "#78b4ff"`, `dragStroke = "#78b4ff78"`.
- Auto-registers `<id>:drag:<index>` and `<id>:hover:<index>` handlers on the surrounding `Z.app`, deduped by id. Drag state lives in `app._dndListState[id]` and persists across renders.
- Outside `Z.app` (no app in scope), the widget renders but the overlay never draws the insertion bar — drag interaction is inert.
- The outer Panel exposes `role = "list"` and `ariaLabel = opts.label or "Reorderable list"` for accessibility.
# dockArea
A docking container backed by egui_dock. Holds a persistent `DockState` keyed by the widget id, so split/tab arrangements and user drags survive across frames. Children are `dockPanel`s, each supplying a tab id, a title, and a content subtree.
The dockArea must be the root of a registered screen tree. Each frame it reconciles: it adds tabs for newly-present dockPanel ids and removes tabs whose dockPanel disappeared. Closing a tab emits a `<panelId>-close` interaction so the app can drop the panel from its children.
The module returns the widget builder function directly.
## Builder
`dockArea(opts?) -> widget node`. `opts` fields:
- `id` — the widget id the DockState is keyed by.
- `layout` — a serialized `DockState` JSON string that seeds the split/tab arrangement on first render. Read the live arrangement back with `ui.getDockLayout(id)` and pass it here to restore.
- `restoreLayout` / `restoreEpoch` — re-apply a saved layout to an already-live dock: pass the JSON in `restoreLayout` and bump `restoreEpoch` to a new value; the dock re-deserializes once per new epoch, then stays freely draggable.
- `overlayType` — `"widgets"` (icon drop buttons) or `"highlightedAreas"` (quadrant highlights — edges split, middle ring appends as a tab, dead-center floats the tab into its own window).
- `leafCollapseButtons` / `leafCloseAllButtons` — the collapse arrow and close-all button on each leaf's tab bar.
- `allowedSplits` — how a dragged tab resolves over a drop area: `"all"`, `"none"`, `"leftRight"`, `"topBottom"`.
- `children` — the dockPanels.
- `props`, `style` — the `style` block carries the standard widget keys (`borderWidth`, `borderRadius`, `padding`) plus the dock-specific chrome keys typed as `ZuiDockStyle`.
## Usage
```luau
local dockArea = require("modules.zui.widget.dockArea")
local widget = dockArea({ id = "editor", children = {
Z.dockPanel({ id = "scene", title = "Scene",
children = { Z.lbl("Scene body") } }),
Z.dockPanel({ id = "props", title = "Properties",
children = { Z.lbl("Inspector body") } }),
}})
```
# dockPanel
A single dockable panel inside a `dockArea`. Its widget `id` is the stable tab id the dockArea uses for reconciliation and for the `<id>-close` interaction fired when the tab is closed. Children form the tab's content subtree, rendered by the dockArea's TabViewer.
The module returns the widget builder function directly.
## Builder
`dockPanel(opts?) -> widget node`. `opts` fields:
- `id` (required) — the stable tab id.
- `title` — the tab label shown in the dock tab bar; defaults to the panel `id`.
- `closable` — whether the tab shows a close button (default true). On close the dockArea emits `<id>-close`.
- `float` — when a NEW panel first appears with `float = true`, the dockArea opens it as a floating, movable, resizable dock-window over the content behind instead of in the focused leaf.
- `children`, `props`, `style`.
## Usage
```luau
local dockPanel = require("modules.zui.widget.dockPanel")
local widget = dockPanel({ id = "props", title = "Properties", children = {
Z.lbl("Inspector body"),
}})
```
# dragValue
DragValue is a Luau builder over `canvas`. Emits a drag-to-change
numeric scrubber: background rect + centered numeric readout + an
`onDrag` handler that accumulates the per-frame delta scaled by
`opts.speed`. Range clamping + Shift-fine-drag (10× finer) ride on top.
Auto-registers `<id>:drag` per id (deduped) and dispatches
`opts.onChange` (or the widget id) with `{ value = newNumber }` on
every drag tick.
## Exports
- `dragValue(id: string, value: number?, lo: number?, hi: number?, opts: DragValueOpts?) -> WidgetNode` — build the scrubber canvas. Default range is `[0, 1]`; default speed is `0.01`; default format is `%.2f`.
Types:
- `DragValueOpts = { style: DragValueStyle?, width: number?, height: number?, speed: number?, format: string?, onChange: string?, label: string?, classes: (string | { string })?, app: any? }`
- `DragValueStyle = { width: number?, height: number?, background: string?, color: string?, borderColor: string?, borderRadius: number?, fontSize: number?, [string]: any }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.dragValue("plug:gain", state.gain, -24, 24, {
speed = 0.1,
format = "%.1f",
onChange = "plug:gain", -- defaults to widget id
})
```
## Notes
- Live value lives in `ui.widgetState(id, "value")`; the first render
seeds it from the caller's `value` arg.
- Inside a `Z.app` context the drag handler is auto-registered and
deduped per id. Outside, the canvas's `onDrag` is routed directly to
the user's callback id (legacy raw-onCallback mode) — the handler
receives the structured drag payload rather than a scalar.
- Inline text-edit on double-click is deferred. If a use case needs
typing, swap to `Z.input` via widgetState.
# dropdown
Combobox-style dropdown — Luau builder over `Z.btn` + `Z.popup` +
`Z.selectableList`. Click-to-open, click-to-select, click-outside /
Escape closes. Full keyboard navigation: the inner SelectableList
handles ArrowUp/Down/Home/End + Enter/Esc, and the trigger button
accepts ArrowDown / Enter / Space to open via generalised `onKey`.
## Exports
- `dropdown(id: string, options: { string }?, selected: number?, opts: DropdownOpts?) -> WidgetNode` — build the trigger + popup. `selected` is the 1-based index of the active option; first call seeds `ui.widgetState(id, "selected")`.
Types:
- `DropdownOpts = { style: { [string]: any }?, classes: (string | { string })?, onChange: string?, pivot: string?, rowWidth: number?, rowHeight: number?, ariaLabel: string?, app: any? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.dropdown("env", { "Dev", "Stage", "Prod" }, state.env, {
onChange = "env:change",
})
app:on("env:change", function(v)
state.env = v -- v is the new 1-based index
end)
```
## Notes
- ARIA roles: trigger is `role="combobox"` / `aria-expanded`; popup
hosts a listbox. Focus moves to the row matching the current
selection on open, and returns to the trigger on close.
- Per-id handlers (`<id>-trigger`, `<id>:triggerKey`, `<id>:commit`,
`<id>:dismiss`) are registered once and deduped — re-renders don't
accumulate handlers.
- `selected` is clamped to `[1, #options]` so out-of-range inputs
don't crash the popup.
# fader
DAW-style vertical fader built on `canvas` interaction props. Draws
track + fill + cap as `rect` commands plus a centred grip `line`, and
wires drag / click / double-click handlers via `widgetState`. Drag and
click both project the pointer Y onto the track — grabbing or
clicking anywhere snaps the cap to that Y. Double-click resets to
`defaultValue` when set.
## Exports
- `fader(id: string, value: number?, lo: number?, hi: number?, opts: FaderOpts?) -> WidgetNode` — build the fader canvas. Auto-registers `<id>:drag`, `<id>:click`, `<id>:reset` handlers (deduped). When `opts.tooltip` is set, the canvas is wrapped in a transparent panel that hosts the tooltip.
Types:
- `FaderOpts = { defaultValue: number?, onChange: string?, tooltip: string?, style: { [string]: any }?, width: number?, height: number?, trackColor: string?, capColor: string?, fillColor: string?, app: any? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.fader("master-volume", state.volume, 0, 1, {
defaultValue = 0.8,
onChange = "audio:volume",
})
app:on("audio:volume", function(v)
state.volume = v -- the new numeric value
end)
```
## Notes
- Track top = `hi`, track bottom = `lo` (egui +y is down). Pointer Y
is projected onto the track range to produce the new value, then
clamped to `[min(lo,hi), max(lo,hi)]`.
- Per-id handlers are deduped — re-renders don't accumulate listeners.
Mutating width/height between renders means the *first* render's
geometry wins (matches every other auto-stash widget).
- Double-click is a no-op when `opts.defaultValue` is nil.
# filterRow
Composite filter row — search input + toggle checkboxes + sort
dropdown + counter + action buttons. Captures the pattern every list
view re-implements (entities, logs, assets, scripts,
animation_browser). Caller owns all bound values; the widget is
stateless. Each piece is optional; an empty `opts` produces an empty
hbox.
## Exports
- `filterRow(opts: FilterRowOpts?) -> WidgetNode` — assemble the row from the optional pieces in `opts`. Callback ids fire as `<id>-search`, `<id>-toggle-<key>`, `<id>-sort`, plus each action's `onClick` verbatim.
Types:
- `FilterRowOpts = { id: string?, search: SearchOpts?, toggles: { ToggleOpts }?, sort: SortOpts?, counter: CounterOpts?, actions: { ActionOpts }?, searchClass: string?, toggleClass: string?, sortClass: string?, class: string?, gap: number?, marginBottom: number?, padding: any?, align: string? }`
- `SearchOpts = { value: any?, placeholder: string?, class: string?, minWidth: number? }`
- `ToggleOpts = { key: any, label: string?, value: boolean?, class: string? }`
- `SortOpts = { options: { string }?, selected: number?, class: string?, minWidth: number? }`
- `CounterOpts = { visible: number?, total: number?, class: string?, fontSize: number? }`
- `ActionOpts = { label: string?, onClick: string?, variant: string?, padding: { number }?, minWidth: number?, tooltip: string?, class: string? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
return Z.filterRow({
id = "logs-filter",
search = { value = state.q, placeholder = "Search...", minWidth = 160 },
toggles = {
{ key = "info", label = "Info", value = state.showInfo },
{ key = "warn", label = "Warn", value = state.showWarn },
},
sort = { options = LOG_TYPES, selected = state.typeIdx },
counter = { visible = #filtered, total = #all },
actions = { { label = "Clear", onClick = "logs-clear", variant = "danger" } },
})
```
## Notes
- Stateless. Caller owns every bound value; the widget only routes
events through the `<id>-*` callback ids.
- When `counter` or `actions` are present, a flex spacer is inserted
first so they right-align to the trailing edge of the row.
- Action `variant` of `"primary"` / `"danger"` selects a coloured
background from the active theme; anything else falls back to
`theme.panel_alt`.
# flex
Flex-grow spacer. Pushes siblings apart inside an hbox/vbox — use to
right-align items in a horizontal row, etc. The engine treats a spacer
with no `space` set as flex-grow.
## Exports
- `flex() -> Spacer` — build a flex-grow spacer widget table.
Types:
- `Spacer = { type: string }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
local row = Z.hbox({ Z.lbl("left"), Z.flex(), Z.lbl("right") })
```
## Notes
- Pure function — no engine calls, no state. Safe at module load time.
- The returned table is interoperable with hand-written widget trees;
any container that accepts a `{ type = "spacer" }` child will treat
it as flex-grow.
# fs
Filesystem composite widgets — pure builders that turn VFS listing
data into widget trees. Four stateless pieces every caller composes
with their own state + polling.
## Exports
- `M.tree(roots, opts) -> WidgetNode` — folder tree (recursive) built on `Z.tree` with VFS-friendly defaults.
- `M.fileList(entries, opts) -> WidgetNode` — flat list of files; folders first; selected file highlighted.
- `M.preview(data, opts) -> WidgetNode` — file preview pane (text or note).
- `M.breadcrumb(path, opts) -> WidgetNode` — clickable path crumbs.
## Usage
```luau
local Fs = require("@builtin::modules.zui.widget.fs")
return Z.hbox({
Fs.tree(state.roots, { onSelect = "files-tree-select" }),
Fs.fileList(state.entries, { onSelect = "files-row", selectedKey = state.name }),
Fs.preview({ name = state.name, text = state.text }, { id = "files-preview" }),
})
```
## Notes
- All four builders are stateless: pass data in, get a widget tree
out. They never touch the VFS — the caller owns reads, listing, and
cache eviction.
- `Z.fs.*` is what Layer B (`engine/ui/file_manager`) and Layer C
(system_tools' "Files" tab) compose with their own polling. You can
build your own file-browser by composing these directly.
# graph
Sparkline-class chart built on `canvas`. Bar mode emits N rect
commands; line mode emits a single polyline. Y axis auto-ranges from
the data unless the caller passes `minValue` / `maxValue`. Optional
gridlines + axis labels via the shared `_axes` helper; optional
on-hover tooltip pinned to the nearest data point. Plot has the more
featureful chart — graph is the cheap visual.
## Exports
- `graph(data: { number }?, opts: GraphOpts?) -> WidgetNode` — build the chart canvas. Empty data arrays render just the background; 1-element arrays render the background (the polyline path needs 2+ points).
Types:
- `GraphOpts = { id: string?, classes: (string | { string })?, style: { [string]: any }?, width: number?, height: number?, bg: string?, background: string?, color: string?, graphType: string?, minValue: number?, maxValue: number?, showAxes: boolean?, gridlines: boolean?, tooltip: boolean?, gridColor: string?, axisColor: string?, labelColor: string?, labelSize: number?, xLabels: boolean?, yLabels: boolean?, xTickFormat: any?, yTickFormat: any?, label: string?, app: any? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.graph({ 1, 4, 9, 16, 25, 36 }) -- line, auto-range
Z.graph(samples, { graphType = "bar", color = "#7AA8FF" })
Z.graph(samples, { minValue = 0, maxValue = 1 })
Z.graph(samples, { id = "fps", tooltip = true }) -- hover tooltip
Z.graph(samples, { showAxes = true, gridlines = true })
```
## Notes
- `tooltip` requires `opts.id` — the hover handler stashes the active
index in `ui.widgetState(id, "hover")`. The tooltip persists until
the next hover; the engine doesn't emit pointer-leave for canvases.
- When `showAxes` is set, the plot body shrinks to reserve room for
tick labels. With axes off, the polyline spans the full canvas
height (preserved by the `respects explicit minValue/maxValue range`
test).
- DOM mirror exposes the resulting canvas as
`<canvas role="img" aria-label="Chart">` via the generic prop
pass-through.
# grid
Fixed-column grid container. Children flow left-to-right then wrap.
`columns` is required.
## Exports
- `grid(children: { WidgetNode }?, columns: number, opts: GridOpts?) -> WidgetNode` — build a fixed-column grid container.
Types:
- `GridOpts = { id: string?, classes: (string | { string })?, props: { [string]: any }?, style: { [string]: any }? }`
- `WidgetNode = { [string]: any }` — widget table (interoperable with hand-written widget trees).
## Usage
```luau
local Z = require("@builtin::modules.zui")
local g = Z.grid({ a, b, c, d }, 2, { style = { gap = 4 } })
```
## Notes
- Pure builder — no state, no engine calls. Safe at module load.
- `children` defaults to `{}` when nil; `columns` has no default and
must be provided.
- The `columns` value is forwarded to the engine as `props.columns`;
any other props the caller passes survive untouched.
# hbox
Horizontal layout container. Children laid out left-to-right; spacing
via `style.gap`; alignment via `style.align` (`"start"` | `"center"` |
`"end"`).
## Exports
- `hbox(children: { WidgetNode }?, opts: HboxOpts?) -> WidgetNode` — build a horizontal-layout container.
Types:
- `HboxOpts = { id: string?, classes: (string | { string })?, props: { [string]: any }?, style: { [string]: any }? }`
- `WidgetNode = { [string]: any }` — widget table (interoperable with hand-written widget trees).
## Usage
```luau
local Z = require("@builtin::modules.zui")
local row = Z.hbox({ Z.lbl("a"), Z.lbl("b") }, {
style = { gap = 6, align = "center" },
})
```
## Notes
- Pure builder over `modules.zui.widget.node` — no state, no engine
calls. Safe at module load.
- `children` defaults to `{}` when nil so an empty hbox is a no-op.
- `style.gap` is the inter-child spacing in pixels; `style.align`
controls cross-axis alignment.
# healthBar
Game-HUD horizontal health bar. Luau builder over `canvas` — emits a
background rect plus a foreground fill rect scaled by `current / max`,
with an optional centered numeric label. The wrapping canvas exposes
ARIA `progressbar` semantics for the DOM mirror so screen readers
report the current value.
## Exports
- `healthBar(current: number, max: number, opts: HealthBarOpts?) -> WidgetNode` — module returns the builder function directly. Call `Z.healthBar(...)` via the zui re-export.
Options:
- `showText: boolean?` — overlay `"current/max"` centered. Default `true`.
- `background: string?` — empty-bar tint. Default `"#3c1e1e"`.
- `color: string?` — fill color when `gradient` is not set. Default `"#c83c3c"`.
- `width: number?`, `height: number?` — bar size. Defaults `200 x 24`.
- `label: string?` — `aria-label` override. Default `"Health"`.
- `gradient: boolean | {{number, string}}?` — `true` for the default 3-stop red→yellow→green, or a sorted `{{ratio, "#rrggbb"}}` list.
- `id`, `classes`, `style` — standard widget plumbing.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.healthBar(state.hp, state.hp_max, {
showText = true,
gradient = true,
label = "Player health",
})
-- Custom gradient stops:
Z.healthBar(hp, max, {
gradient = {
{ 0, "#000000" },
{ 0.5, "#777777" },
{ 1, "#ffffff" },
},
})
```
## Notes
- Stops must be sorted ascending by ratio. Ratios outside `[0, 1]` are
clamped. Fewer than 2 stops falls back to the default 3-stop palette.
- The fill rect is omitted when `ratio == 0` so an empty bar's edge
doesn't render a 0-width sliver.
- `gradient` (when truthy) overrides `color`.
- Stateless — no module state, safe to call every frame.
# hotbar
Game-HUD hotbar. Composes an hbox of per-slot buttons with overlaid
count + slot-index labels, highlighting the slot indicated by
`selectedSlot`. Clicking a slot fires the callback
`<opts.id or "hotbar">-<index>`. The caller is the source of truth
for the selection (controlled-component pattern).
## Exports
- `hotbar(slots: {Slot}, selectedSlot: number?, opts: HotbarOpts?) -> WidgetNode` — module returns the builder function directly.
Per-slot shape:
- `Slot = { icon: string?, count: number?, tooltip: string? }`
Options:
- `id: string?` — callback prefix. Default `"hotbar"`.
- `style: table?` — hbox style. Default `{ gap = 4 }`.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.hotbar(state.slots, state.selectedSlot, { id = "hotbar" })
-- Pattern-match the per-slot callbacks:
app:on("^hotbar%-(%d+)$", function(_, _, idx)
state.selectedSlot = tonumber(idx)
end)
```
## Notes
- Slot indices start at 1.
- Empty `slots` (or `nil`) renders an empty hbox.
- The widget is stateless — the parent app owns selection state.
- Each button's `id` is `<prefix>-slot-<i>`; the click callback is
`<prefix>-<i>` (note: different separator pattern by design).
# icon
Icon glyph rendered via a glyph font (default `phosphor`). Effectively
a `label` with the `fontFamily` fixed to the icon font, kept as its
own widget so callers don't have to remember which fontFamily the
icons live under.
## Exports
- `icon(text: string, opts: IconOpts?) -> WidgetNode` — module returns the builder function directly.
Options:
- `font: string?` — override the font family. Default `"phosphor"`.
- `size: number?` — sets `style.fontSize`.
- `color: string?` — sets `style.color`.
- `padding: any?` — sets `style.padding`.
- `id: string?`, `style: table?` — standard widget plumbing.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.icon("", { size = 16, color = "#dcdcdc" })
Z.icon("", { font = "fontawesome" })
```
## Notes
- Stateless — returns a fresh widget table each call.
- `text` is whatever the icon font renders for the codepoint you pass.
- Top-level shortcuts (`size`, `color`, `padding`, `font`) overwrite any
conflicting field on `style`.
# iconBtn
Button rendered with the phosphor glyph font. Convenience wrapper over
`Z.btn` for the common case of an icon-only button — defaults the
`fontFamily` to `phosphor` so callers don't repeat it on every click
target.
## Exports
- `iconBtn(iconText: string, callbackId: string, opts: table?) -> WidgetNode` — module returns the builder function directly.
`opts` is forwarded to `Z.btn`; this wrapper only injects
`opts.style.fontFamily = "phosphor"` when none is set.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.iconBtn("", "save:click", { id = "save", tooltip = "Save" })
```
## Notes
- Equivalent to `Z.iconButton` (which simply re-requires this module).
- The wrapper mutates the supplied `opts` table in place. If you reuse
the same `opts` across calls, expect `style.fontFamily` to persist.
- Any explicit `opts.style.fontFamily` wins; the default only fires
when the field is missing.
# iconButton
Square button rendered with the phosphor glyph font. Thin alias for
`Z.iconBtn` — re-requires the same builder so the call shapes are
identical. Pick whichever name reads better at the call site.
## Exports
- `iconButton(iconText: string, callbackId: string, opts: table?) -> WidgetNode` — module returns the `iconBtn` builder directly.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.iconButton("", "save:click", { id = "save", tooltip = "Save" })
```
## Notes
- This module is a one-line `return require("modules.zui.widget.iconBtn")`.
- See `iconBtn` for full option semantics.
- Useful when reading code: `iconButton` reads more naturally in some
call sites, `iconBtn` is shorter for inline use.
# image
Static image widget. Wraps a single `image` node whose `src` is fed
to the engine's image loader. Sizing comes from `style.width` and
`style.height`.
## Exports
- `image(src: string, opts: ImageOpts?) -> WidgetNode` — module returns the builder function directly.
Options:
- `id: string?` — widget id.
- `style: table?` — passes through to the underlying node; supply `width`/`height` here.
## Usage
```luau
local Z = require("@builtin::modules.zui")
-- By VFS path.
Z.image("/source/libs/@builtin/textures/uv_checker_bw.png", { style = { width = 64, height = 64 } })
-- By asset identity.
Z.image("@builtin::textures.uv_checker_bw", { style = { width = 64, height = 64 } })
```
## Notes
- Stateless — no side effects beyond producing a widget table.
- `src` reaches the engine's image loader, which resolves these spellings:
a VFS path (`/source/...` or `/zero/source/...`), an asset identity
(`@builtin::textures.uv_checker_bw`), an asset guid, and an http URL.
A path anchors at the VFS root, so name it from there.
- A `src` the loader cannot reach paints a `[failed <src>]` placeholder in
place of the image.
- Aspect ratio is whatever the engine's image renderer applies — this
widget does not impose one.
# input
Text input widget. Single-line by default; pass `multiline = true`
for a textarea. The code-editor variant (syntax-highlight, line
numbers, folding) lives in `zui.widget.codeEditor` — same underlying
widget kind, more defaults, plus the Luau highlighter producing
`segments`.
## Exports
- `input(id: string, value: string?, opts: InputOpts?) -> WidgetNode` — module returns the builder function directly.
Options forwarded to the node's `props`:
- `placeholder: string?`
- `onChange: string?` — callback id
- `submitOnEnter: boolean?`
- `multiline: boolean?`
- `password: boolean?`
- `codeEditor: boolean?`
- `segments: { Segment }?` — pre-highlighted layout segments
- `foldLanguage: string?` — opt into the Rust fold detector (`"lua"` etc.)
- `lineNumbers: boolean?`, `folding: boolean?`
- `props`, `classes`, `style` — standard widget plumbing.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.input("name", state.name, {
placeholder = "Your name",
onChange = "name:edit",
})
-- Multiline:
Z.input("notes", state.notes, { multiline = true })
```
## Notes
- When `props.segments` is supplied, the renderer builds the LayoutJob
from segments instead of the plain `text` string — but `text` is
still set, so the underlying value continues to work for callbacks.
- For syntax-highlighted code editing, prefer `Z.codeEditor`, which
bundles `foldLanguage`, `lineNumbers`, `folding`, and a default
highlighter call.
- Stateless — the parent owns the buffer; this widget only renders.
# kbd
Keybind widget — a Luau builder over `hbox` + `button` (or a
focusable `canvas` while capturing). Uses canvas `onKey` and
`ui.focus(id)` to capture the next pressed key from primitives. Has
two call shapes that produce the same widget kind: a display-only
form for showing a key combo, and an interactive capture form for
rebinding.
## Exports
- `kbd(keysOrOpts: string | KbdOpts, opts: table?) -> WidgetNode` — module returns the builder function directly. The first arg is polymorphic.
Display-only call: `kbd("Ctrl+S")` or `kbd("Ctrl+S", { style = {...} })`.
Interactive call (table form):
- `id: string` — required; identifies the widget for state + handlers.
- `label: string?` — left-side label. Default `"Key"`.
- `key: string?` — current binding text. Default `"None"`.
- `onChange: string?` — callback id; fires on commit with `{ value = "F1" }`.
- `app: App?` — explicit app; falls back to `App.current()`.
- `buttonWidth`, `buttonHeight`, `gap`, `labelStyle`, `buttonStyle`, `canvasStyle`, `style`, `classes` — layout/style overrides.
## Usage
```luau
local Z = require("@builtin::modules.zui")
-- Display only:
Z.kbd("Ctrl+S")
-- Interactive:
Z.kbd({
id = "settings:bind:jump",
label = "Jump",
key = state.jumpKey,
onChange = "ui:bind:jump", -- fires with { value = "F1" }
})
```
## Notes
- Behaviour while capturing: clicking the `[<key>]` button transitions
to capturing and focuses the per-instance hidden canvas. Any key
press commits and leaves capturing. `Escape` cancels (capturing flips
off, key unchanged).
- Captured state lives in `ui.widgetState(id, "capturing"|"key")` so
the wrapper survives screen rerenders without the caller threading
it through.
- `onChange` fires only on commit, not on cancel.
- Per-id handler registration is deduped via `app._keybindHandlers`
(mirrors the `radioGroup` pattern); `onChange` swaps land on each
render without re-registering.
- Calling the table form without an `id` falls back to display-only.
# knob
Rotary knob built on `canvas` interaction props. Renders a 270° dial
as a track polyline + fill polyline + needle line, and wires
drag/reset handlers via `widgetState`. Auto-registers per-id handlers
on the current `Z.app` so callers only need to supply `onChange`.
## Exports
- `knob(id: string, value: number, lo: number?, hi: number?, opts: KnobOpts?) -> WidgetNode` — module returns the builder function directly.
Options:
- `defaultValue: number?` — restored on double-click. Omit to disable reset.
- `onChange: string?` — callback id; fires with `{ value = number }` on drag/reset commit.
- `tooltip: string?` — when set, wraps the canvas in a transparent tooltip panel.
- `width: number?`, `height: number?` — canvas size. Default `34 × 34`.
- `arcWidth: number?` — track/fill stroke width. Default `4`.
- `trackColor: string?`, `fillColor: string?`, `capColor: string?` — palette overrides.
- `style: table?`, `app: App?` — standard plumbing.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.knob("master-gain", state.gain, 0, 1, {
defaultValue = 0.75,
onChange = "audio:gain",
tooltip = "Master gain",
})
```
## Notes
- Vertical drag updates the value: `1px = 0.5% of span`, or `0.05%` when
Shift is held (10× finer for fine adjustment). Drag *up* increases.
- Double-click restores `defaultValue` if set; otherwise no-op.
- Live state lives in `ui.widgetState(id, "value")` — first render seeds
from the supplied `value`, thereafter the drag handler owns it. This
mirrors the `Z.collapsible` auto-stash pattern.
- Handlers are registered once per id via `app._knobHandlers`; subsequent
renders are no-ops on the handler side.
- The fill polyline is omitted when only one segment is filled so the
renderer's min-2-points guard isn't tripped.
- The tooltip wrap is only added when `opts.tooltip` is set so non-tooltip
knobs stay flat.
# label
Label widget — read-only text. Accepts top-level shortcuts for the
most commonly styled fields (`color`, `fontSize`, `bold`, `bg`,
`padding`, `minWidth`, `font`) so callers don't have to nest
everything under `style = { ... }`.
## Exports
- `label(text: any, opts: LabelOpts?) -> WidgetNode` — module returns the builder function directly. Also exposed as `Z.lbl`.
Options (top-level shortcuts mapped onto `style`):
- `color: string?`
- `fontSize: number?`
- `fontWeight: string?`
- `bold: boolean?` — sets `fontWeight = "bold"` when true.
- `bg: string?` — sets `style.background`.
- `padding: any?`
- `minWidth: number?`
- `font: string?` — sets `style.fontFamily`.
- `id`, `classes`, `class`, `style` — standard widget plumbing.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.lbl("Hello")
Z.lbl("dim text", { color = "#888", bold = true })
Z.lbl(42, { fontSize = 18, font = "monospace" })
```
## Notes
- `text` is coerced to a string via `tostring(text or "")`. Passing `nil`
yields the empty string.
- The shortcut props overwrite any conflicting field on `style`.
- Stateless — no module state, no engine calls.
# leftPanel
Left-docked panel. Root-only — must be a top-level child of the
screen builder, not nested inside another container. Wraps the
supplied children in a `leftPanel` node that the layout engine docks
against the left edge of its parent screen.
## Exports
- `leftPanel(children: { WidgetNode }, opts: table?) -> WidgetNode` — module returns the builder function directly.
`opts` is forwarded verbatim to the underlying node.
## Usage
```luau
local Z = require("@builtin::modules.zui")
Z.app(function()
return {
Z.leftPanel({
Z.lbl("Sidebar"),
-- ...
}),
Z.centralPanel({
-- main view
}),
}
end)
```
## Notes
- Must be a root-level child of the screen builder; nesting it inside
another container is unsupported.
- `nil` children are treated as an empty array.
- Stateless.
# lsp
LSP composite widgets — pure builders that turn the engine's `lsp.*`
data shapes into widget trees. Six pieces gathered onto a single `M`
table so callers can `require` the namespace and pick out individual
builders. These are stateless: pass data in, get a widget tree out.
## Exports
- `M.severitySummary(counts, opts?) -> WidgetNode` — hbox of count chips per severity.
- `M.diagnosticsList(diags, onSelect, opts?) -> WidgetNode` — scrollable vbox of diagnostic rows.
- `M.diagnosticDetail(diag, opts?) -> WidgetNode` — detail panel for one diagnostic.
- `M.docBrowser(state, opts?) -> WidgetNode` — namespaces / methods / describe browser.
- `M.strictModeToggle(mode, onChange, opts?) -> WidgetNode` — three-button radio.
- `M.directiveBadge(skipMode, opts?) -> WidgetNode?` — chip indicating the file's `--!skip` mode, or `nil`.
Each export is the builder module's `return function(...)`; see the
sibling `*.module/README.md` files for the per-builder signatures.
## Usage
```luau
local Z = require("@builtin::modules.zui")
local lsp = require("@builtin::modules.zui.widget.lsp")
return Z.vbox({
lsp.severitySummary(counts),
lsp.diagnosticsList(diags, "lsp:row:select"),
lsp.diagnosticDetail(diags[selectedIndex], { source = source }),
})
```
## Notes
- Layer B (`lsp_ui.module`) and Layer C (system_tools' LSP tab) compose
these with their own state + polling — but you don't have to: roll
your own.
- Each entry is loaded lazily by `require`. Hot-reloading any sibling
re-imports it on next call.
- This namespace owns no state. The composite layers above this one do.
# meter
Peak-style level meter built on `canvas`. Renders either a continuous
fill or N segmented LED rects, plus an optional peak indicator line.
Read-only — no interaction props. Peak-hold state lives in
`ui.widgetState(id, ...)` when an `id` is supplied; without one, the
meter still renders but the peak indicator is skipped.
## Exports
- `meter(value: number?, opts: Opts?) -> any` — build the meter canvas node. Returned directly by the module.
Types:
- `Style = { width?, height?, background?, fillColor?, warnColor?, clipColor?, offColor? }`
- `Opts = { id?, orientation?, segments?, warnThreshold?, clipThreshold?, peakHoldMs?, peak?, width?, height?, background?, fillColor?, warnColor?, clipColor?, offColor?, style? }`
## Usage
```luau
local meter = require("@builtin::modules.zui.widget.meter")
local widget = meter(state.master_l, {
id = "master-meter-l",
orientation = "horizontal",
style = { width = 220, height = 8,
fillColor = "#3cc864", warnColor = "#dcc83c",
clipColor = "#dc463c", background = "#101214" },
})
```
## Notes
- `value` is clamped to `[0, 1.5]` so out-of-range inputs paint into
the clip-coloured band without spilling outside the canvas.
- Peak hold defaults to 1500ms then decays at 1.5/sec — matches the
deleted Rust `render_meter` algorithm.
- Pass `opts.peak` to override the computed peak — useful for
ganged-channel meters where a single source value drives multiple
visuals.
- Vertical default is 12×160; horizontal flips to 160×12.
# minimap
Luau builder over `canvas` for a square minimap. Renders a 150×150
dark-green square with a single light-green centre marker by default,
and accepts an optional `markers` array so callers can paint arbitrary
points (entities, waypoints, POIs) without needing a new Rust widget
kind. Marker coordinates are normalised — `[0..1]` × `[0..1]` —
clamped so out-of-bounds entries paint at the edge.
## Exports
- `minimap(opts: Opts?) -> any` — build the canvas node. Returned directly by the module.
Types:
- `Marker = { x?: number, y?: number, color?: string, radius?: number }`
- `Style = { width?: number, height?: number, background?: string }`
- `Opts = { id?, classes?, label?, size?, background?, borderColor?, borderWidth?, borderRadius?, markers?: { Marker }, style?: Style }`
## Usage
```luau
local minimap = require("@builtin::modules.zui.widget.minimap")
local widget = minimap({
size = 200,
markers = {
{ x = 0.5, y = 0.5, color = "#FFC832", radius = 5 }, -- player
{ x = 0.2, y = 0.8, color = "#64C8FF" }, -- ally
{ x = 0.7, y = 0.3, color = "#C84040" }, -- enemy
},
})
```
## Notes
- DOM mirror exposes the widget as `<canvas role="img"
aria-label="Minimap">` via the generic `role` / `aria*` prop
pass-through.
- Legacy single-dot fallback ensures existing demos keep rendering
even when no markers are supplied.
- The marker `radius` and `color` are per-marker — use them to encode
per-entity context (size for distance, colour for faction, etc.).
# modal
Top-layer modal dialog with backdrop dim, click-outside + Escape
dismissal. Wraps `egui::Modal` (added 0.30, refined through 0.34).
Root-only — the render arm dispatches at the screen-root path, like
Window. Pass `dismissible = false` to force a button-only answer.
## Exports
- `modal(opts: Opts?) -> any` — build the modal widget node. Returned directly by the module.
Types:
- `Opts = { id?, title?, open?, onClose?, dismissible?, focusable?, tooltip?, children?, props?, style? }`
## Usage
```luau
local modal = require("@builtin::modules.zui.widget.modal")
local widget = modal({
title = "Confirm",
open = state.dialogOpen,
onClose = "dialog:close",
children = {
Z.lbl("Are you sure?"),
Z.hbox({
Z.btn("Yes", "dialog:yes"),
Z.btn("No", "dialog:no"),
}),
},
})
```
## Notes
- Known limitation (pending Wave 5 / #2416): Tab navigation isn't
trapped inside the modal — keyboard focus can still reach widgets
behind the backdrop. The visible "this is modal" contract is
otherwise complete.
- Must render at the screen root for the backdrop to cover the whole
surface; nesting inside a `panel` will clip the dim layer.
- `dismissible = false` is the right choice for confirm dialogs whose
answer affects irreversible state.
# node
Core widget-table constructor used by every zui widget. Returned
tables are interoperable with hand-written widget trees, so user-built
widgets can reuse the exact same primitive without depending on the
rest of zui.
## Exports
- `node(widgetType: string, opts: Opts?, children: any?) -> any` — build the widget table. Returned directly by the module.
Types:
- `Opts = { id?: string, classes?: any, class?: any, props?: any, style?: any }`
## Usage
```luau
local node = require("@builtin::modules.zui.widget.node")
-- User-built widget composed on top of node:
return function(text, opts)
return node("label", { props = { text = text } })
end
```
## Notes
- Accepts either a single child table or an array of children; single
children are wrapped automatically (matches `scroll.module`'s fix
from #2331).
- `classes` may be a string (space-separated) or an array — both
normalise to an array of class names.
- `class` is accepted as an alias for `classes` for ergonomic call
sites.
- Returning a function (not a table) keeps consumers terse and avoids
callers needing to know whether the constructor lives on `M.x` or
the module itself.
# panel
Bordered surface for grouping widgets. Accepts top-level shortcut
keys (`bg`, `border`, `borderWidth`, `padding`, `gap`, `minWidth`,
`minHeight`, `maxWidth`, `maxHeight`) so the common case doesn't
require nesting under `style = { ... }`.
## Exports
- `panel(children: { any }?, opts: Opts?) -> any` — build the panel widget node. Returned directly by the module.
Types:
- `Opts = { id?, classes?, props?, style?, bg?, border?, borderWidth?, padding?, gap?, minWidth?, minHeight?, maxWidth?, maxHeight?, scroll?, scrollMaxHeight?, scrollId? }`
## Usage
```luau
local panel = require("@builtin::modules.zui.widget.panel")
local widget = panel({
Z.lbl("Header"),
Z.btn("Action", "click"),
}, {
bg = "#101010",
border = "#3a3a3a",
borderWidth = 1,
padding = 8,
})
```
## Tall panels — scrolling overflow (closes #3270)
`Z.anchor("Center", ...) { Z.panel(rows) }` with more rows than the
viewport will silently clip top + bottom of the list — content scrolls
off-screen with no affordance. Opt into in-place scrolling by passing
`scroll = true` alongside a `maxHeight`:
```luau
local rows = {}
for i = 1, 100 do rows[#rows + 1] = Z.lbl("row " .. i) end
-- Header + footer pin to the panel; the rows scroll between them.
return Z.anchor("Center", {}, {
Z.panel({
Z.lbl("Codex", { bold = true }),
Z.sep(),
Z.panel(rows, { scroll = true, maxHeight = 480 }),
Z.sep(),
Z.btn("Close", "codex:close"),
}, { bg = "#101010", padding = 12 }),
})
```
Without `scroll = true`, `maxHeight` only clips — `scroll = true` wraps
the children in a `scrollArea` so overflow rows are reachable via the
scrollbar. `scrollMaxHeight` (optional) bounds only the scroll region
when you want the panel itself to size to the header + footer and let
the scroll region claim what's left.
## Notes
- Top-level shortcuts merge into `opts.style` (caller-supplied keys
take precedence — explicit `style.background` wins over `opts.bg`
only because the shortcut writes to `style.background` after `style`
is captured).
- Defers to `node("panel", ...)` so any panel-specific renderer arm
changes flow through automatically.
- Children default to `{}` — an empty panel renders as a bordered
spacer.
- `scroll = true` inserts a single `scrollArea` child wrapping the
caller's children. Pair with a `maxHeight` (or `scrollMaxHeight` to
bound only the scroll region) so the scrollArea has something to
scroll against — without a bound the scrollArea fills its parent and
no scrolling is observed.
# plot
Plot is a Luau builder over `canvas` interaction props (`onDrag`,
`onScroll`, `onPointerMove`). Rebuilds the pan/zoom/legend/crosshair
UX from canvas primitives so there is no `egui_plot` dependency. The
module returns a callable table — `Z.plot(id, spec, opts)` builds the
widget, while `.line` / `.points` / `.heatmap` / `.boxPlot` /
`.bezierLine` are element helpers that tag specs with the right `type`.
## Exports
- `Plot.line(spec: LineSpec) -> LineSpec` — tag a spec with `type = "line"`.
- `Plot.points(spec: PointsSpec) -> PointsSpec` — tag a spec with `type = "points"`.
- `Plot.heatmap(spec: HeatmapSpec) -> HeatmapSpec` — tag a spec with `type = "heatmap"`.
- `Plot.boxPlot(spec: BoxPlotSpec) -> BoxPlotSpec` — tag a spec with `type = "boxPlot"`.
- `Plot.bezierLine(p0, p1, p2, p3, samples?, opts?) -> LineSpec` — sample a cubic bezier into a `LineSpec`.
- `__call(id, plotSpec, opts) -> any` — calling the table builds the plot widget itself.
Types:
- `Point = { number }` (2-element)
- `LineSpec = { type?, id?, name?, color?, points?, y?, width?, gradient?, fillY?, fillColor?, lineStyle? }`
- `PointsSpec = { type?, id?, name?, color?, points?, shape?, radius?, filled? }`
- `HeatmapSpec = { type?, id?, name?, values?, cols?, palette?, showLabels? }`
- `BoxPlotSpec = { type?, id?, name?, boxes?, horizontal? }`
- `PlotOptions = { showAxes?, showGrid?, showCrosshair?, invertX?, invertY?, legend?, showCoordinates?, coordinatesCorner?, allowZoom?, allowDrag?, allowScroll?, linkGroup?, linkAxis?, linkCursor?, xTickFormat?, yTickFormat? }`
- `PlotSpec = { options?: PlotOptions, elements?: { any } }`
- `PlotOpts = { width?, height?, style?, background?, classes?, label?, app? }`
## Usage
```luau
local Plot = require("@builtin::modules.zui.widget.plot")
local widget = Plot("chart-1", {
options = { showGrid = true, legend = { show = true } },
elements = {
Plot.line({ points = { { 0, 0 }, { 1, 0.5 }, { 2, 0.2 } }, name = "A" }),
Plot.points({ points = { { 1, 0.5 } }, radius = 6 }),
},
}, { width = 480, height = 240 })
```
## Notes
- Pan/zoom state lives in `ui.widgetState(id, ...)`; the same `id`
across renders preserves the viewport.
- `linkGroup` syncs pan/zoom across multiple plots — set `linkAxis`
/ `linkCursor` per axis to opt each plot in.
- Shift+Drag triggers boxed-zoom marquee selection; non-shift drag pans.
- `xTickFormat` / `yTickFormat` accept `function(v: number) -> string`
to override the default D3 nice-tick labelling.
- Heatmap `cols` defines column count — rows are inferred from
`#values / cols`.
# popup
Anchored floating popup. Wraps `egui::Popup` (added 0.32). Pins
itself to a referenced widget's rect — useful for button-anchored
dropdowns, autocompletes, callouts. The anchor MUST render before the
popup in the tree, otherwise the rect lookup misses and the popup
silently does not paint.
## Exports
- `popup(opts: Opts?) -> any` — build the popup widget node. Returned directly by the module.
Types:
- `Opts = { id?, anchor: string, pivot?, open?, onDismiss?, focusable?, children?, props?, style? }`
## Usage
```luau
local popup = require("@builtin::modules.zui.widget.popup")
Z.btn("Save", "saveBtn"),
popup({
anchor = "saveBtn",
open = state.popupOpen,
onDismiss = "save:popup-dismiss",
children = {
Z.btn("PNG", "save:png"),
Z.btn("JPG", "save:jpg"),
},
})
```
## Notes
- The `anchor` is required — the wrapper asserts and errors loudly on
nil rather than silently failing.
- Pivot maps to egui's `RectAlign`: `"belowLeft"` → BOTTOM_START
(default), `"belowRight"` → BOTTOM_END, `"aboveLeft"` → TOP_START,
`"aboveRight"` → TOP_END.
- Auto-dismiss fires `onDismiss` on click-outside / Escape so the
caller can mirror the new state. Falls back to `<id>-dismiss` if
`onDismiss` is omitted.
- The Lua-facing key is `anchor`; the underlying Rust prop is
`anchorTo` (egui already claims `anchor` for an enum). The wrapper
bridges the two names automatically.
# progressBar
Horizontal progress bar — a Luau builder over `canvas` with
`fillWidth` + `"N%"` coords. Emits two stacked `kind = "rect"`
commands: a full-width track plus a percent-of-width fill clipped to
the value. `value` is clamped to `[0, 1]` so out-of-range inputs don't
paint outside the canvas.
## Exports
- `progressBar(value: number?, opts: Opts?) -> any` — build the canvas widget node. Returned directly by the module.
Types:
- `Style = { height?: number, color?: string, borderRadius?: number }`
- `Opts = { id?: string, classes?: any, color?: string, trackColor?: string, style?: Style }`
## Usage
```luau
local progressBar = require("@builtin::modules.zui.widget.progressBar")
local widget1 = progressBar(0.42)
local widget2 = progressBar(value, { color = "#7BC97B", trackColor = "#222" })
```
## Notes
- A11y: the canvas declares `role = "progressbar"` and ARIA value
attrs (`ariaValueNow`, `ariaValueMin = 0`, `ariaValueMax = 1`) so
the DOM mirror exposes the same shape as a native `<progress>`.
- `style.borderRadius` defaults to `height / 2` for a pill silhouette.
Override to 0 for a sharp-cornered look.
- The fill rect's `max.x` is a `"N%"` string — width resolves at
paint time via `fillWidth = true`, so the builder doesn't need to
know the canvas's pixel width at construction time.
# radioGroup
Luau builder for a single-select radio group composed of focusable
per-row canvases inside a panel. Each row draws its own background
highlight + circle glyph + label; click commits the selection,
arrow-keys cycle it. Wraps the rows in a panel with
`role="radiogroup"` so assistive tech reads it as a group.
## Exports
- `radioGroup(id: string, options: { any }?, selected: number?, opts: RadioGroupOpts?) -> any` — build a radio-group widget. The module returns this function directly.
Types:
- `RadioGroupOpts = { style: { [string]: any }?, classes: (string | { string })?, rowWidth: number?, rowHeight: number?, onChange: string?, app: any?, ariaLabel: string?, label: string? }`
## Usage
```luau
local radioGroup = require("@builtin::modules.zui.widget.radioGroup")
radioGroup("difficulty", { "Easy", "Normal", "Hard" }, state.diff, {
onChange = "ui:diff:change",
})
```
## Notes
- Single-select; `selected` is a 1-based index. The first call seeds
`ui.widgetState(id, "selected")` from the caller's arg; subsequent
ticks read state back from there.
- Keyboard nav (per-row canvas `onKey`): `ArrowDown` / `ArrowRight`
next, `ArrowUp` / `ArrowLeft` previous, `Home` -> 1, `End` ->
`#options`. Tab / Shift+Tab walk the per-row canvases via egui's
focus chain. Click also commits selection.
- `opts.onChange` is dispatched as a callback id on the surrounding
`Z.app` router with `data.value` set to the new 1-based index.
Without an app in scope, only `ui.widgetState` updates.
- Handlers are registered once per group id (deduped via
`app._radioGroupHandlers`); option-count and `onChange` swaps land
without re-registering.
# richText
Read-only multi-colored text widget. Pass a flat list of
`{ text, color, italic?, monospace? }` segments and the renderer builds
a single-flow `LayoutJob` from them — no edit buffer, no cursor, no
input handling. The same segment shape is consumed by `TextInput`
when `props.segments` is set; `Z.codeEditor` builds segments via the
highlighter modules under `zui.highlight.*` and passes them to
`TextInput`.
## Exports
- `richText(segments: { RichTextSegment }?, opts: RichTextOpts?) -> any` — build a styled-text widget. The module returns this function directly.
Types:
- `RichTextSegment = { text: string, color: string?, italic: boolean?, monospace: boolean? }`
- `RichTextOpts = { id: string?, classes: (string | { string })?, style: { [string]: any }? }`
## Usage
```luau
local richText = require("@builtin::modules.zui.widget.richText")
richText({
{ text = "hello ", color = "#fff" },
{ text = "world", color = "#0E639C" },
})
```
## Notes
- Read-only: no edit buffer, no cursor, no input handling. Use
`Z.codeEditor` or `TextInput` directly when text needs to be editable.
- The renderer produces a single-flow `LayoutJob` from the segments,
so a mid-sentence color change does not break line wrapping.
# rightPanel
Right-docked panel. Root-only — must be the top-level widget of its
registered screen.
## Exports
- `rightPanel(children: { any }?, opts: RightPanelOpts?) -> any` — build a right-docked panel widget. The module returns this function directly.
Types:
- `RightPanelOpts = { id: string?, classes: (string | { string })?, class: (string | { string })?, props: { [string]: any }?, style: { [string]: any }? }`
## Usage
```luau
local rightPanel = require("@builtin::modules.zui.widget.rightPanel")
rightPanel({ child1, child2 })
```
## Notes
- Root-only: must be the top-level widget of its registered screen.
Nesting a `rightPanel` inside another container is unsupported.
# scene
Pan/zoom 2D viewport. Wraps `egui::containers::Scene` (added 0.34).
Children render inside a transformed coordinate space — mouse-wheel
zooms, primary-drag pans (right-click stays free for context menus).
Transform state persists in egui's per-id temp data, so pan/zoom
carries across frames without caller plumbing.
## Exports
- `scene(opts: SceneOpts?) -> any` — build a pan/zoom 2D viewport widget. The module returns this function directly.
Types:
- `SceneOpts = { id: string?, props: { [string]: any }?, style: { [string]: any }?, children: { any }?, zoomRange: { number }?, initialPan: { x: number, y: number }?, initialZoom: number?, onTransformChange: string?, focusable: boolean? }`
## Usage
```luau
local scene = require("@builtin::modules.zui.widget.scene")
scene({
zoomRange = { 0.25, 4.0 },
onTransformChange = "graph:moved",
children = {
Z.canvas({ commands = drawNodes(state) }),
Z.area({ id = "node-1", pos = nodePos[1] }, { ... }),
},
})
```
## Notes
- `zoomRange` defaults to `[0.25, 4.0]` (overriding egui's default of
`0.0..=1.0` so wheel-zoom works in both directions).
- `initialPan` and `initialZoom` only apply on the first frame; once
the user pans or zooms the persisted rect takes over.
- `onTransformChange` payload is a comma-separated string
`"panX,panY,zoom"` — UiValue is scalar-only. Parse with
`string.split(value, ",")`. Falls back to `<id>-transform` when not
set.
- Pan is primary-button only — right-click stays free for
`Z.contextMenu` handlers on inner widgets.
# scroll
Scrollable container. Pass `maxHeight` (or `maxWidth`) to bound the
visible region; children beyond that get scrolled. Top-level shortcuts
`maxHeight` / `maxWidth` / `minHeight` / `minWidth` / `stickToBottom`
merge into `style` / `props` so the common case doesn't require nesting
under `style = { ... }`.
## Exports
- `scroll(children: any?, opts: ScrollOpts?) -> any` — build a scrollable container. The module returns this function directly.
Types:
- `ScrollOpts = { id?, classes?, props?, style?, maxHeight?, maxWidth?, minHeight?, minWidth?, stickToBottom? }`
## Usage
```luau
local scroll = require("@builtin::modules.zui.widget.scroll")
-- Shortcut form (preferred):
scroll(rows, { maxHeight = 200 })
-- Equivalent verbose form:
scroll(rows, { style = { maxHeight = 200 } })
```
For tall content inside `Z.panel`, prefer `Z.panel(rows, { scroll =
true, maxHeight = N })` — see the [panel README](../panel.module/README.md)
for the pattern documented under issue #3270.
## Notes
- Either a single widget table or an array of widgets is accepted as
`children` — single widgets do not need to be wrapped in `{ ... }`
(closes #2331).
- Without a `maxHeight` / `maxWidth` (top-level or `style.*`), the
scroll area fills the parent's available rect and scrolls on overflow
(renderer applies `auto_shrink([false, false])` in that case). With a
bound, the scrollArea sizes to it and scrolls past that bound.
# section
Panel with a bold header label on top. Convenience composition — every
demo had its own version before this widget existed. The header style
defaults to a small accent label; override via `opts.headerStyle`.
## Exports
- `section(title: any, children: { any }?, opts: SectionOpts?) -> any` — build a panel with a bold header label. The module returns this function directly.
Types:
- `SectionOpts = { id: string?, classes: (string | { string })?, props: { [string]: any }?, style: { [string]: any }?, headerStyle: { [string]: any }?, titleColor: string?, bg: string?, border: string?, borderWidth: number?, padding: any?, gap: number?, minWidth: number?, minHeight: number?, maxWidth: number?, maxHeight: number? }`
## Usage
```luau
local section = require("@builtin::modules.zui.widget.section")
section("Settings", { Z.label("hello") })
```
## Notes
- The `title` is coerced via `tostring`, so non-string values are
accepted as headers.
- `opts.headerStyle` fully replaces the default header style — pass a
table containing every field you want set, not a partial override.
- All standard panel options (`bg`, `border`, `padding`, ...) flow
through to the wrapping panel.
# selectableList
Luau builder for a single-select listbox composed of focusable per-row
canvases inside a panel. Same shape as `Z.radioGroup`, but rows draw
no glyph — they're highlight-on-selection labels — and the wrapping
panel declares `role="listbox"` / row `role="option"` so screen
readers read it as a single-select list.
## Exports
- `selectableList(id: string, options: { any }?, selected: number?, opts: SelectableListOpts?) -> any` — build a listbox widget. The module returns this function directly.
Types:
- `SelectableListOpts = { style: { [string]: any }?, classes: (string | { string })?, rowWidth: number?, rowHeight: number?, onChange: string?, app: any?, ariaLabel: string?, label: string? }`
## Usage
```luau
local selectableList = require("@builtin::modules.zui.widget.selectableList")
selectableList("category", CATEGORIES, state.cat, {
onChange = "ui:cat:change",
})
```
## Notes
- Single-select; `selected` is a 1-based index. The first call seeds
`ui.widgetState(id, "selected")` from the caller's arg; subsequent
ticks read state back from there.
- Keyboard nav (per-row canvas `onKey`): `ArrowDown` / `ArrowRight`
next, `ArrowUp` / `ArrowLeft` previous, `Home` -> 1, `End` ->
`#options`. Tab walks the per-row canvases via egui's focus chain.
- For sidebar / asset-browser / category-picker patterns where every
option is visible at once. For long lists where only a few items fit,
wrap the result in `Z.scroll(...)`.
- `opts.onChange` is dispatched as a callback id on the surrounding
`Z.app` router with `data.value` set to the new 1-based index.
Without an app in scope, only `ui.widgetState` updates.
- Handlers are registered once per group id (deduped via
`app._selectableListHandlers`); option-count and `onChange` swaps
land without re-registering.
# sep
Horizontal separator — a Luau builder over `canvas` with `fillWidth`
+ `"N%"` coords. Emits a single `kind = "line"` command spanning
`[0, mid]` -> `["100%", mid]`. `fillWidth = true` makes the canvas
claim the parent's full available width. 4 px of vertical breathing
room is baked in (thickness + 4) so the line has a clear top/bottom
gap.
## Exports
- `sep(opts: SepOpts?) -> any` — build a horizontal-line separator widget. The module returns this function directly.
Types:
- `SepOpts = { id: string?, classes: (string | { string })?, style: { [string]: any }? }`
## Usage
```luau
local sep = require("@builtin::modules.zui.widget.sep")
sep()
sep({ style = { color = "#0E639C", height = 2 } })
```
## Notes
- Style overrides: `style.height` (default 1.0) sets line thickness in
pixels, `style.color` (default `#3C3C3C`) sets line color.
- Pure builder — no side effects, no state.
# sides
Two-slot horizontal row that anchors the first child left, the second
child right, and stretches a flexible gap between them. Designed for
window title bars, toolbars, status footers — any "title left,
controls right" pattern.
## Exports
- `sides(opts: SidesOpts?) -> any` — build a two-slot left/right row. The module returns this function directly.
Types:
- `SidesOpts = { left: any?, right: any?, [number]: any, id: string?, style: { [string]: any }? }`
## Usage
```luau
local sides = require("@builtin::modules.zui.widget.sides")
-- Positional shape
sides({ leftWidget, rightWidget })
-- Named-slot shape
sides({
left = Z.hbox({ Z.lbl("◆"), Z.lbl("zero") }),
right = Z.hbox({ Z.iconBtn("─"), Z.iconBtn("□"), Z.iconBtn("✕") }),
})
```
## Notes
- When more than two widgets are needed on either side, wrap them in a
layout container first (`Z.hbox` / `Z.vbox`).
- Implemented as an `hbox` containing `[left, flex(), right]`; the
flex-grow spacer makes the right slot hug the row's right edge.
- Children render in source order on both sides.
# slider
Horizontal slider for a numeric value in `[min, max]`. Emits the given
`onChange` callback id with `data.value` set to the new value. Pass
`step` to constrain to discrete increments.
## Exports
- `slider(id: string, value: number?, lo: number?, hi: number?, opts: SliderOpts?) -> any` — build a horizontal slider widget. The module returns this function directly.
Types:
- `SliderOpts = { props: { [string]: any }?, style: { [string]: any }?, onChange: string?, step: number? }`
## Usage
```luau
local slider = require("@builtin::modules.zui.widget.slider")
slider("volume", 0.5, 0, 1, { onChange = "ui:volume:change", step = 0.05 })
```
## Notes
- `value`, `lo`, `hi` all default to `0`, `0`, `1` respectively when nil.
- `onChange` callbacks fire with `data.value` set to the new numeric
value; route them via `component.onCallback` or a `Z.app` router.
# spacer
Fixed-size gap widget. Default 4 px. Use `Z.flex()` for a flex-grow
spacer that pushes siblings apart.
## Exports
- `spacer(n: number?) -> any` — build a fixed-size spacer widget. The module returns this function directly.
## Usage
```luau
local spacer = require("@builtin::modules.zui.widget.spacer")
spacer() -- 4 px gap
spacer(12) -- 12 px gap
```
## Notes
- Pure builder — no side effects, no state. Returns a widget table the
zui renderer understands directly.
- Use `Z.flex()` when you need a spacer that grows to fill remaining
space rather than a fixed size.
# split
Two-pane resizable split. `direction` is `"horizontal"` or
`"vertical"`; `firstSize` is the first pane's size in pixels (or
`0..1` for proportional). Children must be exactly two widgets.
## Exports
- `split(children: { any }?, opts: SplitOpts?) -> any` — build a two-pane resizable split widget. The module returns this function directly.
Types:
- `SplitOpts = { id: string?, direction: string?, firstSize: number?, props: { [string]: any }?, style: { [string]: any }? }`
## Usage
```luau
local split = require("@builtin::modules.zui.widget.split")
split({ leftWidget, rightWidget }, {
direction = "horizontal",
firstSize = 200,
})
```
## Notes
- `direction` defaults to `"horizontal"` when omitted.
- `firstSize` accepts pixels (>= 1) or a proportion in `0..1`.
- Children must be exactly two widgets — wrap multiple widgets in a
layout container if more pane content is needed.
# statRow
Label-value row — `[label] [value]` — with consistent label width,
theme-token defaults, and an optional value class/color. Used wherever
a stats panel hand-rolls a tiny `Z.hbox(label, value)` (runtime /
profiler / physics tabs).
`value` may be a string/number (rendered as a label) or a widget table
(rendered as-is — e.g. `Z.statusLabel`).
## Exports
- `statRow(labelText: any, value: any, opts: StatRowOpts?) -> any` — build a label-value row widget. The module returns this function directly.
Types:
- `StatRowOpts = { id: string?, class: (string | { string })?, fontSize: number?, labelWidth: number?, labelMinWidth: number?, labelColor: string?, labelClass: (string | { string })?, valueColor: string?, valueClass: (string | { string })?, bold: boolean?, gap: number?, align: string?, padding: any? }`
## Usage
```luau
local statRow = require("@builtin::modules.zui.widget.statRow")
statRow("Heap allocated", "12.4 MB", {
labelWidth = 140, valueClass = "debug-good", fontSize = 11,
})
statRow("Frame", Z.statusLabel(dtMs, { good = 16, warn = 33 }))
```
## Notes
- Label width defaults to 140 px, font size to 11.
- Label / value colors fall back to the active theme's `text_dim` /
`text` tokens respectively.
- The value slot accepts a widget table directly, which is the
idiomatic way to inline status-coloured values.
# statusLabel
Numeric label that auto-picks a class by threshold ranges. The caller
passes `{ good = X, warn = Y }` (sorted ascending). Values below `good`
get the `good` class; below `warn` get `warn`; the rest get `bad`.
Non-numeric values get the `bad` class so a missing/erroring data
source is visually loud. Defaults to the engine theme's
`debug-timing-good/warn/bad` classes shipped in `themes/debug.yaml`.
## Exports
- `statusLabel(value, thresholds, opts?) -> Node` — returns a coloured label widget. Module returns the builder function directly.
Types:
- `StatusClasses = { good: string, warn: string, bad: string }`
- `StatusThresholds = { good: number?, warn: number? }`
- `StatusLabelOpts = { id?, classes?, ratioOf?, fmt?, bold?, color?, fontSize? }`
## Usage
```luau
local statusLabel = require("@builtin::modules.zui.widget.statusLabel")
statusLabel(dtMs, { good = 16, warn = 33 })
statusLabel(used, { good = 0.8, warn = 0.95 }, {
ratioOf = max,
fmt = function(v) return string.format("%.1f%%", v * 100) end,
})
```
## Notes
- Pass `ratioOf` to compare `value / ratioOf` against the thresholds
while still feeding the *raw* value to `fmt`. Non-positive `ratioOf`
values are ignored.
- Pass custom `classes = { good, warn, bad }` to retarget styling. The
default classes live in `themes/debug.yaml`.
- Non-numeric `value` always renders in the `bad` class so a broken
data source is visually loud.
# svg
Inline vector graphics widget. Wraps a single `svg` node that
rasterizes an SVG document at the element's display resolution, so it
stays crisp from a 16px line icon to a 600px chart. Sizing comes from
`style.width` / `style.height`; `opts.fit` chooses the viewBox mapping.
## Exports
- `svg(source: string?, opts: SvgOpts?) -> WidgetNode` — module returns the builder function directly.
Options:
- `id: string?` — widget id.
- `style: table?` — passes through to the underlying node; supply `width`/`height` here, and `color` to ink `fill="currentColor"`.
- `fit: string?` — viewBox mapping: `"meet"` (default, uniform + letterbox), `"none"`/`"stretch"` (fill both axes), `"slice"` (uniform + crop). `preserveAspectRatio` keywords (e.g. `"xMidYMid meet"`) are accepted too.
- `src: string?` — render a `.svg` texture-asset reference instead of an inline `source` string.
## Usage
```luau
local Z = require("@builtin::modules.zui")
-- Inline document; currentColor inks the element's CSS color.
Z.svg("<svg viewBox='0 0 24 24'><path d='M4 12h16' stroke='currentColor' stroke-width='2'/></svg>", {
style = { width = 24, height = 24, color = "#3b82f6" },
})
-- From a .svg asset file.
Z.svg(nil, { src = "@builtin::icons.logo", style = { width = 64, height = 64 } })
```
## Notes
- Stateless — returns a fresh widget table each call.
- `fill="currentColor"` resolves to the element's CSS `color`; `fill`/`stroke`
gradients, the full path grammar, basic shapes, `viewBox`,
`preserveAspectRatio`, and `<g>` grouping all render.
- Pass either an inline `source` string or `opts.src` — `source` is the
document text, `src` points at a `.svg` asset file.
- Rasterization happens at the resolved display size, so scaling the widget
re-renders sharp rather than sampling a fixed bitmap.
# tabs
Tab strip — a horizontal row of buttons with one highlighted as
active. Each tab emits the callback id `<onChange>-<key>` so a single
pattern handler can capture every click and update the active tab in
state. Under a `Z.app` context the strip also intercepts arrow-key
navigation (with wrap-around, skipping disabled tabs) and dispatches
the same event a click would.
## Exports
- `tabs(items, activeKey, onChange, opts?) -> Node` — returns the tab-strip widget node. Module returns the builder function directly.
Types:
- `TabItem = { key: string, label?: string, icon?: string, enabled?: boolean }`
- `TabsOpts = { id?, app?, padding?, gap?, minTabWidth?, containerPadding?, style? }`
## Usage
```luau
local tabs = require("@builtin::modules.zui.widget.tabs")
local items = {
{ key = "entities", label = "Entities" },
{ key = "logs", label = "Logs" },
}
tabs(items, state.activeTab, "main-tabs")
app:on("^main%-tabs%-(.+)$", function(_v, _id, key)
state.activeTab = key
end)
```
## Notes
- The wrapper emits `{ type = "tabs", ... }`; the
`Z.defineWidget("tabs", ...)` registration in `zui.module/init.luau`
decodes that into the primitive `hbox` + `btn` tree the Rust
renderer sees.
- `activeKey` and `items` are mirrored into `widgetState` so the
per-strip key handler reads the live values at event time — closures
never go stale across re-renders.
- Tab itself stays the focus-traversal key (egui's built-in cycle);
only arrow keys are intercepted by the strip.
# ZuiTerminal
A terminal pane widget. Renders the live vt100 grid of a terminal from the
engine's terminal registry (created with `terminal.create`, run with
`terminal.spawn`) inside the UI tree. Captures the keyboard while focused; the
scroll wheel and Shift+PageUp/PageDown page the scrollback. Backed by a host PTY,
so terminals run on native targets.
# toggle
iOS-style on/off switch — a Luau builder over `canvas`. Draws a
rounded pill background, a white circle knob sliding along its axis,
and an optional text label next to it. Operable by mouse (click) and
keyboard (Tab to focus, Enter/Space to flip).
## Exports
- `toggle(label, id, checked, opts?) -> Node` — returns the toggle widget node. Module returns the builder function directly.
Types:
- `ToggleOpts = { style?, width?, height?, onColor?, offColor?, knobColor?, onChange?, classes?, ariaLabel?, app? }`
## Usage
```luau
local toggle = require("@builtin::modules.zui.widget.toggle")
toggle("Lights on", "lights", state.lights, { onChange = "lights:toggle" })
-- Without onChange, the callback id defaults to the widget id:
toggle("Bypass", "fx:bypass", state.bypass)
```
## Notes
- Under `Z.app` the internal `<id>:click` handler reads
`widgetState(id, "checked")`, flips it, and dispatches `onChange` (or
the widget id) with `{ value = newBool }`. The Router unpacks
`data.value` so `function(v) end` receives the new bool.
- Without `Z.app` the canvas's `onClick` routes directly to the
caller's callback id and the legacy `onCallback(id, _)` pattern
(caller flips its own local state) keeps working.
- DOM mirror surfaces as `<canvas role="switch" aria-checked="…">` for
screen-reader support.
# topPanel
Top-docked panel. Root-only. Pairs with `centralPanel` (and
optionally `bottomPanel`/`leftPanel`/`rightPanel`) for a docked app
shell — register each as its own screen with appropriate layer
ordering.
## Exports
- `topPanel(children, opts?) -> Node` — returns the top-panel widget node. Module returns the builder function directly.
Types:
- `TopPanelOpts = { id?, classes?, props?, style? }`
## Usage
```luau
local topPanel = require("@builtin::modules.zui.widget.topPanel")
topPanel({ menubar, breadcrumb })
```
## Notes
- Must be the top-level widget of the screen it's registered to —
nested topPanels render incorrectly.
- Pair with `centralPanel`/`bottomPanel`/`leftPanel`/`rightPanel` for
full docked-shell layouts; each lives on its own screen so their
layer ordering controls the dock.
# tree
Recursive expandable tree. Each node renders as a clickable row
(chevron + optional icon + label, indented by `depth * indentPx`, with
optional right-side action buttons). Clicking the chevron emits
`<onToggle>-<key>`; clicking the label emits `<onSelect>-<key>`. The
tree itself is stateless — toggle/select state lives in the caller's
state.
## Exports
- `tree(nodes, opts?) -> Node` — render a list of root nodes into a vbox of rows. Reached via the module's `__call` metamethod.
- `tree.fromFlat: (items, opts?) -> (roots, nodeById)` — re-exports the `fromFlat` sub-module that builds recursive nodes from a flat parent-pointer list.
Node shape:
- `{ key, label, children?, expandable?, expanded?, icon?, actions?, payload? }`
## Usage
```luau
local Z = { tree = require("@builtin::modules.zui.widget.tree") }
local function buildTree()
return Z.tree(state.nodes, {
onSelect = "ent-select",
onToggle = "ent-toggle",
selectedKey = state.selectedId,
})
end
app:on("^ent%-select%-(.+)$", function(_v, _id, key)
state.selectedId = key
end)
app:on("^ent%-toggle%-(.+)$", function(_v, _id, key)
state.expanded[key] = not state.expanded[key]
end)
```
## Notes
- The module returns a callable table — `tree(...)` works as a
function, and `tree.fromFlat(...)` reaches the sub-module. This is a
dynamic-dispatch shape; the `typed function` directive is skipped
here per the module-conversion spec rule 7.
- A row gets a chevron when it has children OR when `expandable ==
true` (lazy-load: the caller fetches children on the toggle event).
- `actions` callback ids are emitted verbatim — no key suffixing — so
a row-level action ("× delete") reads as the same callback whether
invoked from the tree, a context menu, or a toolbar.
- Hard depth cap (32) protects against accidentally cyclic node data.
# vbox
Vertical layout container. Children stacked top-to-bottom; spacing via
`style.gap`; horizontal alignment via `style.align` (`"start"` |
`"center"` | `"end"`).
## Exports
- `vbox(children, opts?) -> Node` — returns the vertical-layout widget node. Module returns the builder function directly.
Types:
- `VboxOpts = { id?, classes?, props?, style? }`
## Usage
```luau
local vbox = require("@builtin::modules.zui.widget.vbox")
vbox({ header, body, footer }, { style = { gap = 8, align = "center" } })
```
## Notes
- Pairs with `hbox` for horizontal layouts and `wrap`/`grid` widgets
for more complex flows.
- `style.gap` is the spacing between children, not padding around the
container — use `style.padding` for the latter.
# viewport
Embedded 3D viewport rendered into the UI. `target` is a render-target
handle id (paired with the Camera component's `renderTarget` setting).
Use for in-UI minimaps, picture-in-picture, scene previewers.
## Exports
- `viewport(target, opts?) -> Node` — returns the viewport widget node. Module returns the builder function directly.
Types:
- `ViewportOpts = { id?, props?, style? }`
## Usage
```luau
local viewport = require("@builtin::modules.zui.widget.viewport")
viewport(minimapTarget, { style = { width = 200, height = 200 } })
```
## Notes
- Pair with a Camera component whose `renderTarget` matches `target` —
the widget itself doesn't choose what to render, it just displays
the target's contents.
- Sizing comes from `style.width` / `style.height` (or layout); the
target's pixel resolution is set when the render target is created.
# window
Floating window. Root-only — must be the top-level widget of its
registered screen. Pass `movable`, `resizable`, `closable`, `pos`
(default position, only honored on first frame), and `onClose` to wire
the close button.
## Exports
- `window(title, children, opts?) -> Node` — returns the window widget node. Module returns the builder function directly.
Types:
- `WindowOpts = { id?, movable?, resizable?, closable?, pos?, onClose?, props?, style? }`
## Usage
```luau
local window = require("@builtin::modules.zui.widget.window")
window("Inspector", { body }, {
movable = true,
closable = true,
onClose = "inspector:close",
})
```
## Notes
- Signature is `window(title, children, opts)`; the older
`window(children, opts)` shape now warns loudly via `log.warn`
instead of falling back silently to the default `"Window"` header
(closes #2342).
- The decoder also accepts the raw form
`{ type = "window", title = "...", children = {...} }`; `title` is
promoted into `props.title` automatically.
- `pos` is only honored on first frame — subsequent renders preserve
the user's drag position so callers never fight egui for window
placement.
# Module (asset type)
A module is a reusable, stateless (or globally-stateful) Luau library
that other code pulls in with `require()`. Modules are the unit of
factored-out logic in a world: helpers, math libraries, format
parsers, registries, shared algorithms.
## When to use one
- You have logic you want to share across multiple components,
services, scenes, or tools.
- You have a registry, lookup table, or shared cache that callers all
read from / write to.
- You want a stable API surface (`M.fn`) other code can depend on.
If the logic is bound to one entity, use a `.component`. If you want a
named UI of fields rather than functions, use a `.preset`.
## Where it lives
- Source: `/zero/source/.../<name>.module/`
- Identity: the source path with `/` written as `.` and each segment's
type suffix dropped — `/zero/source/demo/beats.module` is
`demo.beats`, and `/zero/source/kit.package/beats.module` is
`kit.beats`, the container's name kept and its `.package` suffix
gone. `asset.create` returns this string, `asset.resolve(...).identity`
reads it back, and the `require` forms below write it as
`<identity>`.
- Folder shape:
- `init.luau` (or `init.lua`) — module body. **Required.** Returns
a table (conventionally named `M`).
- `README.md` — instance-level documentation. **Required.**
- `.metadata` — agent-editable tags + free-form fields. **Required.**
## How to create one
```luau
asset.create("module", "<name>")
-- Creates: /zero/source/<name>.module/
-- init.luau (canonical `local M = {} … return M`)
-- README.md (instance README template)
-- `folder` places it in a subfolder of /source, and that subfolder
-- leads the identity: `{ folder = "lib" }` produces `lib.<name>`.
-- `into` authors it inside a resolved container (a package, a toolbox),
-- whose own identity leads the same way:
asset.create("module", "<name>", { folder = "lib" })
asset.create("module", "<name>", { into = asset.resolve("myPkg.package") })
```
## How it operates
1. **Registration.** Writing `init.luau` into a `.module/` folder
indexes the asset and registers the module path with the resolver.
2. **Loading.** The first `require("<identity>")` runs
the file's body and caches the returned table. Subsequent requires
from anywhere return the **same table** — this is the
shared-state lever for "module-local" registries. The body runs in
an environment of the module's own: a name it declares without
`local` is readable by the module's own functions and by no other
script, so an export reaches its callers through the returned table
and nothing else. Requiring a component's folder runs its chunk the
same way, once, and its `update`, `start` and `public` stay in that
environment; a component runs on an entity through
`entity(id).component.add(name)`.
3. **Hot reload.** Editing the file re-runs the module body and folds
what it returns into the table already loaded, so that table keeps
its identity: a caller that captured it with `require` reads the new
source's functions and values through the reference it already
holds, and a later `require` returns that same table. A key the new
source drops goes away; a key something set at runtime stays. The
body's own `local`s start again from their initial values, so state
that must outlive an edit lives in `modules.state()`
(`guides { path: "core/scripting-and-tasks" }`).
4. **Identity resolution.** A module is reached by its `<identity>`,
and where the caller lives decides which spelling of it resolves.
For a module in a **world**, from a caller in that same world —
another module, a component, a scene entrypoint, or an `execute`
chunk:
- `require("<identity>")` — the identity on its own, resolved
against the caller's own root. It carries every folder segment,
so a module created with `{ folder = "demo" }` is
`require("demo.beats")`.
- `require("@root::<identity>")` — the same root-relative
resolution, written out.
- `require(".sibling")` — a module in the same folder, by its bare
name; `..name` steps up one folder, `...name` two.
Logs, stack traces and hot-reload notices name that same module
`@local.source.<identity>` — its key under the world source root.
The `<identity>` tail of that key is the form above, so a trace
reading `@local.source.demo.beats` is `require("demo.beats")`.
For a module in a **library** — content under
`/zero/source/libs/@<lib>/` — `@<lib>::` addresses that library's
root from anywhere: `require("@builtin::modules.transform")`.
Mounting a world as a library moves its files under such a root and
flips the caller root to `@<lib>::`, which is what keeps the
root-relative forms above resolving across the move.
## Discovery
- `asset.list("module")` — every registered module.
- `asset.inspect("<name>")` — public functions, source path, this
type README.
- `ls /zero/source/<name>.module` lists the files the folder holds.
## Authoring conventions
- Return a single `M` table from `init.luau`. Top-level statements
with side effects run on first require — useful for one-time
initialization, dangerous if they touch the engine before it's
ready.
- Write exported functions as `typed function`, not `function`: the
argument types are enforced at the call and the checker knows the
signature, so a caller's mistake is reported where they made it.
- Annotate exported functions with `--!desc` / `--!arg` / `--!return`
/ `--!example` so the LSP, `tools.list`, and `asset.inspect`
surface them. A function with no `--!desc` is reachable only by
someone already reading this file.
- Declare a VALUE with `Field.<kind>(default, mode, description)`, and
a table whose members are reached through a metatable with
`--!members <TypeName>` — the latter gives the surface its accepted
member set, its type, and its documentation from one table. See
`guides { path: "core/authoring" }` for all four rules and
`modules/api/engine/entity.module/members.module` for a worked
member table.
- Keep module state in module-local upvalues or in `modules.state()`.
A name the body declares without `local` lives in the module's
environment, which every run of the module shares: a function the
previous run left in place reads what the reload assigned. Module-locals start again from their
initial values with each hot reload; the table `modules.state()`
returns is the same table on both sides of every reload.
- Prefer focused modules over kitchen-sink modules. If two halves of a
module have no shared state, split them.
## Common pitfalls
- **Cyclic requires.** A `require` chain that loops will return the
partial table (the half built before the cycle was detected).
Design for one-way dependencies.
- **Engine-time side effects.** Don't `entity.spawn` at module
top-level — the engine may not be ready. Expose an `M.init` and
call it from a scene entrypoint.
- **Hot-reload + module-local cache.** A module that caches
expensive computation in upvalues loses that cache on reload —
fine for dev, but be aware in performance work.
- **`init.lua` vs `init.luau`.** Either works, `.luau` is canonical.
- **Writing one while play runs.** A `/source` write made while play is
running lands on the play shadow, and a guarded play-exit discards it
unless it is kept. One `.module` write shadows `init.luau`, the
`README.md` and the `.metadata` together.
`vfs.write(path, bytes, { durable = true })` skips the shadow, and
`vfs.promotePlayShadow` keeps what is already on it — the `core/vfs`
guide has the model and what each route costs.
## Related types
- `.component` — for entity-bound state + lifecycle hooks.
- `.service` — generates content you don't have yet (a mesh, sound, texture, …) via a metered provider.
- `.tool` — for a single agent-callable function with a YAML schema.
- `.package` — to group several modules + components + scenes into
one shippable folder.
## In the Inspector
Exports: what the module exports (name, kind, signature), parsed from its source without running it, with **Check** (the LSP's diagnostics for its entry file) and **Open**.
# dataView.selectionModel
Pure selection-interaction algebra for `Z.dataView`. Maps a row click plus
modifier state to a new selected-index set and anchor, following the standard
desktop model: plain click replaces, ctrl toggles, shift selects the contiguous
range from the anchor.
## Exports
- `M.resolveClick(index, mods, current, anchor) -> { selected: { number }, anchor: number }`
— 1-based indices; `mods` is `{ ctrl?, shift? }`; `current` is the current
selected-index array; `anchor` is the current anchor or nil.
## Notes
- Pure functions, no engine calls — unit-tested in the `editor_dataview` suite.
- Callers translate the returned indices into selection-service refs.
# dataView.view
Pure view computation for `Z.dataView` — filter then sort an item array into an
ordered list of 1-based indices.
## Exports
- `M.computeView(items, spec) -> { number }` — `spec` is
`{ filter?, sortKey?, sortDir?, textOf, valueOf }`. Filter is a case-insensitive
substring over `textOf(item)`; sort compares `valueOf(item, sortKey)`
numerically or case-insensitively, ascending or descending, with a stable
tiebreak on the original index.
## Notes
- Pure functions, no engine calls — unit-tested in the `editor_dataview` suite.
# dataView.virtual
Pure virtualization window math for `Z.dataView` — given a scroll position and
geometry, compute the inclusive range of row indices that are visible.
## Exports
- `M.windowFor(scrollTop, viewportH, rowH, count, overscan) -> { first, last }`
— 1-based inclusive; `last < first` when the dataset is empty. `overscan`
extends the window above and below the visible band.
## Notes
- Pure functions, no engine calls — unit-tested in the `editor_dataview` suite.
- Backs the row-window rendering; the same math would drive a future
construction-virtualization provider.
# breadcrumb
Breadcrumb path widget — renders `/zero/runtime/scenes/...` as a row
of clickable segments. Each segment emits a callback id carrying the
absolute path up to and including that segment, so a single router
rule reaches every navigation target. Stateless — caller passes the
current absolute path and a callback prefix; receives a hbox.
## Exports
- `breadcrumb(path: string, opts: BreadcrumbOpts?) -> WidgetNode` — build a hbox of breadcrumb segments. Home (`⌂`) segment always renders first; each `/`-delimited segment renders as a button whose callback id is `<onNavigate>-<absolute-path>`.
Types:
- `BreadcrumbOpts = { id: string?, onNavigate: string? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
local crumb = Z.fs.breadcrumb("/zero/runtime/scenes/", {
onNavigate = "files-nav",
})
app:on("^files%-nav%-(.+)$", function(_v, _id, path)
state.currentPath = path
end)
```
## Notes
- Stateless. No state ownership, no engine calls beyond the widget
primitives.
- A trailing slash on the input path is stripped before splitting
unless the whole input is `/`.
- The home crumb's callback id is `<onNavigate>-/` so a single router
rule (`^files%-nav%-(.+)$`) covers root too.
# controller
The state half of the generic Explorer. The `Z.fs.*` builders are stateless (data in, widgets out); this controller owns the VFS-backed navigation state and the callback routing that drives them, so both the Files panel and the save/load dialog reuse one model and one router.
It operates on a caller-owned `slot` table (so two Explorers — e.g. the panel and a dialog — keep independent state) and a caller-chosen callback `prefix` (so their widgets' callbacks don't collide). The controller caches directory listings, tracks the current directory, the expanded folder set, the selected path, and a file preview.
## API
- `M.init(slot, opts?) -> slot` — idempotently seed a controller state slot. `opts.root` defaults to `/zero/`.
- `M.model(slot)` — build the render model the `Z.fs.explorer` / `Z.fs.dialog` builders consume: `{ root, currentDir, breadcrumbPath, treeRoots, listEntries, selectedPath, expanded, preview }`.
- `M.handle(slot, prefix, callbackId, data?) -> boolean` — route an Explorer callback against this slot; returns true when handled.
- `M.invalidate(slot, pathPrefix?)` — drop cached listings under `pathPrefix` (or all when nil) so fresh writes show.
- `M.readPreview(path) -> (text|nil, note, size)` — read a file preview; refuses binary, truncates large text.
- `M.confirmTarget(slot, mode, filename) -> path|nil` — resolve the absolute target a dialog confirm should act on. In `"save"` mode it's `currentDir .. filename` (nil if filename is empty); in `"open"` mode it's the selected file (nil if nothing or a folder is selected).
## Callback grammar
All callbacks carry the absolute path verbatim:
- `<prefix>-nav-<path>` — breadcrumb segment
- `<prefix>-tree-select-<path>` — tree row
- `<prefix>-tree-toggle-<path>` — tree chevron
- `<prefix>-list-<d|f>-<path>` — details-list row (`d` = dir, `f` = file)
- `<prefix>-up` — parent directory
- `<prefix>-refresh` — drop cache for the visible subtree
## Usage
```luau
local fsc = require("modules.zui.widget.fs.controller")
fsc.init(state.files, { root = "/zero/" })
local model = fsc.model(state.files)
local widget = Z.fs.explorer(model, { prefix = "files" })
-- in onCallback:
if fsc.handle(state.files, "files", callbackId, data) then end
```
# detailsList
The right pane of the two-pane Explorer: a details list of one directory's entries with an icon, name, and kind column. Folders sort first (warm accent), then files. Stateless — the caller passes the entries (each already carrying its absolute `path`) and a callback prefix, and receives a scrollable column of clickable rows.
A row click emits `<onActivate>-<d|f>-<path>` — the `d`/`f` marker tells the handler folder-vs-file without a second lookup, and the absolute path is carried verbatim. Each row shows a phosphor icon, a clickable name button, and a kind column derived from the file extension.
The module returns the builder function directly.
## Builder
`build(entries?, opts?) -> widget node`.
- `entries` — array of `{ name, isDirectory?, path }` (path = the entry's absolute path).
- `opts` (`DetailsListOpts`) — `id`, `onActivate` (callback prefix; rows emit `<onActivate>-<d|f>-<path>`), `selectedPath` (the highlighted row), `maxHeight` (caps the scroll height; otherwise the pane fills available height via flex), `showHeader` (the Name · Kind header row, default on).
Returns a scroll-wrapped column with an optional header row and one row per entry; an empty list renders `(empty)`.
## Usage
```luau
Z.fs.detailsList(entries, {
onActivate = "files-list",
selectedPath = state.selectedPath,
})
```
# dialog
A modal save / load file picker: the same two-pane Explorer (`Z.fs.explorer`) inside a `Z.modal`, plus a filename field (save mode) and Open/Save + Cancel buttons. The panel and the dialog share one Explorer and one controller, so navigating feels identical in both.
Stateless builder: pass the controller model and the dialog options; the host owns `open`, the filename string, and the confirm/cancel wiring. The module returns the builder function directly.
## Builder
`build(model, opts?) -> widget node` (a `Z.modal` tree; renders nothing when `open` is false).
- `model` — the `Z.fs.controller.model(slot)` result for the dialog's own controller slot.
- `opts` (`DialogOpts`) — `prefix` (callback prefix, default `"fsdlg"`), `open` (modal visibility, host-owned), `title`, `mode` (`"save"` for a filename field, `"open"` default), `filename` (save-mode field value), `confirmLabel` (defaults to "Save"/"Open" by mode), `width` (default 640), `height` (default 460), `treeFrac`, `id`.
## Callbacks
Beyond the Explorer's `<prefix>-*` navigation:
- `<prefix>-filename` — filename field changed (value in the event payload)
- `<prefix>-confirm` — Open/Save pressed
- `<prefix>-cancel` — Cancel pressed or the modal dismissed
## Usage
```luau
-- host state: state.dlg = {} (controller slot), open, filename
Z.fs.dialog(Z.fs.controller.model(state.dlg), {
prefix = "savedlg", open = state.open, mode = "save",
title = "Save Layout", filename = state.filename,
confirmLabel = "Save",
})
-- host onCallback:
-- Z.fs.controller.handle(state.dlg, "savedlg", cb, data) -- navigation
-- "savedlg-filename" → state.filename = Z.eventValue(data)
-- "savedlg-confirm" → path = Z.fs.controller.confirmTarget(state.dlg, "save", state.filename)
-- "savedlg-cancel" → state.open = false
```
# explorer
A two-pane filesystem Explorer composite: a breadcrumb plus up/refresh actions on top, a folder tree on the left, and a details list (icon · name · kind) of the current directory on the right. Stateless — pass the model from `Z.fs.controller.model(slot)` and a callback `prefix`; the controller's `handle(slot, prefix, ...)` routes the callbacks this emits.
The same composite is the body of `Z.fs.dialog` (the modal save/load picker), so the panel and the dialog look and behave identically. The explorer fills its parent's height via flex, so the host panel just needs to give it room.
The module returns the builder function directly.
## Builder
`build(model, opts?) -> widget node`.
- `model` — the `Z.fs.controller.model(slot)` result: `{ root, currentDir, breadcrumbPath, treeRoots, listEntries, selectedPath, expanded }`.
- `opts` (`ExplorerOpts`) — `prefix` (callback prefix, default `"fs"`), `treeFrac` (tree pane fraction of width, 0..1, default 0.4), `id`.
Returns a vbox of the action row (up + refresh + breadcrumb) and a resizable horizontal split of the tree and details-list panes.
## Usage
```luau
local model = Z.fs.controller.model(state.files)
Z.fs.explorer(model, { prefix = "files", treeFrac = 0.4 })
```
# fileList
Flat row list of files in a directory. Folders first (orange), then
files (selected file highlighted). Stateless — caller passes the
entries array `[{name, isDirectory}]` and a callback prefix; receives
a scrollable vbox of clickable rows. Each click emits
`<onSelect>-<index>` where index is 1-based into the *original*
entries array, so the caller doesn't need a sorted-vs-original map.
## Exports
- `fileList(entries: { FileEntry }?, opts: FileListOpts?) -> WidgetNode` — build a scrollable vbox of rows. Folders style differently from files; the selected file row is highlighted.
Types:
- `FileEntry = { name: string, isDirectory: boolean? }`
- `FileListOpts = { id: string?, onSelect: string?, selectedKey: string?, sort: string?, maxHeight: number? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
return Z.fs.fileList(state.entries, {
onSelect = "files-row",
selectedKey = state.selectedName,
sort = "dirs_first", -- or "alpha"
})
app:on("^files%-row%-(%d+)$", function(_v, _id, idx)
state.selectedName = state.entries[tonumber(idx)].name
end)
```
## Notes
- Stateless. The caller owns the entries array and the selection key.
- The callback id carries an index (1-based) rather than the file
name, so unusual characters in paths can't break the router.
- `sort` defaults to `"dirs_first"` (folders alphabetically, then files
alphabetically). `"alpha"` ignores type. Any other value preserves
the caller's order.
- An empty entries array produces a single `(empty directory)` label.
# preview
File preview pane — header, optional note line ("Size: 12345 bytes" /
"Truncated: ..."), separator, and the body. Body is monospace text
when `text` is non-nil, or a "(no preview)" line when nil. Stateless:
caller decides what `text`/`note` should be by reading the file (e.g.
via `vfs.read`).
## Exports
- `preview(data: PreviewData?, opts: PreviewOpts?) -> WidgetNode` — build the preview pane. When all three `data` fields are nil, renders a "Select a file to preview." placeholder.
Types:
- `PreviewData = { name: string?, text: string?, note: string? }`
- `PreviewOpts = { id: string?, scrollHeight: number?, onCopyPath: string? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
return Z.fs.preview({
name = state.name,
text = state.text,
note = "Size: " .. tostring(state.size) .. " bytes",
}, {
id = "files-preview",
scrollHeight = 480,
onCopyPath = "files-copy",
})
```
## Notes
- Stateless. Caller owns the file read and decides what `text` and
`note` should be (truncation messaging, byte counts, hexdumps, etc.
are all the caller's job).
- `scrollHeight` defaults to 480; only applies when `data.text` is
non-nil (the body is wrapped in a `scroll` container).
- The copy-path button is only rendered when `opts.onCopyPath` is set;
the click emits that callback id verbatim so the caller routes it.
# tree
Folder tree composite. Wraps `Z.tree` with folder-friendly defaults:
folder icon for directories, file icon for leaves, callback ids that
carry the absolute path. Stateless — caller owns the recursive node
table. Use this when you want a single deep tree of folders + files;
for the classic two-pane ("folder tree | file list") layout, use this
for the left pane and `Z.fs.fileList` for the right.
## Exports
- `tree(roots: { FsNode }?, opts: FsTreeOpts?) -> WidgetNode` — build a recursive folder tree. Callback ids: `<onSelect>-<path>` (label click), `<onToggle>-<path>` (chevron click).
Types:
- `FsNode = { name: string, path: string?, isDirectory: boolean?, children: { FsNode }?, expanded: boolean? }`
- `FsTreeOpts = { id: string?, onSelect: string?, onToggle: string?, selectedKey: string?, expanded: { [string]: boolean }?, basePath: string?, indentPx: number?, gap: number? }`
- `WidgetNode = { [string]: any }`
## Usage
```luau
local Z = require("@builtin::modules.zui")
return Z.fs.tree(state.roots, {
onSelect = "files-tree-select",
onToggle = "files-tree-toggle",
selectedKey = state.selectedPath,
expanded = state.expandedSet,
})
app:on("^files%-tree%-select%-(.+)$", function(_v, _id, path)
state.selectedPath = path
end)
app:on("^files%-tree%-toggle%-(.+)$", function(_v, _id, path)
state.expandedSet[path] = not state.expandedSet[path]
end)
```
## Notes
- Stateless. Caller owns selection, expansion, and on-demand listing
(the `onToggle` handler is where you'd `vfs.list` and refill
`children` for the next render).
- Folders without listed children (`children == nil`) still get a
chevron via `expandable = true`. This is the lazy-load shape.
- `basePath` defaults to `/`. Used when an `FsNode` has no `path` —
the recursive walk builds the absolute path on the fly.