# gizlang/ui

Backend-agnostic high-level GUI layout and widget toolkit. Produces pure paint operations (UiOp) and hit targets (UiTarget) so the same declarative UI code runs identically across WebGPU, Three.js (GZ3J 2D pass), and Native GUI / GizOS (gizlang/graphics Scene).

```gizlang
import * as Ui from "gizlang/ui";
```

## Types

### `Box`

```gizlang
type Box = { x: f64; y: f64; w: f64; h: f64; }
```

Axis-aligned rectangle in logical UI units.

- `x`: `f64`
- `y`: `f64`
- `w`: `f64`
- `h`: `f64`

### `Color`

```gizlang
type Color = Vec<f64>
```

Straight RGBA color with channels in [0, 1].

### `UiTarget`

```gizlang
type UiTarget = { code: string; x: f64; y: f64; w: f64; h: f64; }
```

One interactive pointer target registered by a widget.

- `code`: `string`
- `x`: `f64`
- `y`: `f64`
- `w`: `f64`
- `h`: `f64`

### `UiOp`

```gizlang
type UiOp = { kind: string; x: f64; y: f64; w: f64; h: f64; radius: f64; fill: f64; size: f64; align: f64; bold: bool; text: string; color: Color; color2: Color; }
```

One backend-agnostic 2D paint operation emitted by Ui.

- `kind`: `string`
- `x`: `f64`
- `y`: `f64`
- `w`: `f64`
- `h`: `f64`
- `radius`: `f64`
- `fill`: `f64`
- `size`: `f64`
- `align`: `f64`
- `bold`: `bool`
- `text`: `string`
- `color`: `Vec<f64>`
- `color2`: `Vec<f64>`

### `RowAction`

```gizlang
type RowAction = { code: string; label: string; accent: Color; fg: Color; width: f64; }
```

One action button on the right side of an itemRow.

- `code`: `string`
- `label`: `string`
- `accent`: `Vec<f64>`
- `fg`: `Vec<f64>`
- `width`: `f64`

### `Theme`

```gizlang
type Theme = { accent: Color; ink: Color; surface: Color; surfaceAlt: Color; rowBg: Color; border: Color; text: Color; muted: Color; radius: f64; gap: f64; pad: f64; }
```

Design tokens shared by all built-in widgets.

- `accent`: `Vec<f64>`
- `ink`: `Vec<f64>`
- `surface`: `Vec<f64>`
- `surfaceAlt`: `Vec<f64>`
- `rowBg`: `Vec<f64>`
- `border`: `Vec<f64>`
- `text`: `Vec<f64>`
- `muted`: `Vec<f64>`
- `radius`: `f64`
- `gap`: `f64`
- `pad`: `f64`

### `UiInput`

```gizlang
type UiInput = { width: f64; height: f64; leftEdge: f64; topEdge: f64; rightEdge: f64; bottomEdge: f64; touch: bool; scale: f64; time: f64; pointerSeen: bool; pointerX: f64; pointerY: f64; measure: (text: string, size: f64, bold: bool) => f64; clicked: (code: string) => bool; pushing: (code: string) => bool; }
```

Frame input supplied by the host surface (Hud, Native Window, or headless test).

- `width`: `f64`
- `height`: `f64`
- `leftEdge`: `f64`
- `topEdge`: `f64`
- `rightEdge`: `f64`
- `bottomEdge`: `f64`
- `touch`: `bool`
- `scale`: `f64`
- `time`: `f64`
- `pointerSeen`: `bool`
- `pointerX`: `f64`
- `pointerY`: `f64`
- `measure`: `(arg0: string, arg1: f64, arg2: bool) => f64`
- `clicked`: `(arg0: string) => bool`
- `pushing`: `(arg0: string) => bool`

### `ModalFrame`

```gizlang
type ModalFrame = { rect: Box; body: Box; closed: bool; backdropClosed: bool; }
```

Result of opening a modal dialog with Ui.openModal.

- `rect`: `gizlang_ui.Box`
- `body`: `gizlang_ui.Box`
- `closed`: `bool`
- `backdropClosed`: `bool`

### `KeyBtnResult`

```gizlang
type KeyBtnResult = { width: f64; clicked: bool; }
```

Result of drawing a keycap toolbar button.

