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

ui/native

lib/ui/native.vk

lib/ui/native.vk Cross-platform retained-handle native OS widget foundation and deterministic CI simulator. - Windows 10/11: live user32.dll, gdi32.dll, comctl32.dll, uxtheme.dll, dwmapi.dll, ole32.dll - Deterministic CI mode (VEKO_HEADLESS=1 or headless environments): exact in-memory control tree - Zero top-level mut globals: all OS/simulator handles live inside the explicit NativeApp value. - .secret hygiene: password-field contents never touch state and read-secret returns secret str.

Rect struct
signature
Rect = struct { x i64 = ..., y i64 = ..., w i64 = ..., h i64 = ... }
Size struct
signature
Size = struct { w i64 = ..., h i64 = ... }
signature
DialogFilter = struct { name str, pattern str }
signature
NativeEvent = struct { kind enum, win_id str, widget_id str, text str = ..., value str = ..., value_n i64 = ..., flag bool = ..., w i64 = ..., h i64 = ... }
signature
WidgetHandle = struct { id str, kind enum, os_hwnd i64 = ..., ctrl_id i64 = ..., sub_hwnds block = ..., text str = ..., value_s str = ..., value_n i64 = ..., flag bool = ..., items block = ..., props map = ..., rect Rect = ..., visible bool = ... }
NativeWin struct
signature
NativeWin = struct { id str, title str, hwnd i64 = ..., width i64 = ..., height i64 = ..., dpi_scale i64 = ..., menu_h i64 = ..., menu_actions map = ..., status_hwnd i64 = ..., status_id str = ..., defer_hdwp i64 = ..., font_h i64 = ..., head_font_h i64 = ..., dark_brush i64 = ..., widgets map = ..., ctrl_to_id map = ..., next_ctrl_id i64 = ..., open bool = ... }
NativeApp struct
signature
NativeApp = struct { headless bool = ..., platform enum = ..., ui_tid i64 = ..., hinst i64 = ..., proc_heap i64 = ..., wnd_cls_atom i64 = ..., com_ready bool = ..., libs map = ..., syms map = ..., windows map = ..., hwnd_to_win map = ..., sim_events block[NativeEvent] = ..., sim_dialogs block = ..., sim_pw_bufs map = ..., next_win_seq i64 = ..., alive bool = ..., shell sh/ShellState = ..., webviews map = ..., net_granted bool = ..., mac_rt ob/ObjcRuntime = ..., mac_shell shm/MacShellState = ..., mac_webviews map = ..., mac_win_views map = ..., mac_view_to_wid map = ..., mac_menu_actions map = ..., gtk_rt gk/GtkRuntime = ..., linux_shell dp/LinuxShellState = ..., linux_webviews map = ..., gtk_win_fixed map = ..., gtk_view_to_wid map = ... }
detect-platform fn caps: .env .fs
signature
detect-platform = fn [] enum
is-headless? fn caps: .env
signature
is-headless? = fn [] bool
init-app fn caps: .ffi
signature
init-app = fn [] NativeApp

Initializes the native desktop runtime (VEKO_HEADLESS=1 selects the deterministic simulator).

shutdown-app fn caps: .ffi
signature
shutdown-app = fn [mut app NativeApp]

Releases loaded OS handles cleanly on shutdown.

signature
open-window = fn [mut app NativeApp, id str, title str, width i64, height i64, props map] NativeWin

Opens a top-level native or simulated window and registers it on app.

signature
close-window = fn [mut app NativeApp, win_id str]
signature
create-widget = fn [mut app NativeApp, win_id str, wid str, kind enum, text str, value_s str, value_n i64, flag bool, items block, props map] WidgetHandle

Creates or updates a retained native control belonging to win_id.

signature
update-widget = fn [mut app NativeApp, win_id str, wid str, text str, value_s str, value_n i64, flag bool, items block, props map]

Updates an existing widget in place without recreating its OS handle (preserves focus/scroll).

signature
destroy-widget = fn [mut app NativeApp, win_id str, wid str]

Destroys a mounted widget handle and removes it from win_id.

signature
set-menu-bar = fn [mut app NativeApp, win_id str, menus block]

Installs or updates a native HMENU window menu bar from menu / menu_item / menu_divider descriptor trees.

signature
present-canvas-any = fn [app NativeApp, win_id str, wid str, c any]

Draws raw pixels (bytes) with dimensions cw x ch into a .canvas_slot native widget surface.

signature
present-canvas-slot = fn [app NativeApp, win_id str, wid str, c cv/Canvas]

Draws a ui/canvas framebuffer into a .canvas_slot native widget surface.

signature
measure-widget = fn [app NativeApp, win_id str, kind enum, text str, items block, props map] Size

Measures the DPI-scaled intrinsic Size for a widget kind + label text.

