Native Surfaces
Native surfaces are the app-owned regions that the Native SDK composes inside a platform window. A surface can be a GPU-rendered canvas, native chrome, a native utility panel, or an embedded WebView. The key model is that a window is a declared tree of surfaces — the default app is one gpu_surface canvas filling the window, and everything else composes around it.
Surface Types
| Surface | Use it for | Backed by |
|---|---|---|
| GPU surface | The canvas your native UI renders into — plus custom drawing regions for editors, timelines, dashboards, and games | Metal-backed on macOS; retained Direct2D/DirectWrite on Windows; CPU reference-rendered on Linux and as the Windows fallback |
| Native chrome | Toolbars, titlebar accessories, sidebars, status bars | Native platform views declared through ShellView or runtime.createView(...) |
| Native controls | Buttons, search fields, toggles, segmented controls, labels, progress | Platform controls with command routing and accessibility metadata |
| OS capability surfaces | Dialogs, tray, clipboard, notifications, credentials, file drops | Guarded PlatformServices, runtime methods, and built-in bridge commands |
| WebView | Embedded web content: web frontends, documents, previews | ViewKind.webview, WebViewSource, and the selected web engine |
The default shape: one canvas
The generated app declares one window with one GPU surface, and the UiApp loop renders the whole UI into it:
Everything below this section is composition around that canvas: platform chrome, split panes, and (when needed) web content.
Window Shape
Use App.scene_fn (or UiApp's scene option) when a window should start with native structure, such as chrome around a WebView workspace:
This creates native chrome and controls in the platform host while the main WebView owns the workspace content.
Canvas + WebView In One Window
A TypeScript canvas app exports webPanes(model): readonly WebViewPane[] to coordinate a manifest-declared child WebView with its canvas layout:
Reserve the region in app.native with <panel grow="1" label="preview-pane"/>. The label names an existing WebView in the manifest; the anchor follows the widget's measured bounds. With anchor: null, the explicit frame applies. Changing the URL navigates, and changing reloadToken reloads. The first four descriptors apply in order. Geometry is finite f32 canvas points with nonnegative dimensions; tokens are nonnegative safe integers. The adapter copies labels (64 bytes), anchors (256 bytes), and URLs (the platform URL budget) into native storage. Navigation retains the manifest's origin policy. See the TypeScript Canvas Preview example.
Zig cores and runtime extensions use the corresponding UiApp.Options.web_panes seam:
A canvas-first UiApp can host a live webview next to its native-rendered widgets — the "native, web, or both per window" composition. The scene declares the webview shell view (parent it to the canvas view so frames share the canvas coordinate space), and UiApp.Options.web_panes keeps it snapped to a canvas widget's layout frame and drives navigation from the model:
Panes re-apply after every rebuild and presented frame, reconciling against the runtime's actual webview state, so shell relayouts (window restores, resizes) cannot leave the webview detached from its anchor. Pane URLs are subject to security.navigation.allowed_origins. A scene whose only webviews are children like this never grows an implicit main webview — the window stays canvas-first. The seam is engine-agnostic (it rides the same PlatformServices webview surface both the system and Chromium hosts implement), though gpu_surface canvases currently require the system engine on macOS. examples/canvas-preview demonstrates this, with a smoke test at zig build test-canvas-preview-smoke.
Imperative View API
For dynamic surfaces, create and update views at runtime:
Trusted WebView code can use the guarded bridge helpers when js_window_api or an explicit builtin_bridge policy allows view commands:
Command Routing
Surfaces should share command IDs instead of each UI entry point owning separate behavior. A native menu item, shortcut, toolbar button, tray item, native button, and WebView bridge call can all dispatch app.refresh into the same Event.command handler.
CommandEvent.source records whether the action came from .menu, .shortcut, .toolbar, .tray, .native_view, .bridge, or .runtime. ViewInfo.id is a stable runtime handle for the view lifetime, while label remains the selector used by runtime and bridge APIs.
Compatibility
Existing App.source, runtime.createWebView(...), and window.zero.webviews.* apps remain valid. The generic view model adds a wider vocabulary:
ViewKind.webviewwraps WebView-backed surfaces.runtime.createView(.{ .kind = .webview, ... })routes through the WebView backend.runtime.listViews(...)returns WebView-backed and native views through one list.- Automation snapshots include native views and WebView-backed views.
Platform Support
macOS, Linux, and Windows system hosts support native views and controls today. The macOS host presents gpu_surface through Metal, Windows presents retained representable packets through Direct2D/DirectWrite with an exact software fallback, and Linux presents through the software reference renderer. See examples/gpu-surface for a minimal native controls plus WebView plus GPU surface composition. Chromium hosts and mobile hosts expose the same public vocabulary where useful, but unsupported operations reject explicitly instead of silently falling back.
Use support checks before showing optional native affordances:
gpu_surface views report GPU presentation state through ViewInfo and GpuSurfaceFrameEvent, including the selected backend, pixel format, present mode, alpha mode, color space, vsync flag, status, frame size, frame index, timestamp, nonblank sample status, input latency budget, first-frame latency budget, retained canvas frame counters, widget revision, widget node count, and current cursor intent.
See Platform Support for the current host matrix.