- `width`: `f64`
- `clicked`: `bool`

### `LayoutFrame`

```gizlang
type LayoutFrame = { kind: string; area: Box; cursor: f64; cursorY: f64; gap: f64; rowGap: f64; rowHeight: f64; }
```

Layout frame on the Ui stack.

- `kind`: `string`
- `area`: `gizlang_ui.Box`
- `cursor`: `f64`
- `cursorY`: `f64`
- `gap`: `f64`
- `rowGap`: `f64`
- `rowHeight`: `f64`

### `Ui`

```gizlang
class Ui { input: UiInput; theme: Theme; ops: Vec<UiOp> = []; targets: Vec<UiTarget> = []; private frames: Vec<LayoutFrame> = []; constructor(input: UiInput, theme: Theme = defaultTheme()) { this.input = input; this.theme = theme; } safeArea(): Box { return { x: this.input.leftEdge, y: this.input.topEdge, w: Math.max(1.0, this.input.rightEdge - this.input.leftEdge), h: Math.max(1.0, this.input.bottomEdge - this.input.topEdge) }; } upright(): bool { return this.input.height> this.input.width; } css(n: f64): f64 { return n * this.input.scale; } reach(h: f64): f64 { return this.input.touch ? Math.max(h, this.css(40.0)): h; } measure(text: string, size: f64, bold: bool = false): f64 { return this.input.measure(text, size, bold); } fit(text: string, size: f64, wide: f64, bold: bool = false): f64 { const w = this.measure(text, size, bold); return Math.min(size, size * Math.max(1.0, wide) / Math.max(1.0, w)); } hovered(r: Box): bool { if (this.input.touch || !this.input.pointerSeen) { return false; } return this.input.pointerX> = r.x && this.input.pointerX <= r.x + r.w && this.input.pointerY> = r.y && this.input.pointerY <= r.y + r.h; } hit(code: string, r: Box): bool { this.targets.push({ code, x: r.x, y: r.y, w: r.w, h: r.h }); return this.input.clicked(code); } beginColumn(area: Box, gap: f64 = 8.0, pad: f64 = 0.0): Box { const inner = pad> 0.0 ? inset(area, pad): area; this.frames.push({ kind: "col", area: inner, cursor: inner.y, cursorY: inner.y, gap, rowGap: gap, rowHeight: 0.0 }); return inner; } beginRow(area: Box, gap: f64 = 8.0, pad: f64 = 0.0): Box { const inner = pad> 0.0 ? inset(area, pad): area; this.frames.push({ kind: "row", area: inner, cursor: inner.x, cursorY: inner.y, gap, rowGap: gap, rowHeight: inner.h }); return inner; } beginWrap(area: Box, rowHeight: f64, gap: f64 = 7.0, rowGap: f64 = 6.0): void { this.frames.push({ kind: "wrap", area, cursor: area.x, cursorY: area.y, gap, rowGap, rowHeight }); } end(): f64 { if (this.frames.length === 0) { return 0.0; } const f = this.frames[this.frames.length - 1]; this.frames.pop(); if (f.kind === "wrap") { return f.cursorY + f.rowHeight; } if (f.kind === "col") { return f.cursor; } return f.area.y + f.area.h; } take(size: f64): Box { if (this.frames.length === 0) { return box(0.0, 0.0, size, size); } const idx = this.frames.length - 1; let f = this.frames[idx]; if (f.kind === "col") { const out = box(f.area.x, f.cursor, f.area.w, size); f.cursor = f.cursor + size + f.gap; this.frames[idx] = f; return out; } if (f.kind === "row") { const out = box(f.cursor, f.area.y, size, f.area.h); f.cursor = f.cursor + size + f.gap; this.frames[idx] = f; return out; } if (f.cursor> f.area.x && f.cursor + size> f.area.x + f.area.w) { f.cursor = f.area.x; f.cursorY = f.cursorY + f.rowHeight + f.rowGap; } const out = box(f.cursor, f.cursorY, size, f.rowHeight); f.cursor = f.cursor + size + f.gap; this.frames[idx] = f; return out; } space(size: f64): void { if (this.frames.length === 0) { return; } const idx = this.frames.length - 1; let f = this.frames[idx]; if (f.kind === "col" || f.kind === "row") { f.cursor = f.cursor + size; this.frames[idx] = f; } } remaining(): Box { if (this.frames.length === 0) { return this.safeArea(); } const f = this.frames[this.frames.length - 1]; if (f.kind === "col") { return box(f.area.x, f.cursor, f.area.w, Math.max(0.0, f.area.y + f.area.h - f.cursor)); } return box(f.cursor, f.area.y, Math.max(0.0, f.area.x + f.area.w - f.cursor), f.area.h); } splitRow(height: f64, count: i64, gap: f64 = 8.0): Vec<Box> { const row = this.take(height); return splitColumns(row, count, gap); } splitWeights(height: f64, weights: Vec<f64>, gap: f64 = 8.0): Vec<Box> { const row = this.take(height); return splitByWeights(row, weights, gap); } fillRect(r: Box, color: Color): void { this.ops.push({ kind: "box", x: r.x, y: r.y, w: r.w, h: r.h, radius: 0.0, fill: 0.0, size: 0.0, align: 0.0, bold: false, text: "", color, color2: [] }); } fillCard(r: Box, color: Color, radius: f64 = 12.0): void { this.ops.push({ kind: "card", x: r.x, y: r.y, w: r.w, h: r.h, radius, fill: 0.0, size: 0.0, align: 0.0, bold: false, text: "", color, color2: [] }); } panel(r: Box, bg: Color = this.theme.surfaceAlt, border: Color = this.theme.border, radius: f64 = this.theme.radius): void { this.ops.push({ kind: "panel", x: r.x, y: r.y, w: r.w, h: r.h, radius, fill: 0.0, size: 0.0, align: 0.0, bold: false, text: "", color: bg, color2: border }); } progressBar(r: Box, fill: f64, color: Color, back: Color = [0.10, 0.15, 0.24, 0.85]): void { this.ops.push({ kind: "bar", x: r.x + r.w * 0.5, y: r.y + r.h * 0.5, w: r.w, h: r.h, radius: r.h * 0.5, fill: Math.max(0.0, Math.min(1.0, fill)), size: 0.0, align: 0.0, bold: false, text: "", color, color2: back }); } disc(cx: f64, cy: f64, size: f64, color: Color): void { this.ops.push({ kind: "disc", x: cx, y: cy, w: size, h: size, radius: size * 0.5, fill: 0.0, size, align: 0.0, bold: false, text: "", color, color2: [] }); } glow(cx: f64, cy: f64, radius: f64, color: Color): void { this.ops.push({ kind: "glow", x: cx, y: cy, w: radius, h: radius, radius, fill: 0.0, size: 0.0, align: 0.0, bold: false, text: "", color, color2: [] }); } label(r: Box, text: string, size: f64, color: Color = this.theme.text, align: f64 = 0.0, bold: bool = false): void { const sz = this.fit(text, size, Math.max(1.0, r.w), bold); const tx = align === 0.5 ? r.x + r.w * 0.5: (align === 1.0 ? r.x + r.w: r.x); const ty = r.y + (r.h - sz * 1.18) * 0.5; this.ops.push({ kind: "text", x: tx, y: ty, w: r.w, h: r.h, radius: 0.0, fill: 0.0, size: sz, align, bold, text, color, color2: [] }); } textLine(text: string, size: f64, color: Color = this.theme.text, align: f64 = 0.0, bold: bool = false, height: f64 = 0.0): void { const h = height> 0.0 ? height: size * 1.45; this.label(this.take(h), text, size, color, align, bold); } backdrop(code: string, alpha: f64 = 0.62): bool { const full = box(0.0, 0.0, this.input.width, this.input.height); this.fillRect(full, [0.01, 0.02, 0.05, alpha]); return this.hit(code, full); } button(code: string, text: string, r: Box, accent: Color = this.theme.accent, fg: Color = this.theme.text, radius: f64 = 9.0, fontSize: f64 = 12.5): bool { const over = this.hovered(r); const bg: Color = over ? [Math.min(1.0, 0.06 + accent[0] * 0.26), Math.min(1.0, 0.09 + accent[1] * 0.26), Math.min(1.0, 0.16 + accent[2] * 0.26), 0.94]: [Math.min(1.0, 0.04 + accent[0] * 0.16), Math.min(1.0, 0.065 + accent[1] * 0.16), Math.min(1.0, 0.12 + accent[2] * 0.16), 0.88]; this.panel(r, bg, [accent[0], accent[1], accent[2], over ? 0.78: 0.38], radius); this.label(box(r.x + 7.0, r.y, Math.max(1.0, r.w - 14.0), r.h), text, fontSize, over ? [1.0, 1.0, 1.0, 1.0]: fg, 0.5, true); const grow = Math.min(6.0, (this.reach(r.h) - r.h) * 0.5); return this.hit(code, box(r.x, r.y - grow, r.w, r.h + grow * 2.0)); } pillButton(code: string, text: string, r: Box, color: Color = this.theme.accent, ink: Color = this.theme.ink, breathe: bool = true): bool { const over = this.hovered(r); if (breathe) { const pulse = 0.18 + 0.08 * Math.sin(this.input.time * 3.0); this.glow(r.x + r.w * 0.5, r.y + r.h * 0.5, r.w * 1.6, [color[0], color[1], color[2], over ? pulse + 0.10: pulse]); } const fill: Color = over ? [Math.min(1.0, color[0] + 0.14), Math.min(1.0, color[1] + 0.08), Math.min(1.0, color[2] + 0.08), 1.0]: color; this.fillCard(r, fill, r.h * 0.5); this.label(box(r.x + 12.0, r.y, Math.max(1.0, r.w - 24.0), r.h), text, Math.min(20.0, r.h * 0.40), ink, 0.5, true); return this.hit(code, r); } keyButton(code: string, keyCap: string, label: string, accent: Color = this.theme.accent, height: f64 = 28.0): bool { const hasKey = keyCap !== "" && !this.input.touch; const lSize = this.input.touch ? 14.0: 12.5; const kSize = 11.0; const kW = hasKey ? Math.max(20.0, this.measure(keyCap, kSize, true) + 10.0): 0.0; const lW = this.measure(label, lSize, true); const w = (hasKey ? (8.0 + kW + 7.0): 12.0) + lW + 12.0; const r = this.take(w); const hh = r.h> 0.0 ? r.h: this.reach(height); const b = box(r.x, r.y, w, hh); const over = this.hovered(b); const bg: Color = over ? [0.09, 0.14, 0.23, 0.90]: [0.035, 0.06, 0.11, 0.78]; this.panel(b, bg, [accent[0], accent[1], accent[2], over ? 0.65: 0.32], 9.0); this.fillCard(box(b.x + 1.0, b.y + 5.0, 2.5, Math.max(8.0, hh - 10.0)), [accent[0], accent[1], accent[2], over ? 1.0: 0.85], 1.2); let tx = b.x + 11.0; if (hasKey) { const ky = b.y + (hh - 18.0) * 0.5; this.panel(box(b.x + 8.0, ky, kW, 18.0), [1.0, 1.0, 1.0, over ? 0.16: 0.10], [accent[0], accent[1], accent[2], over ? 0.62: 0.38], 5.0); this.label(box(b.x + 8.0, ky, kW, 18.0), keyCap, kSize, [accent[0], accent[1], accent[2], 1.0], 0.5, true); tx = b.x + 8.0 + kW + 7.0; } this.label(box(tx, b.y, Math.max(1.0, b.x + w - tx - 8.0), hh), label, lSize, over ? [1.0, 1.0, 1.0, 1.0]: [0.94, 0.97, 1.0, 0.96], 0.0, true); return this.hit(code, b); } tabBar(prefix: string, labels: Vec<string>, active: i64, height: f64 = 30.0, accent: Color = this.theme.accent): i64 { const cols = this.splitRow(height, labels.length, 6.0); let picked = -1; for (const [i, col] of cols.entries()) { const on = i === active; const c = on ? accent: [0.48, 0.62, 0.80, 0.55]; const fg = on ? [1.0, 1.0, 1.0, 1.0]: [0.76, 0.84, 0.94, 0.88]; if (this.button(`${prefix }${ i }`, labels[i], col, c, fg, 9.0, 12.5)) { picked = i; } } return picked; } openModal(width: f64, height: f64, title: string, closeCode: string, closeLabel: string, accent: Color = this.theme.accent, backdropAlpha: f64 = 0.62): ModalFrame { const backdropClosed = this.backdrop("V_BACKDROP", backdropAlpha); const safe = this.safeArea(); const mw = Math.min(safe.w, width); const mh = Math.min(this.input.height - 88.0, height); const mx = (this.input.width - mw) * 0.5; const my = (this.input.height - mh) * 0.5; const rect = box(mx, my, mw, mh); void(this.hit("V_MODAL_BODY", rect)); this.panel(rect, this.theme.surface, [accent[0], accent[1], accent[2], 0.40], 18.0); const inner = this.beginColumn(rect, 8.0, 16.0); const hdr = this.take(30.0); const closeW = closeCode !== "" ? Math.max(76.0, this.measure(closeLabel, 12.5, true) + 22.0): 0.0; this.label(box(hdr.x, hdr.y, Math.max(1.0, hdr.w - closeW - 8.0), hdr.h), title, 15.5, [1.0, 0.88, 0.42, 1.0], 0.0, true); let closed = false; if (closeCode !== "") { closed = this.button(closeCode, closeLabel, box(hdr.x + hdr.w - closeW, hdr.y, closeW, 28.0), accent, [0.95, 0.98, 1.0, 1.0]); } return { rect, body: inner, closed, backdropClosed }; } itemRow(text: string, actions: Vec<RowAction>, height: f64 = 36.0): string { const row = this.take(height); this.panel(row, this.theme.rowBg, [0.60, 0.80, 1.0, 0.14], 9.0); let right = row.x + row.w - 6.0; let clicked = ""; for (let i = actions.length - 1; i> = 0; i - = 1) { const a = actions[i]; const bw = a.width> 0.0 ? a.width: 76.0; right - = bw; const br = box(right, row.y + 4.0, bw, Math.max(20.0, height - 8.0)); if (this.button(a.code, a.label, br, a.accent, a.fg, 8.0, 12.2)) { clicked = a.code; } right - = 6.0; } this.label(box(row.x + 10.0, row.y, Math.max(1.0, right - row.x - 14.0), row.h), text, 12.8, this.theme.text, 0.0, true); return clicked; } toast(text: string, y: f64, accent: Color = [1.0, 0.84, 0.40, 1.0]): f64 { const safeW = this.safeArea().w; const sz = this.fit(text, 13.5, safeW - 32.0, true); const w = Math.min(safeW, this.measure(text, sz, true) + 28.0); const r = box((this.input.width - w) * 0.5, y, w, 30.0); this.panel(r, [0.04, 0.08, 0.16, 0.84], [accent[0], accent[1], accent[2], 0.34], 15.0); this.label(r, text, sz, [1.0, 0.92, 0.58, 1.0], 0.5, true); return y + 30.0; } sliderRow(r: Box, label: string, shown: string, share: f64, picked: bool, span: f64, k: f64 = 1.0): void { if (picked) { this.fillCard(box(r.x - 16.0 * k, r.y + 3.0 * k, r.w + 32.0 * k, r.h - 6.0 * k), [0.45, 0.9, 1.0, 0.13], 12.0 * k); } const controlRight = r.x + r.w; const controlLeft = controlRight - span; this.label(box(r.x, r.y, Math.max(80.0, controlLeft - r.x - 12.0 * k), r.h), label, 19.0 * k, picked ? [1.0, 1.0, 1.0, 1.0]: [0.88, 0.90, 0.94, 0.92], 0.0, false); const track = span * 0.72; const t = Math.max(0.0, Math.min(1.0, share)); const x0 = controlRight - track; const mid = r.y + r.h * 0.5; this.progressBar(box(x0, mid - 3.0 * k, track, 6.0 * k), t, this.theme.accent, [1.0, 1.0, 1.0, 0.14]); this.disc(x0 + track * t, mid, 18.0 * k, [1.0, 1.0, 1.0, 1.0]); this.label(box(controlLeft, r.y, Math.max(1.0, x0 - controlLeft - 14.0 * k), r.h), shown, 16.0 * k, [0.80, 0.85, 0.90, 0.95], 1.0, false); } switchRow(r: Box, label: string, shown: string, on: bool, picked: bool, span: f64, k: f64 = 1.0): void { if (picked) { this.fillCard(box(r.x - 16.0 * k, r.y + 3.0 * k, r.w + 32.0 * k, r.h - 6.0 * k), [0.45, 0.9, 1.0, 0.13], 12.0 * k); } const controlRight = r.x + r.w; const controlLeft = controlRight - span; this.label(box(r.x, r.y, Math.max(80.0, controlLeft - r.x - 12.0 * k), r.h), label, 19.0 * k, picked ? [1.0, 1.0, 1.0, 1.0]: [0.88, 0.90, 0.94, 0.92], 0.0, false); const sw = 46.0 * k; const x0 = controlRight - sw; const mid = r.y + r.h * 0.5; this.fillCard(box(x0, mid - 13.0 * k, sw, 26.0 * k), on ? this.theme.accent: [1.0, 1.0, 1.0, 0.18], 13.0 * k); this.disc(on ? x0 + sw - 13.0 * k: x0 + 13.0 * k, mid, 20.0 * k, on ? this.theme.ink: [0.90, 0.92, 0.95, 1.0]); this.label(box(controlLeft, r.y, Math.max(1.0, x0 - controlLeft - 14.0 * k), r.h), shown, 16.0 * k, [0.80, 0.85, 0.90, 0.95], 1.0, false); } choiceRow(r: Box, label: string, shown: string, picked: bool, span: f64, k: f64 = 1.0): void { if (picked) { this.fillCard(box(r.x - 16.0 * k, r.y + 3.0 * k, r.w + 32.0 * k, r.h - 6.0 * k), [0.45, 0.9, 1.0, 0.13], 12.0 * k); } const controlRight = r.x + r.w; const controlLeft = controlRight - span; this.label(box(r.x, r.y, Math.max(80.0, controlLeft - r.x - 12.0 * k), r.h), label, 19.0 * k, picked ? [1.0, 1.0, 1.0, 1.0]: [0.88, 0.90, 0.94, 0.92], 0.0, false); const arrow: Color = picked ? this.theme.accent: [0.70, 0.75, 0.80, 0.80]; this.label(box(controlLeft + 28.0 * k, r.y, 24.0 * k, r.h), "‹", 22.0 * k, arrow, 0.5, true); this.label(box(controlRight - 20.0 * k, r.y, 20.0 * k, r.h), "›", 22.0 * k, arrow, 0.5, true); this.label(box(controlLeft + 52.0 * k, r.y, Math.max(1.0, controlRight - controlLeft - 72.0 * k), r.h), shown, 17.0 * k, [1.0, 1.0, 1.0, 0.95], 0.5, true); } }
```

