veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

ui/view

lib/ui/view.vk

lib/ui/view.vk Pure-Veko homoiconic declarative UI DSL, mobile viewport renderer, offscreen PNG screenshotter, and live 60fps desktop mobile-simulator previewer built on ui/canvas, ui/font, ui/layout, ui/widgets, image/png, and ui. Supports BOTH: 1. Strictly-typed primary declarative builders (screen, vstack, hstack, card, button, ...) with zero host capabilities required. 2. Homoiconic quote [...] dynamic / OTA view evaluation (eval-quoted) against a state map with zero eval and zero host capabilities.

Viewport struct
signature
Viewport = struct { name str, width i64, height i64, safe_top i64, safe_bottom i64, corner_r i64, has_island bool }

Physical and safe-area geometry for a target mobile or handheld device viewport.

TabItem struct
signature
TabItem = struct { id str, label str, badge str = ... }

Navigation item descriptor for tab-bar.

Node struct
signature
Node = struct { kind enum, id str = ..., text str = ..., value_s str = ..., value_n i64 = ..., flag bool = ..., props map = ..., action any = ..., items block = ..., children block[Node] = ... }

Immutable declarative UI virtual-DOM node.

signature
PreviewResult = struct { canvas cv/Canvas, triggered_actions block, scroll_max i64 }

Result of rendering and hit-testing a single mobile viewport frame.

signature
iphone-viewport = fn [] Viewport

Returns the iPhone 16 Pro viewport preset (393 x 852, Dynamic Island enabled).

Executable Example
veko
use [view = ui/view]
vp = view/iphone-viewport
if vp.width != 393 or vp.height != 852 or (not vp.has_island) [ err 'iphone-viewport' ] else [ .ok ]
signature
pixel-viewport = fn [] Viewport

Returns the Google Pixel 9 viewport preset (412 x 915).

signature
ipad-viewport = fn [] Viewport

Returns the iPad Mini tablet viewport preset (744 x 1024).

signature
compact-viewport = fn [] Viewport

Returns the rugged Field Handheld compact viewport preset (360 x 640).

signature
viewport-by-name = fn [name str] Viewport

Resolves a mobile Viewport preset by case-insensitive device alias ('iphone', 'pixel', 'ipad', 'compact').

signature
screen = fn [title str, props map, children block[Node]] Node

Root mobile screen container with navigation bar (title, optional subtitle, safe_area, trailing_label, trailing_action).

signature
vstack = fn [props map, children block[Node]] Node

Vertical flex stack (props: gap default 12, pad default 0).

signature
hstack = fn [props map, children block[Node]] Node

Horizontal row stack (props: gap default 10, pad default 0).

signature
zstack = fn [props map, children block[Node]] Node

Layered Z-axis overlay container.

signature
scroll = fn [props map, children block[Node]] Node

Scrollable vertical container (props: gap default 12, pad default 0).

card fn
signature
card = fn [title str, props map, children block[Node]] Node

Elevated rounded surface card (props: tone in .default | .accent | .success | .warning | .danger, pad default 14).

signature
section = fn [title str, children block[Node]] Node

Labeled group section with muted header title and stacked children.

row fn
signature
row = fn [props map, children block[Node]] Node

Horizontal list/detail row (props: on_tap, gap default 10, pad default 10).

grid fn
signature
grid = fn [cols i64, gap i64, children block[Node]] Node

Multi-column uniform grid layout with cols columns and gap spacing.

signature
sheet = fn [is_open bool, title str, close_action any, children block[Node]] Node

Modal bottom sheet overlay (is_open, title, close_action, children).

signature
tab-bar = fn [active_id str, select_prefix str, tabs block[TabItem]] Node

Docked bottom navigation tab bar (active_id, select_prefix, tabs).

text fn
signature
text = fn [content str] Node

Body text paragraph node.

signature
text-styled = fn [content str, props map] Node

