ui/native
lib/ui/native.vklib/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 { x i64 = ..., y i64 = ..., w i64 = ..., h i64 = ... }
Size = struct { w i64 = ..., h i64 = ... }
DialogFilter = struct { name str, pattern str }
NativeEvent = struct { kind enum, win_id str, widget_id str, text str = ..., value str = ..., value_n i64 = ..., flag bool = ..., w i64 = ..., h i64 = ... }
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 { 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 { 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 [] enum
is-headless? = fn [] bool
init-app = fn [] NativeApp
Initializes the native desktop runtime (VEKO_HEADLESS=1 selects the deterministic simulator).
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.
close-window = fn [mut app NativeApp, win_id str]
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.
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).
destroy-widget = fn [mut app NativeApp, win_id str, wid str]
Destroys a mounted widget handle and removes it from win_id.
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.
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.
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.
begin-layout = fn [mut app NativeApp, win_id str, widget_count i64]
set-widget-rect = fn [mut app NativeApp, win_id str, wid str, r Rect]
end-layout = fn [mut app NativeApp, win_id str]
focus-widget = fn [app NativeApp, win_id str, wid str]
native-handle = fn [app NativeApp, win_id str, wid str] i64
read-widget-text = fn [app NativeApp, win_id str, wid str] str
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.
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.
wake-tid = fn [app NativeApp, tid i64]
Safe cross-thread UI wakeup helper callable from worker threads with ui_tid (PostThreadMessageW).
wake = fn [mut app NativeApp]
poll-events = fn [mut app NativeApp] block[NativeEvent]
Non-blocking pump draining OS messages (PeekMessageW on Win, NSEvent on macOS) and queued C callbacks.
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.
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.
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).
pick-folder-dialog = fn [mut app NativeApp, win_id str, title str] str
Opens a native folder picker dialog (path or '' on cancel).
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.
sim-push-dialog-result = fn [mut app NativeApp, val str]
sim-click = fn [mut app NativeApp, win_id str, wid str]
sim-input = fn [mut app NativeApp, win_id str, wid str, text str]
sim-secret-input = fn [mut app NativeApp, win_id str, wid str, simulated_keystrokes str]
sim-toggle = fn [mut app NativeApp, win_id str, wid str, flag bool]
sim-select = fn [mut app NativeApp, win_id str, wid str, value str]
sim-slider = fn [mut app NativeApp, win_id str, wid str, value_n i64]
sim-tree-select = fn [mut app NativeApp, win_id str, wid str, node_id str]
sim-table-select = fn [mut app NativeApp, win_id str, wid str, row_idx i64]
sim-tab = fn [mut app NativeApp, win_id str, wid str, tab_id str]
sim-close = fn [mut app NativeApp, win_id str]
grant-webview-net = fn [mut app NativeApp]
system-tray = fn [mut app NativeApp, win_id str, tooltip str, icon_canvas any, menu_items block, click_action any] bool
update-tray = fn [mut app NativeApp, tooltip str, icon_canvas any, menu_items block] bool
remove-tray = fn [mut app NativeApp]
notify = fn [mut app NativeApp, win_id str, title str, body str, tone enum] bool
register-shortcut = fn [mut app NativeApp, win_id str, chord str] any
unregister-shortcut = fn [mut app NativeApp, win_id str, chord str] bool
webview-eval-js = fn [mut app NativeApp, win_id str, wid str, js str] any
webview-post-message = fn [mut app NativeApp, win_id str, wid str, msg str] any
webview-set-html = fn [mut app NativeApp, win_id str, wid str, html str] any
webview-handle = fn [app NativeApp, win_id str, wid str] any
sim-tray-click = fn [mut app NativeApp, win_id str]
sim-shortcut = fn [mut app NativeApp, win_id str, chord str]
sim-webview-ipc = fn [mut app NativeApp, win_id str, wid str, payload str]
sim-notifications = fn [app NativeApp] block