High-level immediate-mode Flex layout and widget context.

- `input`: `gizlang_ui.UiInput`
- `theme`: `gizlang_ui.Theme`
- `ops`: `Vec<gizlang_ui.UiOp>`
- `targets`: `Vec<gizlang_ui.UiTarget>`
- `frames`: `Vec<gizlang_ui.LayoutFrame>`

## Functions

### `defaultTheme`

```gizlang
function defaultTheme(): Theme
```

Default obsidian-glass theme matching GizGame and GizOS surfaces.

Effects: fail, alloc.

### `box`

```gizlang
function box(x: f64, y: f64, w: f64, h: f64): Box
```

Constructs a Box.

### `inset`

```gizlang
function inset(b: Box, pad: f64): Box
```

Insets a Box on all four sides by PAD.

### `toArgb`

```gizlang
function toArgb(c: Color): i64
```

Converts a [0..1] RGBA Color to 0xAARRGGBB for gizlang/graphics.

Effects: fail.

### `constructor`

```gizlang
constructor(input: UiInput, theme: Theme = defaultTheme())
```

Effects: fail, read, write, alloc.

### `splitColumns`

```gizlang
function splitColumns(row: Box, count: i64, gap: f64 = 8.0): Vec<Box>
```

Splits ROW horizontally into COUNT equal-width boxes with GAP between them.

