veko-lang.org
Download Free EPUB 3.0

Part II · Standard Library, PQC, Networking, Async, Durable State & Desktop UI

Chapter 11

Terminal UI, 33-Widget Studio UI, PNG Graphics & Foreign Interop

TrueColor TUI dashboards, Light-Mode RGBA32 Studio widgets (--gui), lossless PNG, and veko bindgen .ffi interop

Veko ships a complete, capability-isolated stack for terminal dashboards (lib/tui.vk), zero-dependency 2D software graphics, RFC 2083 PNG encoding/decoding (lib/image/png.vk), mixed-case proportional typography (lib/ui/font.vk), 1D/2D flex & grid layout (lib/ui/layout.vk), 33 immediate-mode desktop & studio widgets (lib/ui/widgets.vk), native window surfaces across Win32, zero-libc Linux Wayland (wl_shm) & X11, macOS arm64 (AppKit / CoreGraphics), and Wasm <canvas> with keyboard focus traversal, OS clipboard & Hi-DPI scaling (lib/ui.vk, lib/ui/wayland.vk, lib/ui/x11.vk), and opt-in foreign library interop (lib/ffi.vk honoring VEKO_LIB + veko bindgen).


1. Capability Model & Zero-Bloat Guarantees

TERMINAL, DESKTOP UI & FFI

Capability-Isolated Terminal UI, RGBA32 Canvas, .ui Window & Opt-In .ffi

Four clean layers keeping CLI binaries tiny while enabling rich TrueColor TUIs, 60 FPS 2D GUIs, and C/Rust interop.

ZERO-CAP PURE-VEKO RENDERING Works on VM, Wasm & Native CAPABILITY-GATED OS & FOREIGN BOUNDARIES .ui and opt-in .ffi mut cv present-canvas RGBA32 pixels Shared telemetry Terminal UIDouble-Buffered TUIlib/tui.vk (TrueColor ANSI) 2D RasterizerRGBA32 Software Canvaslib/ui/canvas.vk (Zero-Copy) Widget ToolkitImmediate-Mode Widgetslib/ui/widgets.vk OS Window (.ui).ui Window Surfacelib/ui.vk + --gui PE switch Foreign Interop (.ffi)Opt-In .ffi C-ABI Bridgelib/ffi.vk (Zero-W^X AOT)
Component & ModuleArchitectural Role
Double-Buffered TUI
lib/tui.vk
Renders flicker-free terminal dashboards by emitting ANSI escapes only for changed cells.
RGBA32 Software Canvas
lib/ui/canvas.vk
Draws alpha-blended shapes, gradients, lines, and crisp 5x7 ASCII glyphs into mut cv.pixels.
Immediate-Mode Widgets
lib/ui/widgets.vk
Composes responsive layouts, themes, hit-tested buttons, lists, and charts over Canvas.
.ui Window Surface
lib/ui.vk + native_pal5.vk
Blits RGBA32 canvases to native Win32 GDI windows or validated headless surfaces.
Opt-In .ffi C-ABI Bridge
lib/ffi.vk + native_pal5.vk
Loads C, C++, Rust, Zig, or Go shared libraries (.dll/.so/.dylib) via static trampolines.

Every layer in Veko's UI and FFI stack follows least-privilege capability isolation:

LayerModulesRequired CapabilityNative Binary FootprintWasm 3.0 (--wasm)
Terminal UI (TUI)tuiNonePure ANSI/VT100; zero GUI DLLsSupported
2D Canvas, Font, Layout, Wayland/X11 Framing, PNG & 33 Studio Widgetsui/canvas, ui/font, ui/layout, ui/wayland, ui/x11, ui/widgets, image/pngNone (allow-caps = [])Pure Veko RGBA32 rasterizer, Wayland & X11 wire codecs + zlib PNG; zero GUI DLLsSupported
Native Window, Keyboard/Mouse Events, OS Clipboard & Hi-DPI Surfaceui (ui/open, ui/present, ui/poll-events, ui/clipboard-get, ui/clipboard-get/secret, ui/clipboard-set, ui/dpi-scale, ui/close).ui (allow-caps = [.ui])Win32 Per-Monitor V2 Hi-DPI (--gui sets PE Subsystem = 2); Linux zero-libc Wayland (wl_shm + memfd_create + SCM_RIGHTS) cascading to X11 over AF_UNIX; macOS arm64 AppKit/CoreGraphics Retina NSWindow (linked only when .ui is active); headless fallback via VEKO_HEADLESS=1Supported (shared linear-memory <canvas> + event ring, 0 leaked slabs)
Opt-In Foreign Librariesffi (ffi/open, ffi/sym, ffi/call, ffi/close) + veko bindgen.ffi (denied by default; requires --allow-ffi, -C ffi, or allow-caps = [.ffi])Resolves search directories from VEKO_LIB; Win64 kernel32.dll; Linux x86_64 opt-in dynamic ELF64 (libc.so.6) only when .ffi is active; macOS arm64 libSystemStrictly forbidden (zero-trust sandbox)

2. Terminal UI (lib/tui.vk)