signature
begin-layout = fn [mut app NativeApp, win_id str, widget_count i64]
signature
set-widget-rect = fn [mut app NativeApp, win_id str, wid str, r Rect]
signature
end-layout = fn [mut app NativeApp, win_id str]
signature
focus-widget = fn [app NativeApp, win_id str, wid str]
signature
native-handle = fn [app NativeApp, win_id str, wid str] i64
signature
read-widget-text = fn [app NativeApp, win_id str, wid str] str
read-secret fn .secret caps: .ffi
signature
read-secret = fn [app NativeApp, win_id str, wid str] secret str

Extracts the value of a password-field directly into a .secret-protected secret str and immediately zeroes the temporary OS heap buffer. Returns '' tagged .secret if absent.

signature
wake-fn-addr = fn [app NativeApp] i64

Returns the native wakeup C function pointer (PostThreadMessageW on Windows, 0 when headless) so background spawn workers can wake thread 0 without capturing NativeApp.

signature
wake-tid = fn [app NativeApp, tid i64]

Safe cross-thread UI wakeup helper callable from worker threads with ui_tid (PostThreadMessageW).

wake fn
signature
wake = fn [mut app NativeApp]
poll-events fn caps: .ffi
signature
poll-events = fn [mut app NativeApp] block[NativeEvent]

Non-blocking pump draining OS messages (PeekMessageW on Win, NSEvent on macOS) and queued C callbacks.

signature
wait-events = fn [mut app NativeApp, timeout_ms i64] block[NativeEvent]

Waits up to timeout_ms for OS input/paint/wake events (MsgWaitForMultipleObjectsEx), then drains events.

signature
open-file-dialog = fn [mut app NativeApp, win_id str, title str, filters block] str

Opens a native file chooser dialog (path or '' on cancel). Consumes sim_dialogs in headless mode.

signature
save-file-dialog = fn [mut app NativeApp, win_id str, title str, filters block] str

Opens a native save-file dialog (path or '' on cancel).

signature
pick-folder-dialog = fn [mut app NativeApp, win_id str, title str] str

Opens a native folder picker dialog (path or '' on cancel).

signature
alert-dialog = fn [mut app NativeApp, win_id str, title str, body str, kind enum] enum

Displays a native modal alert dialog (kind in .info | .warning | .danger | .confirm), returning .ok | .yes | .no | .cancel.

signature
sim-push-dialog-result = fn [mut app NativeApp, val str]
signature
sim-click = fn [mut app NativeApp, win_id str, wid str]
signature
sim-input = fn [mut app NativeApp, win_id str, wid str, text str]
signature
sim-secret-input = fn [mut app NativeApp, win_id str, wid str, simulated_keystrokes str]
signature
sim-toggle = fn [mut app NativeApp, win_id str, wid str, flag bool]
signature
sim-select = fn [mut app NativeApp, win_id str, wid str, value str]
signature
sim-slider = fn [mut app NativeApp, win_id str, wid str, value_n i64]
signature
sim-tree-select = fn [mut app NativeApp, win_id str, wid str, node_id str]
signature
sim-table-select = fn [mut app NativeApp, win_id str, wid str, row_idx i64]
signature
sim-tab = fn [mut app NativeApp, win_id str, wid str, tab_id str]
signature
sim-menu = fn [mut app NativeApp, win_id str, item_label str]
signature
sim-close = fn [mut app NativeApp, win_id str]
signature
grant-webview-net = fn [mut app NativeApp]
signature
system-tray = fn [mut app NativeApp, win_id str, tooltip str, icon_canvas any, menu_items block, click_action any] bool
signature
update-tray = fn [mut app NativeApp, tooltip str, icon_canvas any, menu_items block] bool
signature
remove-tray = fn [mut app NativeApp]
signature
notify = fn [mut app NativeApp, win_id str, title str, body str, tone enum] bool
signature
register-shortcut = fn [mut app NativeApp, win_id str, chord str] any
signature
unregister-shortcut = fn [mut app NativeApp, win_id str, chord str] bool
signature
webview-eval-js = fn [mut app NativeApp, win_id str, wid str, js str] any
signature
webview-post-message = fn [mut app NativeApp, win_id str, wid str, msg str] any
signature
webview-navigate = fn [mut app NativeApp, win_id str, wid str, url str] any
signature
webview-set-html = fn [mut app NativeApp, win_id str, wid str, html str] any
signature
webview-handle = fn [app NativeApp, win_id str, wid str] any
signature
sim-tray-click = fn [mut app NativeApp, win_id str]
signature
sim-tray-menu = fn [mut app NativeApp, win_id str, item_label str]
signature
sim-shortcut = fn [mut app NativeApp, win_id str, chord str]
signature
sim-webview-ipc = fn [mut app NativeApp, win_id str, wid str, payload str]
signature
sim-notifications = fn [app NativeApp] block