Effects: fail, alloc.

### `splitByWeights`

```gizlang
function splitByWeights(row: Box, weights: Vec<f64>, gap: f64 = 8.0): Vec<Box>
```

Splits ROW horizontally according to WEIGHTS with GAP between them.

Effects: fail, alloc.

### `paintToScene`

```gizlang
function paintToScene(ops: Vec<UiOp>, scene: Scene, font: Font, boldFont: Font): void
```

Native CPU / GizOS renderer: replays UiOps into a gizlang/graphics Scene.

Effects: fail, read, write, console, io, alloc.

## Methods

### `Ui.safeArea`

```gizlang
safeArea(): Box
```

Safe usable viewport rectangle inside screen margins/notches.

Effects: fail, read.

### `Ui.upright`

```gizlang
upright(): bool
```

Whether the viewport is portrait (taller than wide).

Effects: fail, read.

### `Ui.css`

```gizlang
css(n: f64): f64
```

N CSS pixels converted to logical UI units.

Effects: fail, read.

### `Ui.reach`

```gizlang
reach(h: f64): f64
```

Minimum comfortable touch target height when touch input is active.

Effects: fail, read.

### `Ui.measure`

```gizlang
measure(text: string, size: f64, bold: bool = false): f64
```

Measures TEXT width at SIZE.