lib/tui.vk provides a double-buffered ANSI/VT100 screen grid with 24-bit TrueColor RGB cells, style bitmasks, boxes, progress bars, sparklines, tables, tui/parse-key input decoding, and a diffing frame encoder (tui/render-diff) that only transmits modified cells:

VEKO
use [tui]

mut scr = tui/new-screen 60 12
tui/clear mut scr tui/color-white tui/color-surface
tui/draw-box mut scr 0 0 60 12 'Node Monitor' .rounded tui/color-cyan tui/color-surface
tui/draw-progress mut scr 2 3 30 75 tui/color-emerald tui/color-slate tui/color-surface
frame_ansi = tui/render-diff mut scr

3. 2D Canvas, Typography, Flex/Grid Layout & Lossless PNG (ui/*, image/png)

  • ui/canvas: Porter-Duff SRC_OVER RGBA32 rasterizer with set-clip / reset-clip scissor rectangles, fill-rounded-rect, stroke-rounded-rect, draw-line-smooth, fill-circle, stroke-circle, encode-bmp, and encode-ppm.
  • ui/font: Crisp mixed-case proportional & monospace typography (A-Z, a-z with true ascenders/descenders, 0-9, symbols, and bullet masks) across body (size = 1), heading (size = 2), and display (size = 3) scales, plus draw-truncated ellipsis clipping.
  • ui/layout: 1D/2D constraint solver (px, flex, flex-row, flex-col, grid, split-h, split-v, ClipStack) usable standalone or via ui/widgets.
  • image/png: Pure-Veko RFC 2083 RGBA32 PNG encoder and decoder (png/encode, png/encode-rgba, png/decode, png/decode-rgba) using adaptive per-scanline filtering and compress/deflate.
  • ui/x11: Pure-Veko X11 Release 11 wire-protocol codec (build-setup, parse-setup, plan-bands, build-put-image-band, decode-event) backing Veko's zero-libc Linux desktop window surface (AF_UNIX /tmp/.X11-unix/X<n>, .Xauthority MIT-MAGIC-COOKIE-1, and chunked scanline-band PutImage <= 128 KB).

4. The 33-Widget Immediate-Mode Desktop & Studio Toolkit (lib/ui/widgets.vk)

lib/ui/widgets.vk renders studio-grade Light-Mode and Dark-Mode desktop interfaces directly into a cv/Canvas with zero GC pauses, zero host capabilities (allow-caps = []), and zero per-frame pixel buffer clones (demos/widget_gallery):

Veko Studio Widget Gallery — Form Inputs, Masked .secret Fields, Dropdowns, Chips & Code Editor
Veko Studio Widget Gallery — Form Inputs, Masked .secret Fields, Dropdowns, Chips & Code Editor
Veko Studio Widget Gallery — Text Selection Highlight, .secret-Firewalled Clipboard & Per-Monitor V2 Hi-DPI Scaling
Veko Studio Widget Gallery — Text Selection Highlight, .secret-Firewalled Clipboard & Per-Monitor V2 Hi-DPI Scaling

Keyboard Focus Ring, OS Clipboard, .secret Hygiene & Hi-DPI Scaling

  • Full Keyboard Navigation & Focus Ring (begin-frame / end-frame): Every interactive widget registers in a deterministic per-frame focus ring. Tab and Shift+Tab cycle focus_id with crisp theme accent outlines, while Space/Enter activate buttons/checkboxes/toggles, arrow keys adjust sliders/radios/dropdowns/tabs/lists/trees, and Escape dismisses modals and palettes. lib/ui.vk exposes EV-KEY-DOWN, EV-KEY-UP, MOD-SHIFT/CTRL/ALT/SUPER, and KEY-F1..F12 / navigation constants across Win32, Wayland, X11, AppKit, and Wasm <canvas>.
  • OS Clipboard & .secret Outbound Firewall: text-input, text-area, and code-editor support keyboard selection (Shift+Arrows/Home/End) and system clipboard shortcuts (Ctrl+A, Ctrl+C, Ctrl+X, Ctrl+V). ui/clipboard-set rejects .secret values statically and at runtime, while ui/clipboard-get/secret reads pasted secrets directly into zeroized-on-drop .secret memory.
  • Per-Monitor V2 Hi-DPI & Wasm <canvas>: ui/dpi-scale queries the active window's percentage scale factor (100, 125, 150, 200) across Win32 Per-Monitor V2 (GetDpiForWindow), Linux Wayland/X11, macOS Retina, and browser devicePixelRatio.

Studio IDE Widgets (code-editor, command-palette, file-picker, split-pane-state)

VEKO
use [fs, cv = ui/canvas, w = ui/widgets]

mut st  = w/new-state
mut ed  = w/new-editor 'pub greet = fn [who str] str [\n    `Hello, {who}!`\n]'
mut pal = w/new-palette
th      = w/light-theme
mut c   = cv/new-canvas 800 480

w/begin-frame mut st
// Multi-line Veko-highlighted code editor with line numbers, selection, clipboard & 64-step Ctrl+Z / Ctrl+Y undo/redo
_ = w/code-editor mut c mut st 'main-editor' (w/Rect { x = 16, y = 16, w = 768, h = 360 }) mut ed th '' ''

// Fuzzy command palette overlay (`Ctrl+P` / `Ctrl+K`)
cmd_id = w/command-palette mut c mut st 'studio-pal' (w/Rect { x = 0, y = 0, w = 800, h = 480 }) mut pal [
    w/CommandItem { id = 'run',   label = 'Run Active Buffer', shortcut = 'F5' }
    w/CommandItem { id = 'check', label = 'Strict Type Check', shortcut = 'Ctrl+Shift+B' }
] th
w/end-frame mut st

To browse workspace files without adding .fs capabilities to ui/widgets, pair fs/list-entries dir (in lib/fs.vk) with the pure w/file-picker modal (w/FilePickerState, w/FileEntry), and resize multi-pane layouts interactively with w/split-pane-state.

Complete Widget Catalog

  1. Surfaces & KPI Cards: panel, panel-body, label, heading, button (with /primary), icon-button, badge, stat-card.
  2. Forms & .secret Inputs: text-input (with /secret bullet mask), secret-input (operates directly on mut secret bytes without str conversion), text-area (with line-number gutter), checkbox, toggle-switch, radio-group, slider, progress-bar (with /label), dropdown, chip-group.
  3. Navigation, Tables & Trees: tabs, begin-scroll / end-scroll (with mouse wheel EV-WHEEL & scrollbar), list-view, select-list, data-table (zebra striping & auto-pill status cells), tree-view (disclosure triangles & badges), split-pane, split-pane-state (interactive mouse drag).
  4. Studio IDE & Overlays: code-editor (EditorState, Veko syntax highlighting, Ctrl+Z/Ctrl+Y undo/redo, auto-indent), command-palette (PaletteState, fuzzy search + shortcuts), file-picker (FilePickerState, breadcrumbs + extension filter), menu-bar, context-menu, modal, toast, tooltip.
  5. Charts & Telemetry: sparkline, bar-chart, line-chart (multi-series anti-aliased curves + legend).
Veko Studio Widget Gallery — Hierarchical Tree View, Multi-Column Data Table & Scrollable Inspector
Veko Studio Widget Gallery — Hierarchical Tree View, Multi-Column Data Table & Scrollable Inspector
Veko Studio Widget Gallery — KPI Stat Cards, Bar Chart, Multi-Series Line Chart & Sparklines
Veko Studio Widget Gallery — KPI Stat Cards, Bar Chart, Multi-Series Line Chart & Sparklines
Veko Studio Widget Gallery — Nested Split Panes, Context Menu, Tooltip, Modal Dialog & Toast
Veko Studio Widget Gallery — Nested Split Panes, Context Menu, Tooltip, Modal Dialog & Toast
Veko Canvas Workbench — Light-Mode Cluster Topology, Sketch Pad, Durable Sprint KV & Profiler
Veko Canvas Workbench — Light-Mode Cluster Topology, Sketch Pad, Durable Sprint KV & Profiler

Running the Desktop Showcases

POWERSHELL
# Run deterministic cross-runtime verification or export Light-Mode PNGs
veko demos/widget_gallery
veko demos/widget_gallery -- --export-dir docs/screenshots

# Launch live interactive Win32 desktop windows (EV-KEY, EV-TEXT, EV-WHEEL, EV-RESIZE, BTN-RIGHT)
veko demos/widget_gallery -- --live
veko demos/canvas_workbench -- --live

5. Opt-In Foreign Library Boundary (lib/ffi.vk) & veko bindgen

Veko's .ffi capability calls native shared libraries (.dll, .so, .dylib) via zero-W^X static AOT C-ABI trampolines while keeping .ffi denied by default, permanently blocked on --wasm, and walled off from .secret data.

Generating Wrapper Modules Automatically (veko bindgen)

Instead of hand-writing symbol lookups and struct offsets, point veko bindgen at a C header file to generate #define constants, Veko struct definitions, little-endian pack-* helpers, and typed ffi/call-c wrappers:

POWERSHELL
veko bindgen path/to/library_api_header -l sqlite3 -o src/sqlite_ffi.vk
veko check --strict-types -C ffi src/sqlite_ffi.vk

Manual Foreign Calls & C-Struct Packing

VEKO
use [ffi]

mut buf = bytes/with-cap 32
ffi/pack-i32 mut buf -42
ffi/pack-u32 mut buf 0x12345678
ffi/pad-align mut buf 8
ffi/pack-i64 mut buf 1735689600000
ffi/pack-cstr mut buf 'veko-ffi'

is_win = (os/getenv/or 'OS' ['']) == 'Windows_NT'
lib = ffi/open-lib (if is_win [ 'kernel32.dll' ] else [ 'libc.so.6' ])
pid_sym = ffi/resolve lib (if is_win [ 'GetCurrentProcessId' ] else [ 'getpid' ])
pid = ffi/call-c pid_sym []
_ = ffi/close-lib lib

Next Steps