Repository navigation
zgx 0.1.3
A patch: Rust and Luau code builds as before (every API change since 0.1.2 is an addition), unless it writes one of the three structs below field by field. Some defaults change, each below with what to check: zoom and find in page are on, keys and cursors behave as a browser's and AppKit's, and Windows presents and serves assistive technology differently.
Changed: new fields
New features add fields to these structs; each has a default, and one written field by field ends with ..Default::default() (or ..LocalTransform::IDENTITY). Every type and signature that was in 0.1.2 is unchanged: LocalTransform::matrix and PaintItem::matrix still give an Affine, and a tilt's map in perspective is beside them (LocalTransform::projective, PaintItem::projective, zgx::affine::Projective).
zgx::scene::LocalTransformgainsrotate_x,rotate_yandperspective(3D tilts, below).zgx::scene::PaintExtrasgainsprojective.zgx::trace::Frame, a frame of the devtools trace, gainsnotes(why the frame did what it did) andgpu_micros(the GPU's own time).
Changed: what to check in an existing app
A window zooms, and finds in its text, as a browser's page does (both below, under Added): Command (Control elsewhere) with plus, minus or 0 zooms a window, and Command-F (Control-F) opens a find bar. On Windows and Linux, Control with the wheel zooms too, and scroll views no longer scroll on it. A keymap or menu item binding those keys keeps them, and a node handling the wheel keeps a Control-wheel, so an app that has its own is unchanged.
- Opt out:
Ui::set_zoomable(false)(Luauui.window.zoomable:set(false)) andUi::set_find_in_page(false)(Rust; a Luau setting follows).
Enter activates a focused control as it goes down, and toggles no checkbox; Space follows no link. As a browser's controls and AppKit's take the keys: a button (and anything with on_click) runs on Enter's press, not its release, and on Space's release as before; a link takes Enter alone (Space scrolls); a checkbox, radio button or switch takes Space alone, so Enter goes on to the form's default action.
- Migrate: a checkbox meant to toggle on Enter handles the key itself (Rust
.on_eventonKeyDownofKey::Enter, Luauon_key), setting its state; a test pressing Enter and expecting the action on its release expects it on the press.
Buttons, checkboxes, menu items and sliders keep the arrow cursor, as Chrome's controls and AppKit's do; only links show the pointing hand, and text fields the I-beam. They showed the hand (sliders a resize arrow) when they stated no cursor.
- Migrate: a control meant to show the hand states it:
.cursor(Cursor::Pointer)(Luaucursor = "pointer").
Option-Tab and Command-Tab (Alt and Super elsewhere) no longer move focus: they are the system's, or a field's literal tab, and go on unhandled. Tab, Shift-Tab and Control with either still do, and Control-Tab now leaves a code editor that indents on Tab, as AppKit's text views do.
- Migrate: an app meant to move focus on Option-Tab binds it (a keymap entry, or
on_key) and moves focus itself.
A display: none node's children report a 0x0 box (Scene::bounds, on_resize, zgx inspect), as the node itself did and as CSS gives them: they reported their content's size at no width. They are no longer measured again each time their parent lays out.
- Migrate: code reading a hidden child's size to plan its layout reads it once the child shows (its
on_resizefires then).
Windows: a window builds its accessibility tree only once a client reads it. Windows' text services ask every window for its client area as it shows, with no assistive technology running, and zgx answered with its whole tree, built and kept in sync from the first frame (15–22% of a frame in lab and vlist). That request now gets AccessKit's placeholder root. UI Automation's request for the root (Narrator, NVDA) builds the tree at once, as before, and a client reading past the placeholder (its children, focus, a point, a pattern) builds it too, a focus event telling it to read again.
- Migrate: a test or tool reading a window through MSAA (
OBJID_CLIENT) waits for that focus event, or reads through UI Automation.ZGX_ACCESSIBILITY_LOG=1logs the requests and when the tree is built.
Windows: a window presents through a swap chain of its own, flip-sequential, its buffers the retained frame (as macOS's surfaces are) and each frame's changed regions passed to the compositor as dirty rectangles, rather than copying the whole frame into wgpu's buffer every frame. The app's GPU does 33–45% less in animate, vlist and lab, 12% less in heavy, the compositor less too, and the first text shows 346 → 280 ms after launch.
- Migrate: nothing to change. If a window draws wrongly on some GPU or driver,
ZGX_DXGI_PRESENT=0presents through wgpu's swap chain, as before, for this release (and please report it). A renderer presenting into a caller's visual always does.
Added
- Find in page: Command-F (Control-F elsewhere) opens a find bar at the window's top right, as a browser's: matches across all the window's text, fields and virtual lists' rows (those not mounted too), case and accents ignored, marked behind the text (theme tokens
find.match,find.current), Enter and Command-G (Control-G, F3) stepping, Escape closing with the match selected. A match in a field is scrolled to without moving its caret, until the bar closes on it. On macOS, Command-E finds the selection, and an app's Edit menu gains AppKit's Find submenu.Ui::find_text,find_next,find_status,find_results. An app whose keymap or menu binds Command-F, -G or -E keeps its own. - Zoom, as a browser's page zoom: Command (Control elsewhere) with plus or equals zooms a window in, minus out, 0 back to 100%, through Chrome's levels (25% to 500%). The window's content draws at the display's scale times the zoom, so layout reflows in a smaller or larger viewport and text and paths stay crisp; scroll views keep what was at their top. On Windows and Linux, Control with the wheel zooms too, a level a notch, when nothing under the pointer takes the wheel (a canvas's or a script's
on_wheelthat zooms keeps it); on macOS neither the wheel nor a pinch zooms, as in Safari. A window with a frame autosave name keeps its zoom and reopens at it.Ui::zoom,set_zoom,zoom_in,zoom_out,reset_zoom; Luau'sui.window.zoomandui.window.zoomable, states that follow the keys and set the zoom (ScriptHost::window_zoomfor a Rust host); on macOS an app's View menu gains Zoom In, Zoom Out and Actual Size. An app whose keymap or menu binds the keys keeps them; with Option, or Command and Control both, they are the app's (zterm's font size, ⌘⌥=). Native views follow it: terminals and web pages are placed in the zoom's points, a terminal's text drawn at its scale, a page at its own zoom times the window's (WKWebView's page zoom, WebView2's zoom factor). At 100% nothing changes: the content scale is the display's, exactly. radio(label, selected, value)andradio_group(label): radio buttons as a browser's and AppKit's, one Tab stop per group landing on the checked one, the arrows (all four) moving and choosing, wrapping at the ends. AnyRole::RadioGroup(Luaurole = "radiogroup",segmented) is such a group now; its arrows stopped at the ends and chose nothing.on_aux_clickin scripts: the middle button (or another beyond the primary and secondary) pressed and released on a node, as the DOM'sauxclick(a tab closed on a middle click, as browsers do). It is told{ button, x, y, local_x, local_y, shift, ctrl, alt, meta, cmd },buttonbeing"middle"or the platform's number; the innermost node with one takes it.- Typing in a list box (
Role::ListBox, Luaurole = "listbox") or a keyboard virtual list (keyboard_navigation, Luaukeyboard = true) jumps to the next option or row whose text starts with what was typed, as a browser's list box and AppKit's tables do: rows not mounted by theirrow_text, without mounting them. A list box's Page Up and Page Down move a page of its options.
Drawing
- Blend modes, as CSS's
mix-blend-mode: a view blends with what lies beneath it in any of the W3C's fifteen modes (multiply, screen, overlay, darken, lighten, color-dodge, color-burn, hard-light, soft-light, difference, exclusion, hue, saturation, color, luminosity):Styled::blend(BlendMode::SoftLight),Scene::set_blend, Luaublend = "soft-light"(a literal or a state). Inside a layer it blends with that layer, not the window. On the wgpu path and in the software renderer. - 3D tilts in perspective, as CSS's
perspective() rotateX() rotateY()about a node's origin:Styled::rotate_x,rotate_yandperspective(Luau props of the same names; anime keysrotateX,rotateY,perspective). The layer composites as a projected quad, sampled perspective-correctly, on the wgpu and direct Metal paths and in the software renderer; its bounds, damage and hit testing follow the projection. - Layer shaders: a node's cached layer composites through WGSL of the app's own (
fn layer(input: LayerInput) -> vec4<f32>,zgx_sample(p)reading the content elsewhere in the box), for a ripple, a chromatic split, scanlines or a dissolve:Styled::layer_shader,Scene::set_layer_shader, Luaulayer_shader = ui.layer_shader(wgsl), with uniforms (set_layer_uniforms,layer_params) and the animatedlayerTimeandlayerParam0..15, which composite again without repainting. - Frames with a blend or a layer shader draw through wgpu rather than macOS's direct Metal path, for now.
Text
- Selected text drags, as in AppKit's text views and browsers: a press on a field's selection, or selectable text's, moved past the drag threshold drags it (
DraggedText). Dropped in a field it goes where the caret shows, selected: within its field it moves as one undo step (TextEditor::move_text), into another field it moves too, and Option (Control elsewhere) copies. Out of the window, other apps take it as plain text. A password's text never leaves its field, and read-only fields take none. Views of an app's own take it withView::on_drop::<DraggedText>. - Text dragged in from other apps (a browser's selection, an editor's) drops into the field under the pointer, its caret showing where, the text selected there. On Wayland always; on macOS, Windows and X11 with zgx's winit patch, which an app from crates.io has only with its
[patch]lines (getting started, releasing). - Look Up (macOS): a field's and selectable text's context menu offers Look Up “…” for the selection, and Control-Command-D looks it up, in the dictionary's panel at the text, as AppKit's text views do (
Platform::looks_up). - Services (macOS, with zgx's winit patch, as above): the Services menu sends a field's selection, or selected display text, as plain text, and a service returning text replaces a field's selection. The menu bar's Services submenu is the one macOS fills; it was empty.
- Assistive technology finds where each character shows: a field's and selectable text's runs carry their visual lines' boxes and each character's place and width, so VoiceOver's cursor, Zoom and Hover Text follow the caret and the selection (macOS answered an empty box before).
- A triple press in a multiline field selects the paragraph, its break included, and a drag goes on by paragraphs; a shift-click after a double or triple press extends by words or paragraphs; Option-Up and Option-Down go to a paragraph's start or end (macOS), as NSTextView does.
Controls and platforms
virtual_listandui.liststretch at their edges and spring back, as scroll views did (AppKit's tables, Safari's pages); the stretch moves their content alone and places no rows. Springs back and overlay scrollbars' fades step every refresh (they stepped every 16 ms, every other refresh at 120 Hz:Ui::set_refresh_interval), and a fling's momentum into an edge bounces once.- macOS: the menu bar is made once the first frame shows (within a second), not before it; a key pressed sooner makes it at once, so shortcuts hold from the first key.
zgx inspect searchandzgx inspect zoom(MCPzgx_search,zgx_zoom) find in page and zoom a running app for agents.zgx inspect framessays why a frame did what it did (why:: a scroll repainted rather than copied and what kept it from copying, a frame kept to the last one's cadence or that missed its refresh, a window that stopped presenting;zgx::profile::note) and the GPU's own time (macOS), takes--runs,--since <mark|frame>and--keep, and warns when the window isn't presenting;marksets a point to read from.replaytakes--repeat N(each run and their spread) and--every MS, and is refused while the window can't draw;record stopwarns when a tape was recorded while the window fell behind.switch(zgx::switches) turns scroll copies, the refresh grid and partial repaints off and on in a running app, to measure what each saves; without thetracefeature they cost nothing.
Performance
- CPU cuts in style, layout, damage and text: against 0.1.2, by exact instruction counts (Linux arm64), style −25.1%, widgets −15.6%, animate −14.2%, anime −13.2%, script-update −10.8%, heavy −7.9 to −8.0%, script-layout −6.2%, chat −5.7%, mount −5.3%, the other apps, lists and scrolls −0.1 to −4.2%: every one of the 26 scenes is faster. Two reach the forks, published again with this release: a userdata method's check of its
selfinlined (zgx-mlua0.12.4) and a glyph's place on the device (zgx-cosmic-text0.19.2). - Windows: the swap chain and accessibility changes above; the GPU device opens on a thread of its own from launch, beside the first window, as macOS's does (first content 299 → 275 ms); Direct3D 12 writes frame vertices into buffers mapped once, and release builds name no driver objects (wgpu's
DISCARD_HAL_LABELS;WGPU_DISCARD_HAL_LABELS=0brings them back for a capture). - macOS: a launch reaches its first frame with 11% fewer instructions (the menu bar made after it), some 10 M fewer again (the first frame's Metal shaders translated ahead, not through naga), and the first input after a window idles wakes the GPU while its frame is built (render to present 6.7 → 1.7 ms).
Fixed
- A rich-text link shows its focus ring when focused from the keyboard, as a browser's
:focus-visibledoes, not after a click on it (a key pressed on it then shows it, as for any control). - The arrows walk mixed-direction text in the order it shows (Right in "abc אבג def" went back and forth for ever), and a paste, even of one character, is an undo step of its own.
- Icons drawn from the glyph atlas survive a change of scale and back (a window zoomed, or moved to another display): they drew other glyphs after it.
- macOS: a scroll after a pause loses no refresh (its second frame came ~22 ms after its first).
Crates: zgx, zgx-components, zgx-gpu, zgx-desktop, zgx-script, zgx-run and zgx-ghostty-sys 0.1.3; zgx-cosmic-text 0.19.2 and zgx-mlua 0.12.4.