Effects: fail, read, write, console, io, alloc.

### `Ui.fit`

```gizlang
fit(text: string, size: f64, wide: f64, bold: bool = false): f64
```

Largest font size <= SIZE at which TEXT fits inside WIDE.

Effects: fail, read, write, console, io, alloc.

### `Ui.hovered`

```gizlang
hovered(r: Box): bool
```

Whether the pointer hovers inside RECT (always false on touch).

Effects: fail, read.

### `Ui.hit`

```gizlang
hit(code: string, r: Box): bool
```

Registers a hit target for CODE and returns whether it was clicked this frame.

Effects: fail, read, write, console, io, alloc.

### `Ui.beginColumn`

```gizlang
beginColumn(area: Box, gap: f64 = 8.0, pad: f64 = 0.0): Box
```

Pushes a vertical column layout over AREA.

Effects: fail, read, write, alloc.

### `Ui.beginRow`

```gizlang
beginRow(area: Box, gap: f64 = 8.0, pad: f64 = 0.0): Box
```

Pushes a horizontal row layout over AREA.

Effects: fail, read, write, alloc.

### `Ui.beginWrap`

```gizlang
beginWrap(area: Box, rowHeight: f64, gap: f64 = 7.0, rowGap: f64 = 6.0): void
```

Pushes an auto-wrapping horizontal flow layout over AREA.