Styled text node (props: size in .caption | .body | .subtitle | .title | .headline | .mono, tone in .default | .muted | .accent | .success | .warning | .danger, weight in .regular | .medium | .bold).

signature
secret-field-badge = fn [label str] Node

Masked .secret hygiene indicator pill (<secret ••••••••>) that never accepts or exposes raw secret text.

signature
banner = fn [tone enum, message str, visible bool] Node

Semantic alert banner (tone in .accent | .success | .warning | .danger, skipped during layout when visible == false).

signature
badge = fn [label str, tone enum] Node

Compact semantic status pill badge.

stat fn
signature
stat = fn [label str, value str, delta str, tone enum] Node

KPI metric tile with label, prominent value, delta badge, and semantic tone accent bar.

signature
button = fn [label str, action any] Node

Primary interactive button triggering action when tapped/clicked.

signature
button-styled = fn [label str, props map, action any] Node

Styled interactive button (props: style in .primary | .secondary | .danger | .ghost, disabled bool).

signature
checkbox = fn [label str, checked bool, action any] Node

Interactive checkbox row triggering action when tapped/clicked.

signature
toggle-switch = fn [label str, is_on bool, action any] Node

Interactive pill toggle switch row triggering action when tapped/clicked.

signature
text-field = fn [id str, placeholder str, value str, submit_action any] Node

Interactive single-line text input field with placeholder, value, and submit_action.

signature
progress = fn [pct i64, label str, tone enum] Node

Labeled horizontal progress bar (pct clamped 0..100) with semantic tone.

signature
sparkline = fn [title str, values block, tone enum] Node

Labeled mini trend sparkline card over numeric values.

signature
divider = fn [] Node

Crisp 1px horizontal divider line.

signature
spacer = fn [height i64] Node

Explicit vertical whitespace gap of height pixels.

signature
empty = fn [] Node

Zero-size placeholder node skipped completely during layout.

signature
for-each = fn [items block, item_fn fn[any->Node]] block[Node]

Maps items through item_fn into a typed block[Node].

signature
list-view = fn [items block, item_fn fn[any->Node]] Node

Builds a vertical .list_view container mapping items through item_fn.

signature
window = fn [title str, props map, children block[Node]] Node

Root native application window (Desktop) or top-level screen frame.

signature
menu-bar = fn [children block[Node]] Node

Native window / macOS app menu bar container holding menu nodes.

menu fn
signature
menu = fn [title str, children block[Node]] Node

Named pull-down menu containing menu-item and menu-divider nodes.

signature
menu-item = fn [label str, action any, props map] Node

Interactive menu entry (props: shortcut, disabled, checked).

signature
menu-divider = fn [] Node

Horizontal separator line inside a menu or context-menu.

signature
toolbar = fn [props map, children block[Node]] Node

Window chrome action toolbar (props: gap, pad, compact).

signature
status-bar = fn [segments block] Node

Window bottom status bar displaying formatted string segments.

signature
context-menu = fn [id str, items block, action any] Node

Right-click / long-press popup menu descriptor (items block of { id, label, action }).

signature
split-view = fn [props map, first Node, second Node] Node

Two-pane split view (props: id, ratio 0..100, vertical bool, min_first, min_second). Desktop/tablet renders a live draggable splitter; phones adapt to stacked/navigation panes.

tabs fn
signature
tabs = fn [id str, active_id str, action any, children block[Node]] Node

Tabbed container (active_id selected tab key, children block of tab nodes).

tab fn
signature
tab = fn [id str, label str, children block[Node]] Node

Individual page inside a tabs container.

form fn
signature
form = fn [props map, children block[Node]] Node

Two-column aligned form layout (props: label_width, gap, pad).

signature
group-box = fn [title str, props map, children block[Node]] Node

Titled native frame / preferences group container.

signature
heading = fn [content str] Node

Prominent section/panel heading text.

signature
label = fn [content str, props map] Node

Single- or multi-line semantic text label (props: tone, align, label_for).

signature
text-area = fn [id str, placeholder str, value str, action any] Node

