ui/view
lib/ui/view.vklib/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 { 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 { id str, label str, badge str = ... }
Navigation item descriptor for tab-bar.
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.
PreviewResult = struct { canvas cv/Canvas, triggered_actions block, scroll_max i64 }
Result of rendering and hit-testing a single mobile viewport frame.
iphone-viewport = fn [] Viewport
Returns the iPhone 16 Pro viewport preset (393 x 852, Dynamic Island enabled).
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 ]
pixel-viewport = fn [] Viewport
Returns the Google Pixel 9 viewport preset (412 x 915).
ipad-viewport = fn [] Viewport
Returns the iPad Mini tablet viewport preset (744 x 1024).
compact-viewport = fn [] Viewport
Returns the rugged Field Handheld compact viewport preset (360 x 640).
viewport-by-name = fn [name str] Viewport
Resolves a mobile Viewport preset by case-insensitive device alias ('iphone', 'pixel', 'ipad', 'compact').
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).
vstack = fn [props map, children block[Node]] Node
Vertical flex stack (props: gap default 12, pad default 0).
hstack = fn [props map, children block[Node]] Node
Horizontal row stack (props: gap default 10, pad default 0).
scroll = fn [props map, children block[Node]] Node
Scrollable vertical container (props: gap default 12, pad default 0).
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).
section = fn [title str, children block[Node]] Node
Labeled group section with muted header title and stacked children.
row = fn [props map, children block[Node]] Node
Horizontal list/detail row (props: on_tap, gap default 10, pad default 10).
grid = fn [cols i64, gap i64, children block[Node]] Node
Multi-column uniform grid layout with cols columns and gap spacing.
sheet = fn [is_open bool, title str, close_action any, children block[Node]] Node
Modal bottom sheet overlay (is_open, title, close_action, children).
tab-bar = fn [active_id str, select_prefix str, tabs block[TabItem]] Node
Docked bottom navigation tab bar (active_id, select_prefix, tabs).
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).
secret-field-badge = fn [label str] Node
Masked .secret hygiene indicator pill (<secret ••••••••>) that never accepts or exposes raw secret text.
banner = fn [tone enum, message str, visible bool] Node
Semantic alert banner (tone in .accent | .success | .warning | .danger, skipped during layout when visible == false).
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.
button = fn [label str, action any] Node
Primary interactive button triggering action when tapped/clicked.
button-styled = fn [label str, props map, action any] Node
Styled interactive button (props: style in .primary | .secondary | .danger | .ghost, disabled bool).
checkbox = fn [label str, checked bool, action any] Node
Interactive checkbox row triggering action when tapped/clicked.
toggle-switch = fn [label str, is_on bool, action any] Node
Interactive pill toggle switch row triggering action when tapped/clicked.
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.
progress = fn [pct i64, label str, tone enum] Node
Labeled horizontal progress bar (pct clamped 0..100) with semantic tone.
sparkline = fn [title str, values block, tone enum] Node
Labeled mini trend sparkline card over numeric values.
for-each = fn [items block, item_fn fn[any->Node]] block[Node]
Maps items through item_fn into a typed block[Node].
list-view = fn [items block, item_fn fn[any->Node]] Node
Builds a vertical .list_view container mapping items through item_fn.
window = fn [title str, props map, children block[Node]] Node
Root native application window (Desktop) or top-level screen frame.
toolbar = fn [props map, children block[Node]] Node
Window chrome action toolbar (props: gap, pad, compact).
status-bar = fn [segments block] Node
Window bottom status bar displaying formatted string segments.
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 [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 [id str, label str, children block[Node]] Node
Individual page inside a tabs container.
form = fn [props map, children block[Node]] Node
Two-column aligned form layout (props: label_width, gap, pad).
group-box = fn [title str, props map, children block[Node]] Node
Titled native frame / preferences group container.
label = fn [content str, props map] Node
Single- or multi-line semantic text label (props: tone, align, label_for).
text-area = fn [id str, placeholder str, value str, action any] Node
Multi-line editable text area (id, placeholder, value, change_or_submit_action).
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.
radio-group = fn [id str, options block, selected str, action any] Node
Mutually exclusive native radio button group (options block of strings, selected).
select = fn [id str, options block, selected str, action any] Node
Native dropdown / combo-box selector (options block of strings, selected).
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).
list-box = fn [id str, items block, selected str, action any] Node
Scrollable single-selection native list box.
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).
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).
canvas-slot = fn [id str, props map] Node
Native surface hosting a custom ui/canvas framebuffer (props: width, height, canvas).
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.
native-slot = fn [id str, handle i64, props map] Node
Escape-hatch slot embedding an externally created native OS widget handle (HWND/NSView/GtkWidget).
eval-quoted = fn [qblock block, state map] Node
Evaluates a homoiconic quote [...] view block against state (map) with zero eval and zero host capabilities.
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 ]
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).
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.
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 [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).
node-to-json = fn [nd Node] str
Serializes a Node tree into the unified JSON AST representation with .secret firewall guarantees.
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.
parse-wire-event = fn [raw str] map
Lightweight zero-dependency parser for flat JSON event payloads emitted by native VekoViewHost shells.