Effects: fail, read, write, alloc.

### `Ui.end`

```gizlang
end(): f64
```

Pops the current layout frame and returns its final bottom Y coordinate.

Effects: fail, read, write, alloc.

### `Ui.take`

```gizlang
take(size: f64): Box
```

Allocates the next slot of SIZE along the current column (height) or row (width).

Effects: fail, read, write, alloc.

### `Ui.space`

```gizlang
space(size: f64): void
```

Advances the current column or row cursor by SIZE.

Effects: fail, read, write, alloc.

### `Ui.remaining`

```gizlang
remaining(): Box
```

Remaining unallocated area inside the current layout frame.

Effects: fail, read.

### `Ui.splitRow`

```gizlang
splitRow(height: f64, count: i64, gap: f64 = 8.0): Vec<Box>
```

Allocates a row of HEIGHT from the current column and splits it into COUNT equal boxes.

Effects: fail, read, write, alloc.

### `Ui.splitWeights`

```gizlang
splitWeights(height: f64, weights: Vec<f64>, gap: f64 = 8.0): Vec<Box>
```

Allocates a row of HEIGHT from the current column and splits it by WEIGHTS.

Effects: fail, read, write, alloc.

### `Ui.fillRect`

```gizlang
fillRect(r: Box, color: Color): void
```