Multi-line editable text area (id, placeholder, value, change_or_submit_action).

signature
password-field = fn [id str, placeholder str] Node

Zero-leak masked OS password control. Keystrokes stay inside the OS control and are read on demand via desktop/read-secret ctx id / native/read-secret as a .secret string.

signature
radio-group = fn [id str, options block, selected str, action any] Node

Mutually exclusive native radio button group (options block of strings, selected).

signature
select = fn [id str, options block, selected str, action any] Node

Native dropdown / combo-box selector (options block of strings, selected).

signature
slider = fn [id str, min_v i64, max_v i64, val i64, action any] Node

Native continuous range slider (min_v..max_v, integer val).

signature
list-box = fn [id str, items block, selected str, action any] Node

Scrollable single-selection native list box.

signature
tree-view = fn [id str, roots block, selected_id str, action any] Node

Hierarchical collapsible native tree view (roots block of { id, label, children } maps).

signature
table-view = fn [id str, columns block, rows block, selected_row i64, action any] Node

Multi-column native data table (columns header strings, rows block of row blocks).

signature
canvas-slot = fn [id str, props map] Node

Native surface hosting a custom ui/canvas framebuffer (props: width, height, canvas).

signature
webview = fn [id str, props map] Node

Embedded OS web engine view (props: html, url, on_ipc, height). Remote http(s):// URLs require .net capability; offline html / veko:// work under .ui.

signature
native-slot = fn [id str, handle i64, props map] Node

Escape-hatch slot embedding an externally created native OS widget handle (HWND/NSView/GtkWidget).

signature
eval-quoted = fn [qblock block, state map] Node

Evaluates a homoiconic quote [...] view block against state (map) with zero eval and zero host capabilities.

Executable Example
veko
use [view = ui/view]
q = quote [
  screen 'Field Sync' { subtitle = 'OTA v2' } [
    vstack { gap = 12 } [
      banner .warning 'Offline' (not state.online)
      button 'Sync Now' .sync_now
    ]
  ]
]
nd = view/eval-quoted q { online = false }
if nd.kind != .screen or nd.text != 'Field Sync' or (len nd.children) != 1 [ err 'eval-quoted' ] else [ .ok ]
signature
action-bounds = fn [root Node, vp Viewport, scroll_y i64, target_action any] w/Rect

Returns the laid-out canvas w/Rect of the first interactive widget matching target_action (zero pixel allocation).

signature
render-mobile-frame = fn [root Node, vp Viewport, dark_mode bool, show_guides bool, scroll_y i64, mut ui_st w/UiState] PreviewResult

Renders a complete mobile viewport frame (bezel, status bar, Dynamic Island, safe-area guides, scrollable view tree, docked tab-bar, modal sheet, and gesture pill) and hit-tests interactions.

signature
render-preview-png = fn [root Node, vp Viewport, dark_mode bool, factor i64] bytes

Renders root offscreen for vp (zero .ui capability required) and encodes RFC 2083 PNG bytes via image/png. Optional /scale factor downsamples the rasterized mobile frame before PNG compression.

run-preview fn caps: .env .ui .clocks
signature
run-preview = fn [title str, init_state any, view_fn fn[any->Node], update_fn fn[any,any->any]] any

Opens an interactive 60fps desktop mobile-simulator window ([1] iPhone [2] Pixel [3] iPad [4] Handheld, [T] Theme, [G] Safe-Area, live state summary) and returns final state on close (exits cleanly after 2 frames under VEKO_HEADLESS=1).

signature
node-to-json = fn [nd Node] str

Serializes a Node tree into the unified JSON AST representation with .secret firewall guarantees.

signature
mobile-wire-envelope = fn [root Node, meta map] str

Wraps a serialized Node AST and meta map in the versioned veko.ui.v1 wire envelope.

signature
parse-wire-event = fn [raw str] map

Lightweight zero-dependency parser for flat JSON event payloads emitted by native VekoViewHost shells.