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

ui

lib/ui.vk

lib/ui.vk Curated .ui-gated native window surface, clipboard, and Hi-DPI wrapper over the Veko PAL window primitives (ui/open, ui/poll-events, ui/present, ui/close, ui/clipboard-get, ui/clipboard-set, ui/dpi-scale) + ui/canvas framebuffer presentation. - Windows x64: native Win32 window (StretchDIBits + Per-Monitor V2 Hi-DPI + Win32 clipboard), or headless under VEKO_HEADLESS=1 - Linux x64/arm64: zero-libc X11 wire-protocol window over AF_UNIX (chunked PutImage + .Xauthority), or headless - macOS / VM / Wasm 3.0: deterministic surface (with shared-memory <canvas> bridge in browser Wasm) and .secret firewall enforcement

Interactive Wasm 3.0 Framebuffer Preview (<canvas>)Mounting Wasm 3.0 surface...
signature
EV-CLOSE = fn [] i64

Window event kind constants matching the 5-element PAL event tuples [kind x y key btn].

signature
EV-KEY = fn [] i64
signature
EV-MOUSE-DOWN = fn [] i64
signature
EV-MOUSE-UP = fn [] i64
signature
EV-MOUSE-MOVE = fn [] i64
signature
EV-RESIZE = fn [] i64
signature
EV-TEXT = fn [] i64
signature
EV-WHEEL = fn [] i64
signature
EV-KEY-UP = fn [] i64
signature
MOD-SHIFT = fn [] i64

Keyboard modifier bitmask constants (UiEvent.btn on EV-KEY / EV-KEY-UP or UiState.key_mods).

signature
MOD-CTRL = fn [] i64
signature
MOD-ALT = fn [] i64
signature
KEY-BACKSPACE = fn [] i64

Standard cross-platform virtual key constants (UiEvent.key on EV-KEY / EV-KEY-UP).

signature
KEY-TAB = fn [] i64
signature
KEY-ENTER = fn [] i64
signature
KEY-SHIFT = fn [] i64
signature
KEY-CTRL = fn [] i64
signature
KEY-ALT = fn [] i64
signature
KEY-ESC = fn [] i64
signature
KEY-SPACE = fn [] i64
signature
KEY-PAGE-UP = fn [] i64
signature
KEY-PAGE-DOWN = fn [] i64
signature
KEY-END = fn [] i64
signature
KEY-HOME = fn [] i64
signature
KEY-LEFT = fn [] i64
signature
KEY-UP = fn [] i64
signature
KEY-RIGHT = fn [] i64
signature
KEY-DOWN = fn [] i64
signature
KEY-DELETE = fn [] i64
signature
BTN-LEFT = fn [] i64

Mouse button constants carried in UiEvent.btn on EV-MOUSE-DOWN / EV-MOUSE-UP.

signature
BTN-RIGHT = fn [] i64
UiEvent struct
signature
UiEvent = struct { kind i64, x i64, y i64, key i64, btn i64 }

Structured window input event decoded from poll-events.

Window struct
signature
Window = struct { handle i64, width i64, height i64, title str }

Handle to an open native or offscreen window surface.

open-window fn caps: .ui
signature
open-window = fn [title str, w i64, h i64] Window

Opens a window surface titled title with dimensions w x h.

Executable Example
veko
use [ui, cv = ui/canvas]
win = ui/open-window 'Veko Window' 64 32
mut c = cv/new-canvas 64 32
cv/clear mut c (cv/color-bg-dark)
_ = ui/present-canvas win c
evs = ui/poll win
_ = ui/close-window win
if (len evs) < 0 [ err 'events' ] else [ .ok ]
poll fn caps: .ui
signature
poll = fn [win Window] block[UiEvent]

Polls all pending OS input events for win without blocking.

present-rgba fn caps: .ui
signature
present-rgba = fn [win Window, rgba bytes, w i64, h i64]

Presents a raw RGBA32 byte buffer (w * h * 4 bytes) to win.

signature
present-canvas = fn [win Window, c cv/Canvas]

Presents a ui/canvas Canvas directly to win.

close-window fn caps: .ui
signature
close-window = fn [win Window]

Closes win and releases OS/offscreen surface resources.

window-dpi-scale fn caps: .ui
signature
window-dpi-scale = fn [win Window] i64

Queries the active Hi-DPI scaling percentage for win (100 = 96 DPI 1x, 150 = 1.5x, 200 = 2x Retina/4K).

clipboard-text fn caps: .ui
signature
clipboard-text = fn [] str

Reads UTF-8 plain text from the OS/session clipboard.

Executable Example
veko
use [ui]
_ = ui/set-clipboard 'veko-clip-ok'
got = ui/clipboard-text
if got != 'veko-clip-ok' [ err 'clipboard mismatch' ] else [ .ok ]
clipboard-secret fn .secret caps: .ui
signature
clipboard-secret = fn [] secret str

Reads clipboard contents directly into a .secret-tainted str for pasting tokens/passwords without exposing plain str copies.

set-clipboard fn caps: .ui
signature
set-clipboard = fn [text str]

Writes plain text to the OS/session clipboard (.secret values are statically and dynamically rejected).