Emits a solid rectangle.

Effects: fail, read, write, alloc.

### `Ui.fillCard`

```gizlang
fillCard(r: Box, color: Color, radius: f64 = 12.0): void
```

Emits a rounded card.

Effects: fail, read, write, alloc.

### `Ui.panel`

```gizlang
panel(r: Box, bg: Color = this.theme.surfaceAlt, border: Color = this.theme.border, radius: f64 = this.theme.radius): void
```

Emits an obsidian glass panel with hairline border and top sheen.

Effects: fail, read, write, alloc.

### `Ui.progressBar`

```gizlang
progressBar(r: Box, fill: f64, color: Color, back: Color = [0.10, 0.15, 0.24, 0.85]): void
```

Emits a progress bar centered vertically inside R.

Effects: fail, read, write, alloc.

### `Ui.disc`

```gizlang
disc(cx: f64, cy: f64, size: f64, color: Color): void
```

Emits a circular disc centered at (CX, CY) with diameter SIZE.

Effects: fail, read, write, alloc.

### `Ui.glow`

```gizlang
glow(cx: f64, cy: f64, radius: f64, color: Color): void
```

Emits a soft radial glow centered at (CX, CY).

Effects: fail, read, write, alloc.

### `Ui.label`

```gizlang
label(r: Box, text: string, size: f64, color: Color = this.theme.text, align: f64 = 0.0, bold: bool = false): void
```

