Skip to content

zgx 0.1.4

Choose a tag to compare

@wingleeio wingleeio released this 27 Oct 23:42
· 1936 commits to main since this release

A patch: Rust and Luau code builds as before (every API change since 0.1.3 is an addition, and zgx-desktop and zgx-gpu 0.1.3 build against this zgx), unless it writes a zgx_gpu::GpuStats field by field (below). A few editor keys and clicks change, each below with what to check.

Changed: new fields

  • zgx_gpu::GpuStats gains layer_partial_repaints (layers repainted only where the window's damage reaches them). One written field by field ends with ..Default::default().

Added

  • Zoom an element, as CSS's zoom: Styled::zoom(n) (Luau zoom = n) shows a node's subtree n times as large, laid out again at that size and drawn crisply at it; zooms multiply with ancestors' and the window's, and zoom_fixed() (Luau zoom_fixed = true) keeps a node at its own size whatever zooms are around it. Scene::set_zoom, zoom, zoom_around, Ui::set_zoom_fixed; PlaneSplit::native_zoom for hosts. At 1 nothing changes. A zoomed node paints as a cached layer at its exact scale, repainted only where the window's damage reaches it (styling).
  • Zoomable elements: View::zoomable(state) (Luau zoomable = state) lets the user zoom a node in place: Control with the wheel over it steps the window's levels (Windows, Linux) and a pinch over it zooms (every platform), 25% to 500%, the innermost zoomable under the pointer taking the gesture and the window zooming elsewhere; in a scroll view what is under the pointer stays there. zgx lint reports a zoom beside a zoomable (zoomable-zoom).
  • Double-click selects a word of Chinese, Japanese or Thai, as Chrome does: those scripts put no spaces between words, and Unicode's boundaries took each character for one. zgx's new cjk-thai-words feature, on by default (and forwarded by zgx-desktop and zgx-script), finds words with ICU4X's dictionaries (北京 in 我们在北京大学, สวัสดี in สวัสดีครับ). The dictionaries are about 2.2 MB of a release binary, paged in when first used, with no startup or per-frame cost. Turn it off with default-features = false on each zgx crate an app depends on. zgx's licence is now MIT AND Unicode-3.0, for the Thai dictionary it carries (composition).
  • Lists copy as lists, as a browser's do: a list item's marker ("•", "3."), drawn as accessible-hidden text leading a Role::ListItem (as markdown draws its lists), is now the list's. A selection takes no part of it, plain text leaves it out, and copied HTML is a <ul>, or an <ol start> from the marker's number, nested as the lists are. Screen readers hear where each item is in its list ("2 of 5") unless the app says so itself. zgx lint reports a marker left as text (list-marker-hidden) (composition).
  • Windows: a start says whether it read its shaders from FXC's disk cache or compiled them, and which it couldn't keep (zgx_gpu::shader_cache_counts(); ZGX_SHADER_LOG=1 prints it with the first frame, as ZGX_PROFILE=1's startup marks carry it). It is None elsewhere, and with crates.io's wgpu-hal.

Performance

  • CPU, against 0.1.3, by exact instruction counts (Linux arm64, with a screen reader on for both, as 0.1.3 always ran; with none, as desktops run, 0.1.4 does less again): widgets −93.7% (a mount lays out its text inputs once, below), style −13.5%, animate −11.2%, heavy −9.5 to −9.9%, anime −5.7%, script-update −4.2%, the apps, lists and scrolls −0.2 to −2.7%; lab-stream and list-state level. No scene is slower.
  • macOS: a focused field left alone takes about 180 MB less memory. Its caret is a Core Animation layer, shown and hidden each blink with no frame drawn, where it was a frame each blink: the Metal driver holds about 176 MB for its command queue for some 8 s after any frame, so a blinking caret kept the window's footprint at 210 MB, where it now falls to an idle window's 30 (M5; GPUI Fast, MyGo and Rune keep 219–404 MB blinking a caret). The window does no GPU work while the caret blinks: two small wakes a second, none while the field is unfocused or the window unseen (its window server cost is what GPUI's blinking frames cost, with 1/13 of the app CPU). It is the editor's caret, drawn in frames as before, wherever Core Animation's could differ (docs/composition.md); ZGX_NATIVE_CARET=0 keeps it everywhere.

Changed: what to check in an existing app

A mount's text inputs are laid out once, when it ends, and geometry read during a mount is reactive: a mount of many inputs is linear, not quadratic (the widgets benchmark −93%), including one whose rows each run a callback of the app's own. An observer in the mount that reads geometry (Scene::bounds and the boxes made from it, from a reactive style or a binding) runs again once the mount's layout settles, if what it read has moved: a style derived from an input's width of 160 settles on 160, where it read an earlier layout's (such as the default 240) and kept it. One whose reads keep moving runs again at most a few times, then at the next flush.

  • Migrate: derive what a callback makes from its geometry read each time it runs. One that keeps only its first read (a Cell set once) keeps a value from before layout; an app relying on the earlier width needs nothing else.
  • A TextMeasurer, TextShaper or FontTextShaper is a cached computation: it may be called any number of times, in any order. The signals it reads keep their subscriptions; writing a signal from one is unsupported.

Editor keys go by words and paragraphs as each platform's text fields do. On Windows, Control-Right and Control-Delete stop at the next word's start (past the spaces), not the end of the word. On Windows and Linux, Control-Up and Control-Down go to the start of a paragraph, not up or down a line. On macOS, Control-A and Control-E go to a wrapped paragraph's edges rather than its row's. Control-K kills into a buffer that Control-Y yanks back, and Control-T swaps characters.

A fourth click keeps a triple click's paragraph selected, as Chrome's do: presses in a row count on past three (Rust EventContext::click_count, Luau's clicks), where they went round to 1 again, and selection takes three and on as a paragraph.

  • Migrate: a handler that relied on the count going back to 1 after three reads (clicks - 1) % 3 + 1.

Shift-Right extends back through right-to-left text, as Chrome does: Shift with Left or Right extends a page's selection the way its block runs (direction), so in a right-to-left paragraph Shift-Right grows it rightward on screen.

Copied HTML keeps code blocks and colours: a selection copied from a page (View::selectable) puts monospace text of more than one line in <pre>, and runs coloured apart from the text the selection starts in carry their colour (<span style="color:…">); body text and links carry none, so a dark theme's white text doesn't paste invisible.

macOS: Home and End in an editor scroll to the text's start or end and leave the caret where it is, as NSTextView and Chrome on Mac take them. Shift-Home and Shift-End extend the selection to the text's ends. ⌘← and ⌘→ go to a line's ends, ⌘↑ and ⌘↓ (and ⌘Home, ⌘End) to the text's, as before. Windows and Linux are unchanged.

  • Migrate: a test or script pressing Home or End in an editor on macOS to move the caret presses ⌘← or ⌘→.

A password field takes no input method, and on macOS types with secure keyboard entry on, as browsers' password fields and AppKit's secure text fields do: a candidate window no longer shows what is typed, and other processes can't read the keys while one has the keyboard (EditorHandle::is_secure).

  • Migrate: nothing, unless an app relied on composing (pinyin, kana) in a secure field: its keys now type their characters.

Fixed

  • A scroll under a rounded clip no longer leaves corners behind: a panel with rounded corners and overflow: hidden around a scrolling view, scrolled down and back, trailed copies of its corners down the view's edge (since before 0.1.2). Copying renderers now repaint each such corner where it is and where the scroll took its pixels; a scroll with no rounded clip around it costs what it did.
  • Windows: a frame of the app's own timing ready just before the compositor latches the next refresh waits until just past it, rather than making and missing the refresh in turn: with a timer drifting near the latch, missed refreshes in an 8 s lab stream went from 45–76 to 0–1.
  • X11: a wheel notch from a pointer with no scroll valuators (XTEST's, a remote desktop's) scrolls one line and zooms one level, not two.
  • A press in a zoomed or scaled editor lands on the character it shows on, and a drag selects the run it covers; extending a selection in a zoomed scroll view scrolls just enough to show its end.
  • macOS: each of an app's menus shows once in the menu bar (Edit, Edit, View, View before).

Crates: zgx, zgx-components, zgx-gpu, zgx-desktop, zgx-script, zgx-run and zgx-ghostty-sys 0.1.4.

Licence: zgx is now MIT AND Unicode-3.0: it carries ICU4X's Thai word dictionary (about 2.2 MB of a release binary, paged in when a Thai word is first selected), under the Unicode licence shipped as data/LICENSE-UNICODE in its package. default-features = false on each zgx crate leaves the cjk-thai-words feature, and the dictionary, out.

Instructions per scene against 0.1.3 (exact counts, Linux arm64, a screen reader on for both sides as 0.1.3 always ran; with none, as desktops run, 0.1.4 does less again):

scene 0.1.3 0.1.4 change
widgets 2,190.8 M 138.2 M −93.7%
style 1,439.4 M 1,245.4 M −13.5%
animate 312.1 M 277.1 M −11.2%
heavy-stream 1,079.0 M 972.5 M −9.9%
heavy-both 1,130.8 M 1,023.5 M −9.5%
anime 3,211.6 M 3,027.8 M −5.7%
script-update 1,485.1 M 1,422.3 M −4.2%
micro-vscroll-fixed 47.3 M 46.0 M −2.7%
micro-vscroll-fixed-luau 64.3 M 63.0 M −2.0%
app-dashboard 173.0 M 170.3 M −1.6%
lab-scroll 67.1 M 66.2 M −1.3%
app-dashboard-sort 114.9 M 113.5 M −1.2%
app-chat 48.3 M 47.8 M −1.0%
heavy-scroll 76.7 M 76.0 M −0.9%
micro-vscroll-variable 83.3 M 82.5 M −0.9%
mount 306.3 M 303.8 M −0.8%
micro-vscroll-variable-luau 128.2 M 127.2 M −0.8%
script-layout 2,842.1 M 2,823.6 M −0.7%
micro-state 56.9 M 56.6 M −0.6%
micro-state-luau 80.3 M 79.9 M −0.5%
app-code 93.4 M 93.1 M −0.3%
app-sketch 45.9 M 45.8 M −0.3%
app-mail 287.2 M 286.6 M −0.2%
app-code-search 82.5 M 82.2 M −0.2%
list-state 824.2 M 824.6 M level
lab-stream 432.0 M 431.9 M level