Emits text auto-fitted inside R with horizontal ALIGN (0 left, 0.5 center, 1 right).

Effects: fail, read, write, console, io, alloc.

### `Ui.textLine`

```gizlang
textLine(text: string, size: f64, color: Color = this.theme.text, align: f64 = 0.0, bold: bool = false, height: f64 = 0.0): void
```

Allocates a line of HEIGHT in the current column and draws auto-fitted text.

Effects: fail, read, write, console, io, alloc.

### `Ui.backdrop`

```gizlang
backdrop(code: string, alpha: f64 = 0.62): bool
```

Full-screen modal scrim that intercepts clicks as CODE.

Effects: fail, read, write, console, io, alloc.

### `Ui.button`

```gizlang
button(code: string, text: string, r: Box, accent: Color = this.theme.accent, fg: Color = this.theme.text, radius: f64 = 9.0, fontSize: f64 = 12.5): bool
```

Interactive styled button inside R; returns true when clicked.

Effects: fail, read, write, console, io, alloc.

### `Ui.pillButton`

```gizlang
pillButton(code: string, text: string, r: Box, color: Color = this.theme.accent, ink: Color = this.theme.ink, breathe: bool = true): bool
```

Primary filled pill button with subtle breathing glow.

Effects: fail, read, write, console, io, alloc.

### `Ui.keyButton`

```gizlang
keyButton(code: string, keyCap: string, label: string, accent: Color = this.theme.accent, height: f64 = 28.0): bool
```

Action toolbar button with optional keyboard badge on the left; works inside beginWrap.

Effects: fail, read, write, console, io, alloc.

### `Ui.tabBar`

```gizlang
tabBar(prefix: string, labels: Vec<string>, active: i64, height: f64 = 30.0, accent: Color = this.theme.accent): i64
```

Horizontal tab bar inside the current column; returns clicked tab index or -1.

Effects: fail, read, write, console, io, alloc.

### `Ui.openModal`

```gizlang
openModal(width: f64, height: f64, title: string, closeCode: string, closeLabel: string, accent: Color = this.theme.accent, backdropAlpha: f64 = 0.62): ModalFrame
```

Centered modal dialog: draws backdrop, panel, header with close button, and opens inner column.

Effects: fail, read, write, console, io, alloc.

### `Ui.itemRow`

```gizlang
itemRow(text: string, actions: Vec<RowAction>, height: f64 = 36.0): string
```

Styled list item row with left label and right-aligned action buttons; returns clicked code or "".

Effects: fail, read, write, console, io, alloc.

### `Ui.toast`

```gizlang
toast(text: string, y: f64, accent: Color = [1.0, 0.84, 0.40, 1.0]): f64
```

Centered auto-sized notification pill at Y; returns bottom Y.

Effects: fail, read, write, console, io, alloc.

### `Ui.sliderRow`

```gizlang
sliderRow(r: Box, label: string, shown: string, share: f64, picked: bool, span: f64, k: f64 = 1.0): void
```

Settings slider control row (label left, value + track + knob right).

Effects: fail, read, write, console, io, alloc.

### `Ui.switchRow`

```gizlang
switchRow(r: Box, label: string, shown: string, on: bool, picked: bool, span: f64, k: f64 = 1.0): void
```

Settings toggle switch control row (label left, value + pill switch right).

Effects: fail, read, write, console, io, alloc.

### `Ui.choiceRow`

```gizlang
choiceRow(r: Box, label: string, shown: string, picked: bool, span: f64, k: f64 = 1.0): void
```

Settings multi-choice selector row (label left, ‹ value › right).

Effects: fail, read, write, console, io, alloc.

