Rune comes from app/vendor/rune now, a checkout of 63ad0209 on branch ported, carrying the four commits of upstream issues 1320 (a pause while a clip is layered holds the layer's picture and time) and 1325 (a video's sound is read ahead of the clock and leads it). Both were written against eb9f1104 and ported across the refactors since. The faults are the first two and the third in docs/rune-upstream.md; the app's workarounds in review.rs stay until the fixes arrive upstream.
66 KiB
66 KiB
05 — Text, IME, Accessibility, and Layout
Research date: 2026-10-21
Executive Summary
- Pure-Rust text shaping and font parsing are production-ready in 2026 (
harfrust+skrifa+fontique). Google Fonts'harfrust(v0.14.0, Oct 2026) has reached HarfBuzz 14.5.1 parity, uses zero-copyfontations/read-fontstables directly (ShaperData+ShaperInstance), and runs 10–15% faster thanrustybuzzwhile supporting variable-font variation coordinates, AAT (morx/kerx/trak), and shape plans. Pair it withskrifa(v0.42.0) for TrueType/CFF hinting + COLRv1 andfontique(v0.8.0) for font enumeration and script/locale fallback. - Keep OS font metrics on Apple (
CTFont) while usingharfrust+parleyfor cross-platform shaping and line breaking. On macOS and iOS, system UI fonts (SF Pro,SF Compact,.AppleSystemUIFont) rely on optical-size (opsz) tracking tables (trak) and OS-specific ascent/descent rules. Useparley(v0.12.0, built onparley_engine+fontique+harfrust+skrifa+icu4x) for bidirectional paragraph layout, mixed inline runs, and cursor/selection geometry, augmented with GPUI's two-tier unwrapped-vs-wrappedLineLayoutCache(zed/crates/gpui/src/text_system/line_layout.rs:523-698) so container resizes only recompute wrap boundaries without re-shaping. - Luminance-quantized glyph dilation solves light-on-dark thin text on Apple displays without subpixel LCD fringes. Subpixel LCD rendering is incompatible with transparent layers and GPU transforms. Instead, steal Kit's GPUI fork (
kitlangton/gpui) luminance glyph dilation (kitlangton/gpui/src/platform/mac/text_system.rs:42-81, 470-564, commit2582af8ad0): quantize text color relative luminance (0.2126R + 0.7152G + 0.0722B) into 5 cache buckets (0..=4), padraster_boundsby1px, and rasterize withset_should_smooth_fonts(true)at that gray fill level whenAppleFontSmoothing != 0, paired with linear-space (sRGBframebuffer) alpha blending. - Never re-rasterize hinted glyphs on every frame of a spring transform. Vello's
glifo(vello/glifo/src/glyph.rs:1702-1731) folds uniform transform scale intodraw_font_sizeand hashessize.to_bits(), thrashing the glyph atlas and causing stem-hinting pop on every frame of a 120 Hz spring animation. During active transforms, lock glyphs to unhinted/linear-metrics outlines rasterized at the target (or octave-stepped) scale and sample bilinearly, or promote large/hero animated text (> 28pxor explicitly tagged) to Rive-style per-glyph vector paths (rive-runtime/src/text/text.cpp:544-592). - Use a unified
SumTree-backed rope + display map for all text editing, from single-line inputs to multi-megabyte buffers. Zed's concurrent B+ treeSumTree(zed/crates/sum_tree/src/sum_tree.rs,TREE_BASE = 6) maintains UTF-8 bytes, UTF-16 code units (required by Apple/Windows/Web IME), UTF-32 chars, line breaks, and soft-wrap display rows inO(\log N)time with zero-copyArcsnapshots. - Implement native platform IME protocols directly on desktop and iOS, with a sliding-window
<textarea>+EditContexthybrid on Web. DirectNSTextInputClient(macOS),UITextInput+UIEditMenuInteractionsubclass (iOS, stealing GPUI's deferredreconcileTextInputingpui_ios/src/ios/text_input.rs:197-318),ITfThreadMgr/ImmGetCompositionStringW(Windows), andzwp_text_input_v3(Wayland) avoid hidden-native-widget desynchronization while preserving marked text, candidate window anchoring, Dictation, and Apple Writing Tools. - AccessKit (
v0.24/ 2026) is the clear winner for cross-platform accessibility and doubles as Rune's agent-inspector tree. AccessKit now covers macOS (accesskit_macos), Windows (accesskit_windows), Linux AT-SPI (accesskit_unix), Android (accesskit_android), and iOS (accesskit_ios,accesskit/adapters/ios/src/node.rs). Building a single retainedaccesskit::TreeUpdateper frame gives VoiceOver/TalkBack/NVDA and AI testing/automation agents (cua-driver) one canonical semantic tree with roles, bounds, values, and deterministicActionRequestdispatch. - Adopt a two-path layout architecture:
Taffy(v0.9.x) for general Flexbox/CSS Grid UI + aSumTree-indexed height cache for virtualized lists + first-class layout interpolation hooks.Taffyis heavily optimized (1.6 ms for 1,000 nodes vs Yoga's 1.5 ms on M1 Pro; 59 ms vs 84 ms on 100k Twitter feed nodes) and matches CSS mental models that LLMs write fluently, whereasPretext+SumTreeprefix-sum heights eliminate the 106.4 ms SwiftUIsizeThatFitsbottleneck (a private iOS layout benchmark), dropping 500-paragraph resize passes to 2.6 ms.
1. Text Shaping & Fonts
1.1 harfrust vs rustybuzz vs OS Shapers (CoreText / DirectWrite)
| Dimension | harfrust (v0.14.0, Oct 2026) |
rustybuzz (v0.20.x) |
CoreText (CTLine/CTTypesetter) |
DirectWrite (IDWriteTextAnalyzer) |
|---|---|---|---|---|
| HarfBuzz parity | HarfBuzz 14.5.1 (harfrust/CHANGELOG.md:9) |
Trails HarfBuzz ~6–12 months | Apple AAT + OpenType engine | Microsoft OpenType engine |
| Font table backend | Native read-fonts (fontations), zero-copy via ShaperData |
Bundled ttf-parser |
CGFont / CTFont |
IDWriteFontFace |
| Performance | ~10–15% faster than rustybuzz; caches reusable ShaperData & ShaperInstance |
Fast CPU, re-parses tables per face | Fast, but Objective-C/CF allocation overhead per run | Fast, COM call overhead |
Apple trak / AAT (morx, kerx) |
Supported (harfrust ports HarfBuzz AAT tables) |
Partial AAT support | Reference implementation (including optical size opsz tracking) |
No AAT morx |
| Cross-platform determinism | 100% identical glyph IDs & advances across all OSes | 100% identical across all OSes | Apple-only | Windows-only |
Source findings:
harfrusthas supersededrustybuzzacross the Linebender and Servo ecosystems. Originally started by Simon Cozens and Behdad Esfahbod (harfrust/CHANGELOG.md:201-215),harfrustis maintained directly under the HarfBuzz organization with Behdad Esfahbod and Chad Brokaw actively porting HarfBuzz algorithmic improvements (harfrust/CHANGELOG.md:7-55).- Pre-parsed table caching (
ShaperData) and variation instance caching (ShaperInstance): Inharfrust/src/hb/ot_shaper.rsandparley/parley/src/shape.rs:146-172,ShaperData::new(&font_ref)pre-validates font tables once, whileShaperInstance::from_variations(&font_ref, coords)caches variation-axis coordinate lookups and feature stores. Shaping a run reuses a thread-localharfrust::UnicodeBuffer(parley/parley/src/shape.rs:424-449) with zero per-run heap allocations. - CoreText vs
harfrusttradeoff on Apple: GPUI currently callsCTTypesetterCreateWithAttributedStringandCTLineGetGlyphRunsdirectly on macOS and iOS (zed/crates/gpui_apple/src/text_system.rs:477-568). While CoreText automatically applies Apple's undocumented optical tracking for.AppleSystemUIFont(SF Pro), allocatingCFAttributedStringandCFDictionaryper text run costs measurable CPU time: in a private iOS layout benchmark, coldCTFramesettermeasurement across 500 chat paragraphs takes 17.8 ms (35.5 µs/msg), and SwiftUIText.sizeThatFitstakes 106.4 ms (212.9 µs/msg).
1.2 Font Loading, Parsing, Hinting, and Fallback (fontations/skrifa, swash, fontique)
fontations(read-fonts+skrifav0.42.0) vsswash:- Google's
fontationsworkspace (skrifa+read-fonts) is now the standard Rust font stack used by Chrome (replacing FreeType in Chromium), Parley, Vello (glifo), and Bevy. skrifa(fontations/skrifa/src/outline/mod.rs:1-148) provides a complete TrueType bytecode interpreter, CFF/CFF2 hint engine, and a FreeType-derived Latin/CJK autohinter (HintingOptions { engine: Engine::AutoFallback, target: Target::Smooth { mode: SmoothMode::Lcd | Normal, symmetric_rendering: true, preserve_linear_metrics: false } }).swashis effectively unmaintained upstream; Parley removedswashentirely inv0.4.0(parley/CHANGELOG.md:191-215) in favor ofharfrust+skrifa.
- Google's
fontique(v0.8.0) for system font discovery and fallback:fontique(maintained insideparley/fontique) handles cross-platform system font collection (CoreTexton macOS/iOS,DirectWriteon Windows,fontconfigon Linux,AndroidXML/NDK font configuration) plus app-registered memory fonts (register_fonts).- During shaping (
parley/parley/src/shape.rs:212-345),fontiquepartitions text byicu_properties::CodePointMapData::<Script>, queries the family list first, and only falls back tofont_ctx.collection.fallback_families(FallbackKey::new(script, locale))for.notdef(glyph_id == 0) sub-clusters, preserving variable font variation coordinates across fallback faces.
1.3 Variable Fonts, OpenType Features, and Emoji
- Variable fonts (
wght,opsz,wdth,slnt, custom axes):skrifa::MetadataProvider::axes()resolves user axis tags into normalizedF2Dot14design-space coordinates shared identically betweenharfrust::ShaperInstance(forGPOS/GSUBfeature variations andHVAR/MVARadvances) andskrifa::outline::OutlineGlyphCollection(forgvar/CFF2interpolated glyph outlines). - OpenType features:
harfrust::Featuresupports arbitrary 4-byte OpenType tags (liga,calt,dlig,tnum,onum,zero,ss01–ss20,cv01–cv99,kern) scoped by byte range (parley/parley/src/shape.rs:178-206). - Emoji (
COLRv0/COLRv1,sbix,CBDT/CBLC):- Apple Color Emoji uses
sbix(embedded PNG strips per strike ppem). - Google Noto Color Emoji (Android/Linux/Web) uses
COLRv1(vector paint graphs with linear/radial/sweep gradients, blend modes, andVARCvariable composites) orCBDT/CBLC(embedded PNG bitmaps). - Windows Segoe UI Emoji uses
COLRv0/COLRv1. - Vello's
glifo(vello/glifo/src/glyph.rs:289-424andvello/glifo/src/colr.rs) inspects glyph tables in priority order:skrifa::color::ColorGlyphCollection(COLRv0/COLRv1) ->sbix/CBDTbitmap strikes (image::load_from_memory_with_format(..., ImageFormat::Png)) -> standard monochrome outline.
- Apple Color Emoji uses
2. Text Layout
2.1 parley vs cosmic-text vs GPUI's Text System
| Engine | Shaping / Bidi / Line-Break Stack | Strengths | Weaknesses |
|---|---|---|---|
parley (v0.12.0, Oct 2026) |
harfrust + skrifa + fontique + icu4x (icu_segmenter, parley_bidi) |
Clean split between parley_engine (core layout) and fontique; supports inline boxes (InlineBox), text-indent (IndentOptions), cluster/cursor geometry, Alignment::Justify, zero allocations on warm LayoutContext. |
Does not include a built-in cross-frame unwrapped-vs-wrapped line cache out of the box (expects host UI to cache Layout). |
cosmic-text |
rustybuzz + swash + fontdb + unicode-bidi |
Battle-tested in System76 COSMIC; includes a basic shape cache (ShapeLine vs LayoutLine). |
Stuck on legacy swash/rustybuzz; weaker inline-box and CSS-aligned typography model than parley. |
GPUI (gpui + gpui_apple / gpui_wgpu) |
Platform LineWrapper + layout_line (CoreText on Apple, DirectWrite on Windows, cosmic-text on Linux/Web) |
Best-in-class two-tier LineLayoutCache (line_layout.rs:523-698) with frame-epoch eviction and bulk reuse_layouts. |
Fragmented per-OS shaping leads to subtle cross-platform line-break and fallback differences; manual boundary wrapper (LineWrapper::wrap_line) rather than full UAX #14. |
2.2 Bidirectional Text, Mixed Inline Runs, and Line Breaking
- Bidirectional layout (UAX #9):
parleyusesparley_bidi(parley/CHANGELOG.md:27) to resolve embedding levels per paragraph and reorders visual runs per wrapped line after line breaking (as required by UAX #9 Section 3.4), ensuring hit-testing (Cursor::from_point) and selection rectangles (Selection::geometry_with) remain accurate across mixed RTL/LTR/numeric runs. - Line breaking (UAX #14) & hyphenation:
parleyusesicu_segmenter::LineSegmenterfor locale-aware UAX #14 line break opportunities (handling CJK kinsoku shori, Thai dictionary breaking, and emergencyWordBreakStrength::BreakAll/KeepAll). - Inline boxes (pills, badges, icons, inline code):
parley::LayoutBuilder::push_inline_box(InlineBox { id, index, width, height })(parley/parley/src/layout.rs) participates directly in line breaking, baseline alignment, and cursor navigation as an atomic cluster—essential for chat UIs with@mentionpills, file chips, and inline status badges.
2.3 Truncation, Ellipsis, and SwiftUI/TextKit 2 Soft Fade Masks
- Why ellipsis (
…) layout is expensive when naively implemented: Shaping an ellipsis string and re-shaping the truncated line tail on every resize requires mutating the glyph stream. GPUI (zed/crates/gpui/src/text_system/line_wrapper.rs) measures the ellipsis width once per font/size and truncates at cluster boundaries, while SwiftUI/TextKit 2 (NSTextLayoutManager) supports both glyph-replacement ellipsis and visual fade masks. - Soft fade masks instead of
…: In modern streaming chat and card UIs (and animated label containers), hard…glyph substitution causes jarring character popping as width animates or tokens stream in. Rendering the full shaped line clipped to the container rect with a horizontal alpha gradient mask over the trailing16–24px(in linear alpha space, direction-aware for LTR/RTL) requires zero re-shaping during width animations, never pops glyphs, and signals overflow cleanly. Rune should support bothOverflow::Ellipsis(cached ellipsis cluster substitution onmax_lines) andOverflow::FadeMask { tail_px: f32 }(shader-evaluated edge ramp in the text quad primitive).
2.4 Caching Shaped Lines Across Frames (Zed's LineLayoutCache & Pretext)
- Zed's two-tier
LineLayoutCache(zed/crates/gpui/src/text_system/line_layout.rs:523-698):- Unwrapped tier (
lines): Keyed by(SharedString, font_size: Pixels, SmallVec<[FontRun; 1]>, force_width: Option<Pixels>). StoresArc<LineLayout>containing shaped glyph positions and UTF-8 indices. - Wrapped tier (
wrapped_lines): Keyed by(SharedString, font_size, runs, wrap_width: Option<Pixels>). Whenwrap_widthchanges (e.g., dragging a split pane or rotating a phone),layout_wrapped_line(line_layout.rs:639-644) hits the cachedunwrapped_layoutand only runscompute_wrap_boundariesover pre-shaped advances. - Two-frame epoch eviction + bulk reuse:
LineLayoutCacheholdscurrent_frameandprevious_framehash maps (FxHashMap). Views that do not re-layout callreuse_layouts(range: Range<LineLayoutIndex>)(line_layout.rs:523-566), which moves used entries fromprevious_frametocurrent_frameby index slice without even hashing keys. Atfinish_frame()(line_layout.rs:586-600), the maps swap and stale entries fromprevious_frameare dropped.
- Unwrapped tier (
Pretextvalidation (a private iOS layout benchmark):- Across 500 mixed markdown/code chat messages on iOS, re-measuring height on viewport width change took 106.44 ms with SwiftUI
sizeThatFits, 17.75 ms with coldCTFramesetter, 2.60 ms with cachedCTFramesetterframes, and 0.23 ms with Pretext's pre-segmented width table (a 462x speedup over SwiftUIsizeThatFits, though Pretext's naive whitespace Collapse had a 29% height mismatch against TextKit 2's hyphenation/kerning). Using exact glyph-run advances from the unwrappedLineLayoutcache gives Pretext-class resize speed (< 1 ms for 500 paragraphs) with 0% height drift.
- Across 500 mixed markdown/code chat messages on iOS, re-measuring height on viewport width change took 106.44 ms with SwiftUI
3. Glyph Rendering
3.1 Glyph Atlas (Grayscale vs Subpixel AA) vs GPU Vector Outlines
| Technique | Crispness at 10–16pt (2x Retina / 1x LoDPI) | Memory & Bandwidth | Arbitrary 2D/3D / Spring Scale Cost | Verdict for Rune |
|---|---|---|---|---|
Grayscale Mask Atlas + Luminance Dilation (kitlangton/gpui) |
Excellent on 2x Retina and 1x with skrifa hinting + 5-level luminance dilation |
Low (R8Unorm 1 byte/px; RGBA8 4 bytes/px for emoji) |
Fast at fixed scale; thrashes atlas if re-rasterized per scale frame | Primary UI text path |
Subpixel LCD Atlas (RGB ClearType/FreeType LCD) |
Sharpest on 1x non-Retina horizontal RGB panels | 3–4x atlas memory; requires dual-source blending (blend_src1) |
Breaks under rotation, scale, non-RGB subpixel layouts (OLED), or unpremultiplied compositing | Avoid (dead on macOS since Mojave, broken on OLED/mobile/rotated layers) |
| SDF / MSDF Atlas | Poor at 11–14pt UI sizes (rounded corners, stem weight distortion on CJK/kanji) | Medium (offline or slow generator per glyph) | Smooth infinite zoom | Avoid for UI text |
| Slug (Lengyel GPU Bezier evaluation) | Exact unhinted outlines at any zoom | Compact curve/band textures | Zero atlas thrashing under zoom/3D; higher fragment shader ALU per covered pixel; no stem hinting at 11–13pt | Optional hero/3D/canvas text path (patent entered public domain / open-sourced in 2026, or via glifo/Vello compute) |
Vello / glifo CPU-cached Atlas (vello/glifo/src/glyph.rs) |
Good (skrifa hinted outlines rasterized via vello_common::kurbo strip generator into shelf-packed AtlasPage) |
Low (PlainMask + Color atlases) |
Currently absorbs transform t_d into draw_font_size (glyph.rs:1702-1731), thrashing cache on scale animations |
Steal glifo's skrifa + COLRv1 + sbix pipeline, fix its transform-scale key behavior |
Rive Direct Vector Path (rive-runtime/src/text/text.cpp:544-592) |
Exact unhinted vector curves tessellated/rasterized by GPU path renderer | Zero glyph atlas | Native per-glyph TextModifierGroup affine transforms + variable-font axis keyframing at 120 Hz |
Use for hero / animated / path-warped text (TextRenderMode::Vector) |
3.2 macOS Font Smoothing, Stem Darkening, and Kit's GPUI fork (kitlangton/gpui) Luminance Glyph Dilation
Why text in naive GPU renderers looks "too thin" or "washed out" on macOS:
- Gamma blending error: Blending a linear coverage mask
\alphadirectly in non-linear sRGB space computesC_{\text{out}} = \alpha C_{\text{fg}} + (1 - \alpha) C_{\text{bg}}in sRGB, which darkens mid-tones and makes light text on a dark background lose ~20–30% of its perceived stroke weight compared to dark text on a light background. - CoreGraphics
AppleFontSmoothingbehavior in alpha-only contexts: When rasterizing glyphs into a single-channelkCGImageAlphaOnlybitmap (gpui_apple/src/text_system.rs:429-434), callingCGContextSetShouldSmoothFonts(cx, true)tells CoreGraphics to apply stem darkening (synthetic bolding/dilation)—but CoreGraphics modulates the dilation strength by the luminance of the active fill color in theCGContext! If a GPU renderer rasterizes glyphs once into an alpha-only atlas with a fixed white (1.0) or black (0.0) fill color, either dark-on-light text looks overly heavy or light-on-dark text looks spindly.
How Kit's GPUI fork (kitlangton/gpui) Luminance Glyph Dilation works (kitlangton/gpui/src/platform/mac/text_system.rs, commit 2582af8ad0):
- 5-bucket relative luminance quantization (
text_system.rs:42-69):pub(crate) const GLYPH_DILATION_LEVELS: u8 = 5; pub(crate) fn glyph_dilation_for_color(color: Hsla) -> u8 { if !font_smoothing_enabled() { return 0; } let rgba = color.to_rgb(); let luminance = 0.2126 * rgba.r + 0.7152 * rgba.g + 0.0722 * rgba.b; (luminance * (GLYPH_DILATION_LEVELS - 1) as f32) .round() .clamp(0.0, (GLYPH_DILATION_LEVELS - 1) as f32) as u8 } - System default detection (
text_system.rs:71-81): Reads macOSNSUserDefaults::standardUserDefaults().integerForKey("AppleFontSmoothing")once viaOnceLock; enabled when!= 0(matching macOS default2). - Cache key & bounds padding (
text_system.rs:470-499):RenderGlyphParamsincludesdilation: u8(0..=4). Whenfont_smoothing_enabled()is true,raster_boundsadds1pxpadding on all four sides (origin - (1, 1),size + (2, 2)) so dilated glyph stems never clip at the atlas tile boundary. - Rasterization (
text_system.rs:537-564): Insiderasterize_glyph, whenparams.dilation > 0:This feeds CoreGraphics the exact 25%-stepped gray luminance (let luminance = params.dilation as f64 / (GLYPH_DILATION_LEVELS - 1) as f64; cx.set_should_smooth_fonts(true); cx.set_gray_fill_color(luminance, 1.0);0.0, 0.25, 0.50, 0.75, 1.0), producing authentic macOS stem weight across both light and dark themes while capping atlas growth to at most the active foreground luminance buckets (typically 2 buckets per theme: primary text + muted text). - Cross-platform equivalent on
skrifa/FreeType (Windows/Linux/Android): When usingskrifa+ CPU/GPU outline rasterization off Apple, apply FreeType/Adobe CFF stem darkening in outline space (darken_x = 0.025 * ppem, modulated by foreground-vs-background luminance contrast) or a linear-space coverage gamma adjustment (\alpha' = \alpha^{1.0 / \gamma_{\text{contrast}}}) in the glyph fragment shader.
3.3 Why SDF / MSDF Fails for Small UI Text
- Single-channel SDF cannot preserve sharp corners (a single distance value rounds every corner when reconstructed at scales different from the raster grid), making
11–14ptsans-serif stems (I,l,m,n) look mushy or blob-like. - Multi-channel SDF (MSDF) preserves sharp 2-edge corners by encoding signed distances to two edge segments in R/G/B channels and taking
median(r, g, b). However:- Complex glyphs with >2 converging edges per texel (common in
11–14ptCJK ideographs,@,%,&, and serif joins) suffer from false edge artifacts (spikes and dropouts) unless the MSDF texel resolution is high (32x32to64x64per glyph). 2.Generating an MSDF on the CPU on demand for newly encountered CJK/Unicode glyphs is 10–30x slower than scanline coverage rasterization. - MSDF operates on unhinted outlines, losing pixel-grid stem alignment at
10–15pton 1x/2x displays.
- Complex glyphs with >2 converging edges per texel (common in
3.4 Subpixel Positioning (4 Horizontal × 1 Vertical Phases)
- Without subpixel positioning, snapping glyph origins to integer device pixels causes uneven inter-glyph kerning ("dancing letters" when slowly scrolling or adjusting tracking).
- Both GPUI (
zed/crates/gpui/src/text_system.rs,SUBPIXEL_VARIANTS_X = 4, SUBPIXEL_VARIANTS_Y = 1on Retina) and Vello'sglifo(vello/glifo/src/glyph.rs:437-465,SubpixelAxis::Four=0.0, 0.25, 0.5, 0.75) quantize the fractional device-pixel X coordinate into 4 horizontal subpixel phases (u80..=3) and 1 vertical phase (since horizontal text baselines align vertically to rows). - Important optimization from
glifo/src/glyph.rs:444-465: Above a font size threshold (OPTICAL_SIZE_THRESHOLD~24–32pxdevice pixels), subpixel phase quantization is reduced toSubpixelAxis::TwoorOne(integer pixel snapping), preventing atlas bloat on large headings where a0.25pxshift is imperceptible.
3.5 Animated Text Under Spring Transforms (Why Text Jitters & How Apple / Figma / Rive Solve It)
The bug in naive atlas renderers (including Vello glifo):
- In
vello/glifo/src/glyph.rs:1702-1731(GlyphScaleProperties::new), when a draw transform has uniform or axis-aligned scale (t_a,t_d),glifofoldst_ddirectly intodraw_font_size = font_size * t_dand keys the glyph cache bysize: draw_font_size.to_bits()(u32,glyph.rs:480-523). - During a 120 Hz spring scale animation (e.g.,
scale: 0.92 -> 1.02 -> 1.00),draw_font_sizetakes 60+ distinctf32bit patterns in 500 ms. Worse, if hinting or integer advance rounding is enabled, stems jump between pixel columns ("swimming / jittering letters") and the glyph atlas thrashes on every frame.
How production engines solve animated text:
- Apple CoreAnimation / SwiftUI (
CATextLayer,.drawingGroup(),NSStringDrawingOptions):- For standard layer transforms (
scaleEffect, modal spring entrance), CoreAnimation caches the text layer at its target (1.0x) contentsScale (or highest octave scale) and applies the spring transform in the GPU compositor with bilinear texture filtering + linear metric advances (CTFontCreateWithFontDescriptorwithkCTFontLinearMetricsAttribute/ subpixel positioning). - For SwiftUI
matchedGeometryEffect/ variable font transitions, Apple interpolates between two pre-rasterized scale snapshots or switches to unhinted subpixel-positioned outlines (preserve_linear_metrics: true).
- For standard layer transforms (
- Figma (WebGL / WebGPU canvas renderer):
- Figma renders text via cached glyph textures while stationary at a discrete zoom level, and during continuous zoom/spring animations either samples the nearest higher power-of-two mip octave from the glyph atlas with linear metrics or renders vector glyph meshes on the GPU.
- Rive (
rive-runtime/src/text/text.cpp:544-592,text_modifier_group.cpp):- Rive never uses a bitmap glyph atlas for scene text. Every shaped glyph outline is extracted as an unhinted
RawPathin normalized em-space (rive-runtime/src/text/text.cpp:544-592) and rendered directly by Rive's GPU vector renderer (PLS / atomic feathering) under per-glyphMat2Dtransforms (TextModifierGroup::transformGlyphsupporting per-character opacity, rotation, scale, position, and variable font axis keyframing at 120 Hz with zero atlas re-rasterization).
- Rive never uses a bitmap glyph atlas for scene text. Every shaped glyph outline is extracted as an unhinted
Rune's hybrid rule for animated text:
- Static & scrolling UI text (
<= 28pt, no active scale/rotation animation): Hinted (skrifapreserve_linear_metrics: falseon 1x, unhinted/light-hintedpreserve_linear_metrics: trueon\ge 2\text{x}Retina) + 4x horizontal subpixel phase + 5-level luminance dilation in the glyph atlas. - Text inside an active scale/rotation spring transform: Automatically switch the text primitive to transform-invariant atlas sampling: rasterize once at
ceil_octave(max_expected_scale) * font_sizewithpreserve_linear_metrics: trueand fractional GPU quad positions (do not snap glyph quads to integer device pixels while transforming!), sampling with bilinear filtering + mild sharpening. - Hero / kinetic typography (
> 28pt, or explicit.textRenderMode(.vector)/ per-glyphTextModifier): Bypass the bitmap atlas and emit unhintedskrifaoutlines directly into Rune's GPU vector path pipeline (Vello/Slug-style curve evaluation), enabling Rive-class per-character spring choreography and variable-font weight/width animations with zero atlas traffic.
4. Text Editing (Single-Line Input through Rich Code/Prose Editor)
4.1 Selection, Caret, Bidirectional Cursor Movement, and Affinity
- Selection representation: Every selection is an ordered or directional pair
Selection { start: usize, end: usize, reversed: bool, goal_column: Option<f32> }in UTF-8 byte offsets, accompanied byAffinity::{Upstream, Downstream}(parley/parley/src/cursor.rs). - Why
Affinityis mandatory: At a soft line wrap boundary, byte offsetkcorresponds to two distinct screen positions: the end of linei(Affinity::Upstream) and the start of linei+1(Affinity::Downstream). Likewise, at an LTR/RTL bidi boundary, a single byte offset maps to two split-caret visual X positions.parley::Cursorencodes(index: usize, affinity: Affinity)directly and computes visual geometry viaCursor::geometry(&layout, size). - Grapheme and word navigation (UAX #29):
- Left/Right arrow movement steps by extended grapheme clusters (
icu_segmenter::GraphemeClusterSegmenterorunicode-segmentation), so multi-codepoint emoji (family ZWJ sequences👨👩👧👦, skin-tone modifiers, flag pairs) and combining marks move and delete (BackspacevsDelete) correctly. - Option+Left/Right (macOS) / Ctrl+Left/Right (Windows/Linux) and double-click word selection use UAX #29 word boundaries customized with character-class tables (
Alphanumeric,Punctuation,Whitespace, plus configurableword_characterslike_or$for code inputs). - Triple-click selects the logical paragraph (or visual line with modifier), dragging extends selection by word (double-click-drag) or line (triple-click-drag) by anchoring the initial word/line range (
gpui_ios/src/ios/text_input.rs/zed/crates/editor).
- Left/Right arrow movement steps by extended grapheme clusters (
4.2 Buffer Data Structures: Ropes vs Zed's SumTree
| Data Structure | Memory / Node | Concurrent Snapshot | Multi-Coordinate Indexing (UTF-8, UTF-16, Lines, Display Wrap) | Used By |
|---|---|---|---|---|
String / Gap Buffer |
Contiguous Vec<u8> |
Requires full clone | O(N) scan for UTF-16 or line numbers |
Naive single-line inputs |
ropey |
B-tree of UTF-8 chunks | Clone-on-write (Arc) |
UTF-8, chars, lines; UTF-16 conversion added but no custom summary dimensions | Helix, cosmic-text |
Zed SumTree + Rope (zed/crates/sum_tree/src/sum_tree.rs, zed/crates/rope) |
Arc-backed B+ tree (TREE_BASE = 6, up to 12 children/node) |
O(1) lock-free Clone |
Arbitrary Summary trait + multiple simultaneous Dimension types (usize bytes, Point, PointUtf16, OffsetUtf16, Chars) |
Zed (Buffer, DisplayMap, WrapMap, FoldMap, BlockMap) |
Why Rune should steal Zed's SumTree + Rope pattern (zed/crates/sum_tree/src/sum_tree.rs:1-140):
- Every node in
SumTree<T>stores an aggregatedT::Summary. ForRope::Chunk,TextSummarytrackslen: usize(UTF-8),len_utf16: OffsetUtf16,lines: Point(row/col),first_line_chars,last_line_chars, andlongest_row. - Converting between UTF-8 byte offsets (used by Rust/
harfrust/parley) and UTF-16 code-unit offsets (mandated by macOSNSRange, iOSUITextPosition, WindowsImmGetCompositionStringW, and WebEditContext/HTMLTextAreaElement) is a singleO(\log N)B+ tree traversal (rope.offset_to_offset_utf16(byte_offset)), eliminating the #1 source of UTF-16 surrogate-pair crashes in emoji-heavy inputs! - Even better, the exact same
SumTreecrate powers both text buffers and virtualized list prefix-sum heights (Section 7).
4.3 Undo/Redo Grouping, DefaultKeyBinding.dict, and System Text Services
- Undo/Redo transaction grouping: Group consecutive character insertions within a
300 mstyping window (broken by whitespace/newline, paste, cursor jump, or backspace transitions) into a single undo transaction storing(transaction_id, timestamp, selection_before, selection_after, Vec<Edit>). - macOS
DefaultKeyBinding.dictbug in GPUI and how to fix it:- In
zed/crates/gpui_macos/src/window.rs:3513-3531, GPUI implementsdoCommandBySelector:as:Because GPUI drops the// We ignore which selector it asks us to do because the user may have // bound the shortcut to something else. extern "C" fn do_command_by_selector(this: &Object, _: Sel, _: Sel) { ... }selector: Selargument and simply replayskeystroke_for_do_commandinto its own keymap, any custom user binding in~/Library/KeyBindings/DefaultKeyBinding.dict(such as mapping a key chord todeleteWordBackward:,moveToBeginningOfParagraph:,yank:,setMark:,swapWithMark:, or a multi-selector array) is ignored! - Fix for Rune: First check if the application keymap explicitly binds the raw keystroke. If not (or if
NSTextInputContextsynthesized one or moreNSStandardKeyBindingRespondingselectors fromDefaultKeyBinding.dict), dispatch the actualSel(insertNewline:,deleteBackward:,deleteWordBackward:,moveWordForward:,moveToBeginningOfLine:,transpose:,yank:, etc.) to the focused text input handler.
- In
- Spellcheck, Autocorrect, Dictation, and Apple Writing Tools (macOS 15+ / iOS 18+):
- Spellcheck & Autocorrect: On macOS, query
NSSpellChecker.sharedSpellCheckerasynchronously on background worker threads per edited paragraph (checkSpellingOfString:startingAt:language:wrap:inSpellDocumentWithTag:wordCount:) and render wavy/dotted underlines as a text decoration layer; on iOS,UITextInputTraits.spellCheckingTypeandautocorrectionTypeare driven natively byUITextInteraction. - Dictation: On both macOS (
NSTextInputClient) and iOS (UITextInput), system Dictation streams tentative transcriptions viasetMarkedText:selectedRange:replacementRange:and commits viainsertText:replacementRange:(plusinsertDictationResult:on iOS). - Apple Writing Tools (macOS 15+ / iOS 18+): Conforming to
NSWritingToolsCoordinatorDelegate(macOS) orUIWritingToolsCoordinatorDelegate/UITextInput(iOS) allows Apple Intelligence Writing Tools to read context ranges, animate proofreading/rewrite highlights, and apply replacements with built-in undo support.
- Spellcheck & Autocorrect: On macOS, query
5. IME (Input Method Editors) Per Platform
5.1 Architecture Matrix Across All 6 Platforms
| Platform | Native Protocol / API | Coordinate Unit | Composition / Marked Text | Candidate Window Positioning | Context / Recon Strategy |
|---|---|---|---|---|---|
| macOS | NSTextInputClient on NSView + NSTextInputContext (gpui_macos/src/window.rs:236-298, 2700-2780, 3368-3532) |
UTF-16 NSRange |
setMarkedText:selectedRange:replacementRange:; unmarkText |
firstRectForCharacterRange:actualRange: (screen coordinates, bottom-left origin!) |
Synchronous query into InputHandler during handleEvent: |
| iOS | Custom UIView <UITextInput, UIKeyInput> + UITextInteraction + UIEditMenuInteraction (gpui_ios/src/ios/text_input.rs:197-1150; FlutterTextInputPlugin.mm:180-1100) |
Abstract UITextPosition wrapping UTF-16 index |
setMarkedText:selectedRange:; unmarkText |
firstRectForRange: + caretRectForPosition: + selectionRectsForRange: |
Deferred coalesced reconcileTextInput (dispatch_async to main queue) to prevent UIKit feedback loops |
| Android | View.onCreateInputConnection -> BaseInputConnection + InputMethodManager |
UTF-16 Editable / offsets |
setComposingText, setComposingRegion, finishComposingText |
CursorAnchorInfo.Builder (setInsertionMarkerLocation, addCharacterBounds) |
State push via imm.updateSelection + imm.updateCursorAnchorInfo |
| Web (2026) | Primary: Sliding-Window Hidden <textarea> (gpui_web/src/ime_mirror.rs:1-450, CONTEXT_CHARS = 512) + progressive enhancement to EditContext API on Chromium/Edge |
UTF-16 DOM offsets | compositionstart, compositionupdate, compositionend, beforeinput (insertFromComposition) |
CSS positioning of <textarea> at bounds_for_range (ime_mirror.rs:412-448) or EditContext.updateCharacterBounds |
Sliding 1,024-char window synced after every frame |
| Windows | WM_IME_STARTCOMPOSITION, WM_IME_COMPOSITION (ImmGetCompositionStringW with GCS_COMPSTR, GCS_COMPATTR, GCS_CURSORPOS, GCS_RESULTSTR) + TSF (ITfThreadMgr / ITfContext) (gpui_windows/src/events.rs:654-790, 1710-1760) |
UTF-16 (WCHAR slice) |
Clause-attributed composition (ATTR_TARGET_CONVERTED, ATTR_CONVERTED, ATTR_INPUT) |
ImmSetCompositionWindow + ImmSetCandidateWindow (CFS_CANDIDATEPOS) |
Per-window ImmAssociateContextEx enabled only when text input focused |
| Linux (Wayland / X11) | Wayland: zwp_text_input_v3 (gpui_linux/src/linux/wayland/client.rs:2278-2354); X11: XIM (XIC) |
UTF-8 byte offsets | Event::PreeditString { text, cursor_begin, cursor_end } buffered until Event::Done { serial } |
set_cursor_rectangle(x, y, width, height) + commit() with serial tracking |
Transactional PreeditString + CommitString applied atomically on Done |
5.2 Deep-Dive Findings & Subtle Platform Traps
- macOS Key Routing Order (
gpui_macos/src/window.rs:2700-2748):- If you run app keybindings before
[inputContext handleEvent: native_event], multi-keystroke bindings (like Vimjjor chord shortcuts) intercept keys meant for Japanese/Chinese/Korean IME (turningjiintojいinstead ofじ) or swallow dead keys (Option+e->é). - Conversely, if you send all keys to
inputContextfirst when no text input is focused, macOS beeps or eats shortcuts. - Rule: Send key events to
inputContextfirst if and only if: (a)hasMarkedText()is true (is_composing), OR (b) a printable key withoutCtrl/Cmd/Fnis pressed while an IME input source is active and the focused view accepts text input (is_ime_printable_key), OR (c) it is a dead key (key_char.is_none()).
- If you run app keybindings before
- iOS Direct
UITextInputvs HiddenUITextField(gpui_ios/src/ios/text_input.rs&FlutterTextInputPlugin.mm):- Why a hidden
UITextField/UITextViewfails: A hidden native text field has its own internal TextKit layout and gesture recognizers; its selection handles, loupe magnifier, Scribble (Apple Pencil), and floating trackpad cursor (holding Spacebar on iOS keyboard) cannot match custom-rendered GPU text lines. - How GPUI and Flutter solve iOS
UITextInputdirectly:- Create a dedicated
UIViewsubclass (GPUITextInputViewingpui_ios/src/ios/text_input.rs:197-318,FlutterTextInputViewinFlutterTextInputPlugin.mm:400-1100) that conforms toUITextInputandUIKeyInput. - Attach a
UITextInteraction::editableInteraction()(text_input.rs:285-295) andUIEditMenuInteractionso UIKit renders the native iOS selection handles, double-tap/long-press loupe, floating keyboard trackpad cursor (beginFloatingCursorAtPoint:/updateFloatingCursorAtPoint:/endFloatingCursor), Scribble, and Cut/Copy/Paste/Autofill callout bar directly over the GPU canvas using geometry returned byfirstRectForRange:,caretRectForPosition:, andselectionRectsForRange:! - Critical anti-reentrancy trick (
gpui_ios/src/ios/text_input.rs:212-238, 1080-1145): Calling[inputDelegate textWillChange:]/[inputDelegate selectionDidChange:]synchronously inside a UIKit callback causes UIKit'sUITextInteractionand autocorrect engine to re-enterUITextInputmethods with stale state. GPUI sets anin_input_callback: BOOLivar and schedules a single coalescedreconcileTextInputviadispatch_async_f(dispatch_get_main_queue(), ...)to notifyinputDelegate(selectionWillChange/selectionDidChange/textWillChange/textDidChange) only when the model state actually diverged from what UIKit already knows. - Flutter's iOS 17+
UITextInteractionworkaround (FlutterTextInputPlugin.mm:260-285): On iOS 17+,UITextInteractionrequires an view in the responder chain when keyboard dictation / trackpad mode activates; keepingGPUITextInputViewin the view hierarchy (with zero visual sublayers) satisfies UIKit's responder checks.
- Create a dedicated
- Why a hidden
- Web IME in 2026: Hidden Sliding-Window
<textarea>+EditContext(gpui_web/src/ime_mirror.rs:1-450):- State of
EditContextin 2026: W3CEditContextis shipping in Chromium/Edge (Chrome 121+), giving directtextupdate,characterboundsupdate, andtextformatupdate(Japanese clause underline thickness/style) without DOM mutation side-effects. However, Safari (WebKit) and Firefox still lack completeEditContextsupport on mobile/desktop in 2026. - Why GPUI's
ImeMirror(gpui_web/src/ime_mirror.rs:1-130) works everywhere: Instead of mirroring an entire 100 KB document into a hidden<textarea>(which freezes mobile Safari),ImeMirrormirrors only a sliding window ofCONTEXT_CHARS = 512characters before and after the selection (ime_mirror.rs:23), trackswindow_start_utf16andcomposition_start_utf16, and positions the1pxtransparent<textarea>directly at the caret'sbounds_for_range(ime_mirror.rs:412-448) so the OS candidate popup and macOS emoji picker (Ctrl+Cmd+Space) anchor to the exact caret pixel.
- State of
- Windows Clause Underline Attributes (
gpui_windows/src/events.rs:713-785, 1738-1760):- Japanese and Chinese IMEs on Windows split an active composition into multiple clauses, where one clause is the active conversion target (
ATTR_TARGET_CONVERTED/ATTR_TARGET_NOTCONVERTED, rendered with a thick or highlighted underline) and sibling clauses areATTR_CONVERTED(thin/dotted underline). QueryingImmGetCompositionStringW(ctx, GCS_COMPATTR, ...)alongsideGCS_CURSORPOSis required so users can see which clause Left/Right arrow keys are reconverting.
- Japanese and Chinese IMEs on Windows split an active composition into multiple clauses, where one clause is the active conversion target (
- Linux Wayland
zwp_text_input_v3Serial & Vim-Mode Quirks (gpui_linux/src/linux/wayland/client.rs:2278-2354):- Wayland
zwp_text_input_v3sendsPreeditStringandCommitStringas pending state followed byEvent::Done { serial }. IfDonearrives withime_pre_edit == Nonewhile previously composing, the client must clear marked text (client.rs:2346-2350). - Also note
client.rs:2306-2320: IBus intercepts single ASCII keys likeaorband sends them asCommitString("a")instead ofwl_keyboard::Key, which breaks modal keybindings unless single-byte ASCII commits when not composing are routed throughKeyDown.
- Wayland
6. Accessibility (a11y) & Agent Inspection
6.1 AccessKit in 2026 (accesskit v0.24+)
Inspection of accesskit/ confirms AccessKit now ships first-party platform adapters across all five native targets:
- macOS (
accesskit_macos): Mapsaccesskit::NodetoNSAccessibilityElementsubclasses (accesskit/adapters/macos/src/node.rs:36-210), postingNSAccessibilityFocusedUIElementChangedNotification,NSAccessibilityValueChangedNotification, andNSAccessibilityLayoutChangedNotification. - iOS (
accesskit_ios): Implemented inaccesskit/adapters/ios/src/node.rs:1-515(v0.4.0), mappingaccesskit::NodetoUIAccessibilityElementwithUIAccessibilityTraits(Button,Header,Adjustable,UpdatesFrequently,Selected,NotEnabled),accessibilityFrame(converted viaUIAccessibilityConvertFrameToScreenCoordinates),accessibilityActivate,accessibilityIncrement/Decrement, andaccessibilityScroll:. - Android (
accesskit_android): Implemented inaccesskit/adapters/android/(v0.6.0), bridging to Android'sAccessibilityNodeProvider(AccessibilityNodeInfovirtual view hierarchy) for TalkBack. - Windows (
accesskit_windows): Implements UI Automation (IRawElementProviderSimple,ITextProvider,IValueProvider,IScrollItemProvider) for Narrator, NVDA, and JAWS. - Linux (
accesskit_unix): Implements AT-SPI2 over D-Bus (zbus) for Orca.
6.2 Roles, Actions, Live Regions, Focus, and Text Navigation
- Core primitives (
accesskit/accesskit/src/lib.rs):NodeId(NonZeroU64): Stable 64-bit identifier per semantic node.Role(lib.rs:62-284): 180+ WAI-ARIA / native roles (Button,TextInput,MultilineTextInput,Switch,Slider,List,ListItem,Dialog,Tab,TabPanel,ScrollView,TextRun, etc.).Action(lib.rs:289-350):Click,Focus,Blur,Increment,Decrement,ReplaceSelectedText,SetValue,SetTextSelection,ScrollIntoView,ScrollToPoint,SetScrollOffset,Expand,Collapse,ShowContextMenu,CustomAction.Live(lib.rs:584):Off,Polite,Assertive(maps toUIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, ...)on iOS andNSAccessibilityAnnouncementRequestedNotificationon macOS).- Character-level text navigation (
Role::TextRun): For multi-line text inputs and selectable text, AccessKit represents each wrapped visual line as a childRole::TextRunnode carryingcharacter_lengths: Box<[u8]>,character_positions: Box<[f32]>,character_widths: Box<[f32]>, andword_starts: Box<[u8]>. AccessKit transforms this directly into macOSaccessibilityFrameForRange:, WindowsITextRangeProvider, and iOS text selection navigation without platform-specific text glue!
6.3 How Flutter Maps SemanticsNode and What iOS VoiceOver Needs
- In Flutter (
flutter/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h&SemanticsObject.mm), everySemanticsNodebecomes aSemanticsObject : UIAccessibilityElement(orSemanticsObjectContainerfor children). - Critical iOS VoiceOver requirements that custom GPU frameworks miss:
- Two-finger Z-scrub ("Escape" gesture): iOS VoiceOver users scrub a "Z" with two fingers to dismiss modals, pop navigation stacks, or close sheets.
accesskit_ios(accesskit/adapters/ios/src/node.rs) and Rune's root container must implementaccessibilityPerformEscapeand map it to a dismiss/back action on the active modal or navigation route. - Modal sibling masking (
accessibilityViewIsModal): When a dialog, sheet, or popover is open, settingNode::set_modal(true)(which maps toaccessibilityViewIsModal = YESon iOS) prevents VoiceOver swipe navigation from cycling through background views behind the scrim. - Scroll-on-swipe (
accessibilityScroll:&Action::ScrollIntoView): When VoiceOver swipes past the last visible row of a virtualized list, the list must keep a 1-screen buffer of offscreen semantic nodes above and below the viewport and handleAction::ScrollIntoView+accessibilityScroll:by advancing the virtual scroll offset and postingUIAccessibilityLayoutChangedNotification. - Rotor Custom Actions (
UIAccessibilityCustomAction): Swipe actions on list rows (e.g., Archive, Delete, Pin) must register asCustomActionon the row'saccesskit::Nodeso VoiceOver users can trigger them via the vertical swipe rotor.
- Two-finger Z-scrub ("Escape" gesture): iOS VoiceOver users scrub a "Z" with two fingers to dismiss modals, pop navigation stacks, or close sheets.
6.4 Should the Accessibility Tree Double as the Agent-Inspector Tree?
Yes — unequivocally.
- Kit's existing automation tools (
cua-driver, macOS Accessibility inspector, agent proof scripts) already operate by snapshotting the accessibility tree, binding stable element tokens, reading bounds/labels/values, and invoking semantic actions (Click,SetValue,ScrollIntoView). - By making
accesskit::TreeUpdatea first-class frame output (built incrementally for dirty subtrees or serialized on demand over a local Unix socket / WebSocket / MCP debug endpoint even when OS screen readers are inactive), Rune gets:- Zero-cost agent drivability on every platform (including headless Linux CI, iOS simulators, Android emulators, and Web) via one JSON/binary
TreeUpdateschema. - Built-in a11y enforcement: If an AI agent cannot see or click a button in an agent proof script, a blind VoiceOver user cannot use it either.
- Lightweight extension: Add an optional side-table
InspectorMetadatakeyed byaccesskit::NodeIdfor agent-only diagnostics (component sourcefile:line, test ID, computed style/spring state, layout constraints) without polluting the OS accessibility bridge.
- Zero-cost agent drivability on every platform (including headless Linux CI, iOS simulators, Android emulators, and Web) via one JSON/binary
7. Layout
7.1 Comparative Evaluation of Layout Models
| Dimension | Taffy (v0.9.x, Flexbox + CSS Grid) |
SwiftUI Proposal / Size Negotiation | Flutter Constraints-Down, Sizes-Up (BoxConstraints) |
Clay (Nic Barker's C micro-layout) | Morphorm (Subform / Vizir units) |
|---|---|---|---|---|---|
| Mental Model | CSS Flexbox & CSS Grid (Style struct) |
Parent proposes (w?, h?) -> Child picks size -> Parent places child |
Parent passes (min_w..max_w, min_h..max_h) -> Child returns Size |
Single-header immediate-mode Sizing::Fixed, Grow, Percent, Fit |
Constraint units (Pixels, Percentage, Stretch, Auto) |
| Passes per Tree | 1–3 passes (Flex intrinsic measure + flex resolve; cached by (known_dimensions, available_space)) |
1–3 proposals (nil ideal, 0 min, .infinity max, concrete width) |
Strictly O(N) single pass (except IntrinsicWidth/Height) |
Strictly 3 linear array passes (BFS/DFS over flat arena) | 2 passes (upward intrinsic, downward stretch) |
| Agent-Writability (LLM accuracy) | Highest: Every LLM has millions of Tailwind/CSS Flexbox/Grid examples in pretraining | High (SwiftUI modifiers), but .frame(maxWidth: .infinity) + layoutPriority traps are common |
Medium-High (Expanded/Flexible inside unconstrained ScrollView panics at runtime!) |
Good for simple rows/columns; no CSS Grid or baseline wrap | Low training corpus; unfamiliar Units::Stretch rules |
| 1M-Row Virtualized List Perf | Must NOT instantiate 1M Taffy nodes; pair with virtual viewport + SumTree height index |
LazyVStack struggles with variable heights (sizeThatFits = 106.4 ms / 500 rows) |
SliverList is fast, requires custom sliver protocol |
Arena-based (~15 µs for visible ~100 nodes), no built-in virtualization | Requires external virtualization |
| Layout Animation (FLIP / Shared Element) | Outputs static Layout { location, size }; requires framework-level previous-rect diffing |
First-class (matchedGeometryEffect, Layout protocol animatable properties) |
Manual (AnimatedSize, Hero overlay widgets) |
Immediate-mode rect output; easy to interpolate (x, y, w, h) per ID |
Static rect output |
7.2 Measured & Cited Benchmark Numbers
- Taffy (
v0.9.2) vs Yoga (v3.2.1) on Apple M1 Pro (taffy/README.md:94-114, Criterion benchmarks):- 1,000 nodes (deep hierarchy): Taffy 1.60 ms vs Yoga 1.50 ms (~1.6 µs/node).
- 10,000 nodes (deep hierarchy): Taffy 17.5 ms vs Yoga 16.2 ms.
- 10,000 nodes (super-deep 12-level hierarchy): Taffy 24.6 ms vs Yoga 36.2 ms (Taffy is 32% faster due to 9-slot
Cacheintaffy/src/tree/cache.rsavoiding exponential re-measurement). - 100,000 nodes (wide 2-level hierarchy): Taffy 98.9 ms vs Yoga 191.5 ms (Taffy is 48% faster).
- Twitter feed benchmark (
yoga/taffyreal-world cards):- 1,500 nodes: Taffy 626 µs vs Yoga 950 µs (1.52x faster).
- 15,000 nodes: Taffy 6.40 ms vs Yoga 11.17 ms (1.75x faster).
- 100,000 nodes: Taffy 59.17 ms vs Yoga 84.42 ms (1.43x faster).
- GPUI's Taffy Integration (
zed/crates/gpui/src/taffy.rs:1-315):- GPUI wraps
TaffyTree<NodeContext>inTaffyLayoutEngine, usingFxHashMap<GlobalElementId, NodeId>and a 2-frame mark-and-sweep (computed_layouts: FxHashSet<NodeId>) so unchanged subtrees keep their Taffy nodes and measurement cache across frames instead of rebuilding the Taffy arena from scratch each frame.
- GPUI wraps
- Text Measurement Inside Layout (a private iOS layout benchmark):
- In any real UI, 80–90% of layout wall-clock time is spent inside the leaf
measure_function(text shaping & line wrapping), not in the Flexbox solver itself. - Measuring 500 chat paragraphs on iOS:
- SwiftUI
sizeThatFits: 106.44 ms (212.88 µs/item) — blows nine 120 Hz frames (8.33 ms budget). - Cold CoreText
CTFramesetter: 17.75 ms (35.51 µs/item). - Reused
CTFramesetterheight: 2.60 ms (5.19 µs/item). - Pre-computed width-break table (
Pretext): 0.23 ms (0.45 µs/item).
- SwiftUI
- In any real UI, 80–90% of layout wall-clock time is spent inside the leaf
7.3 Solving the 3 Hard Layout Cases in Rune
- Agent-Writability:
- Expose Tailwind/Flexbox/Grid-aligned builder methods backed by
taffy(flex(),flex_col(),items_center(),justify_between(),gap(px(8.)),grid_cols(3)) plus ergonomic SwiftUI-style shorthand (hstack(),vstack(),zstack(),spacer()) that compile down to the exact sametaffy::Style. Agents never hit Flutter's dreaded "RenderFlex children have non-zero flex but incoming height constraints are unbounded" crash because Taffy gracefully resolvesflex-growinside auto-sized containers to content size.
- Expose Tailwind/Flexbox/Grid-aligned builder methods backed by
- 1M-Row Variable-Height Virtualized Lists:
- Never insert offscreen rows into
TaffyTree. - Store the 1M-row list state in a
SumTree<ListItemSummary>(zed/crates/sum_tree/src/sum_tree.rs) where each item summary stores(count: usize, height: f32, is_measured: bool):- Unmeasured items initialize with a fast estimated height (or
LineLayoutCacheunwrapped width / container wrap width estimate). - Mapping a scroll pixel offset
y \in [0, 50,000,000]to the first visible row index is aO(\log N)SumTreeseek (~200 nanoseconds for 1M items). - Only the visible viewport rows + overscan buffer (~20–40 rows) are laid out via
Taffyeach frame (< 0.15 ms). When a row's measured height differs from its estimate while scrolling upward, anchor scroll position relative to the first visible item's top edge so the viewport never jumps.
- Unmeasured items initialize with a fast estimated height (or
- Never insert offscreen rows into
- Layout Animation (Spring-Driven Bounds & Shared-Element
layout_id):- Why layout animation is painful in raw Flexbox: Taffy outputs discrete
(location, size)rectangles per frame. - Rune's solution: Attach an optional
.layout_id(id)/.animate_layout(Spring)to any element. AfterTaffycomputes the target layout rectR_{\text{target}} = (x, y, w, h)in window space, Rune's layout-animation pass comparesR_{\text{target}}against the previous frame's rendered rectR_{\text{prev}}for thatElementId:- Position delta (
\Delta x, \Delta y): Drive a 2D spring offset on the element's GPU transform matrix (zero re-layout cost!). - Size delta (
\Delta w, \Delta h): Drive a 2D spring on the element's rendered clip/background bounds while keeping text children anchored (or usingOverflow::FadeMask) so text never re-wraps on every intermediate frame of a container resize spring!
- Position delta (
- Why layout animation is painful in raw Flexbox: Taffy outputs discrete
8. What to Steal / What to Avoid
What to Steal
- Kit's GPUI fork (
kitlangton/gpui) 5-level Luminance Glyph Dilation (kitlangton/gpui/src/platform/mac/text_system.rs:42-81, 470-564, commit2582af8ad0): Quantize text foreground luminance into 5 buckets (0..=4), pad glyph bounds by1px, and rasterize withAppleFontSmoothing/ stem darkening scaled to that luminance so light-on-dark and dark-on-light text have optically matched weight. - GPUI's Two-Tier
LineLayoutCache(zed/crates/gpui/src/text_system/line_layout.rs:523-698): Separate cached unwrappedLineLayout(shaping) fromWrappedLineLayout(wrap boundaries) with two-frame epoch swapping and index-rangereuse_layouts. Resizing a window or split pane only recomputes line breaks over cached glyph advances, never re-running HarfRust/CoreText shaping. - Zed's
SumTree(zed/crates/sum_tree/src/sum_tree.rs): Use one battle-tested concurrent B+ tree for both text ropes (simultaneous UTF-8, UTF-16, line/col, and soft-wrap coordinates inO(\log N)) and 1M-row virtualized list height indexing. - Parley
v0.12.0(parley+fontique+harfrust+skrifa+icu4x): Use Parley's shaping/bidi/segmentation pipeline (parley/parley/src/shape.rs,layout.rs,cursor.rs) for UAX #9 bidi reordering, UAX #14 line breaking,InlineBoxlayout, andAffinity-aware cursor/selection geometry. - Vello
glifo'sCOLRv1+sbix+skrifaGlyph Extractor (vello/glifo/src/glyph.rs:289-465,colr.rs): Stealglifo's priority waterfall (COLRv0/v1vector paint trees ->sbix/CBDTPNG bitmaps ->skrifahinted outlines) and size-adaptive subpixel quantization (SubpixelAxis::Fourat body sizes,Oneat large sizes). - GPUI iOS's
GPUITextInputView+ DeferredreconcileTextInput(zed/crates/gpui_ios/src/ios/text_input.rs:197-318, 1080-1145) & Flutter'sUIEditMenuInteraction/ Floating Cursor (FlutterTextInputPlugin.mm:400-950): DirectUITextInputconformance withUITextInteractionand coalesced main-queue delegate reconciliation gives native iOS selection handles, loupe, Scribble, Dictation, and Spacebar trackpad cursor with zero reentrancy bugs. - GPUI Web's 512-Char Sliding-Window
ImeMirror(zed/crates/gpui_web/src/ime_mirror.rs:1-130, 412-448): Bound hidden<textarea>synchronization to\pm 512characters around the selection and position it at the exact caret rect, adding ChromiumEditContextas a fast path when detected. - AccessKit (
v0.24+) Across All 5 Platforms (accesskit/adapters/{macos,ios,android,windows,unix}): Emit oneaccesskit::TreeUpdatethat simultaneously powers VoiceOver (macOS/iOS), TalkBack (Android), UIA (Windows), AT-SPI (Linux), and Rune's AI agent inspector.
What to Avoid
- Avoid absorbing continuous spring scale transforms into the glyph atlas cache key (
vello/glifo/src/glyph.rs:1702-1731): Hashingdraw_font_size.to_bits()during a 120 Hz scale animation rasterizes 60+ transient font sizes per glyph, thrashing the atlas and causing stem-hinting jitter. - Avoid ignoring the
Selargument in macOSdoCommandBySelector:(zed/crates/gpui_macos/src/window.rs:3515): Dropping the Cocoa selector breaks custom~/Library/KeyBindings/DefaultKeyBinding.dictbindings and standard Cocoa text movement/kill-ring commands. - Avoid SDF / MSDF for body UI text (
10–16pt): MSDF rounds or spikes complex CJK/symbol corners, lacks stem hinting, and has slow CPU generation for dynamic Unicode fallback. - Avoid subpixel LCD (
RGB) glyph atlases: Incompatible with layer opacity, rotation, scale springs, OLED subpixel layouts, and modern macOS/mobile compositors. - Avoid hidden native
UITextField/NSTextViewoverlays for mobile/desktop IME: They desynchronize selection handles, break custom line heights/inline pills, and fight custom scroll physics. - Avoid per-OS text shapers as the sole layout engine: Relying exclusively on CoreText on Apple and DirectWrite on Windows causes cross-platform line-wrap differences and
CFAttributedStringallocation overhead (17.8 ms / 500 paragraphs cold vs < 1 ms cachedharfrust+LineLayoutCache). - Avoid putting offscreen virtualized list items into
TaffyTreeor re-running text shaping during width animations: UseSumTreeheight prefix-sums for offscreen rows andOverflow::FadeMaskor cached unwrapped glyph advances during animated width transitions.
9. Decisive Recommendations for Rune
9.1 Architectural Decisions & Rejected Alternatives
| Sub-Area | Rune Decision | Rejected Alternatives & Why |
|---|---|---|
| 1. Text Shaping & Fonts | harfrust (0.14) + skrifa (0.42) + fontique (0.8), with a thin platform bridge on Apple to read .AppleSystemUIFont (SF Pro) trak optical tracking tables. |
Rejected rustybuzz + swash: swash is unmaintained; rustybuzz is 10–15% slower and duplicates ttf-parser tables.Rejected CoreText/DirectWrite-only shaping: Allocates OS objects per run and produces divergent line wraps across platforms. |
| 2. Text Layout | parley (0.12) wrapped in GPUI's two-tier LineLayoutCache (unwrapped shaped runs separated from wrapped line boundaries) + first-class Overflow::FadeMask shader clip alongside Overflow::Ellipsis. |
Rejected cosmic-text: Tied to rustybuzz/swash, lacks InlineBox layout.Rejected naive Pretext whitespace width tables: 29% height mismatch on hyphenated/kerned prose (opencode-ios-pretext-layout); caching exact LineLayout glyph advances achieves the same sub-millisecond resize speed with 0% drift. |
| 3. Glyph Rendering | Two-tier hybrid: • Tier 1 (UI Text <= 28pt): Grayscale R8Unorm (RGBA8 for COLRv1/sbix emoji) shelf-packed atlas with skrifa hinting, 4x X-subpixel phases, and 5-level luminance glyph dilation (kitlangton/gpui).• Tier 2 (Animated / Hero Text): Transform-invariant linear-metrics octave sampling for scaled UI containers, and direct GPU vector paths ( skrifa outlines -> Vello/Slug) for hero/per-character animated text (> 28pt or .textRenderMode(.vector)). |
Rejected SDF/MSDF: Artifacts on CJK and 11–14pt UI text.Rejected LCD subpixel AA: Breaks transparency and transforms. Rejected per-frame draw_font_size atlas rasterization (glifo default): Thrashes atlas on spring scales. |
| 4. Text Editing | Single unified TextBuffer built on Zed's SumTree + Rope, supporting both <Input> and multi-MB <Editor>, UAX #29 grapheme/word movement (icu_segmenter), Affinity-aware bidi carets, 300 ms undo coalescing, and macOS DefaultKeyBinding.dict selector dispatch. |
Rejected separate String for <Input> and ropey for <Editor>: Maintaining two cursor/IME/UTF-16/undo stacks doubles surface area for surrogate-pair and IME bugs. |
| 5. Platform IME | Direct native protocols per OS: NSTextInputClient (macOS), UITextInput + UITextInteraction + deferred reconcileTextInput (iOS), InputConnection + CursorAnchorInfo (Android), ImmGetCompositionStringW/TSF (Windows), zwp_text_input_v3 (Wayland), and 512-char sliding-window <textarea> + EditContext (Web). |
Rejected hidden UITextField/NSTextField: Breaks native iOS loupe/handles/Scribble alignment on custom GPU text.Rejected EditContext-only on Web: Not supported on Safari/iOS WebKit or Firefox in 2026. |
| 6. Accessibility & Agent Tree | accesskit (v0.24+) across all 5 native platforms, with the frame's accesskit::TreeUpdate + InspectorMetadata exposed directly as Rune's AI Agent Inspector & Automation Tree. |
Rejected custom per-OS accessibility bridges: Thousands of lines of duplicated ObjC/JNI/COM glue. Rejected separate DOM/inspector tree for agents: Diverges from real screen-reader semantics. |
| 7. Layout | taffy (0.9.x, incremental retained tree) + SumTree prefix-sum height virtualizer for lists + built-in FLIP/Spring layout-rect interpolation. |
Rejected Flutter BoxConstraints-only: Poor LLM ergonomics (Expanded in ScrollView runtime crashes) and lacks CSS Grid.Rejected Clay / Morphorm: Lack CSS Grid and deep LLM pretraining familiarity. |
9.2 Recommended Rust Crate Dependencies
[dependencies]
# Text Shaping, Fonts, Bidi & Segmentation
harfrust = "0.14"
skrifa = { version = "0.42", features = ["std", "autohint_shaping"] }
read-fonts = "0.37"
fontique = "0.8"
parley = "0.12"
icu_segmenter = "2.0"
icu_properties = "2.0"
# Buffer & Virtualized List Indexing
sum_tree = { path = "crates/sum_tree" } # Forked/extracted from zed/crates/sum_tree
rope = { path = "crates/rope" } # Forked/extracted from zed/crates/rope
# Layout
taffy = { version = "0.9", features = ["flexbox", "grid", "taffy_tree"] }
etagere = "0.2" # Shelf-packing allocator for glyph & emoji atlases
# Accessibility (Core + Platform Adapters)
accesskit = "0.24"
[target.'cfg(target_os = "macos")'.dependencies]
accesskit_macos = "0.24"
[target.'cfg(target_os = "ios")'.dependencies]
accesskit_ios = "0.4"
[target.'cfg(target_os = "windows")'.dependencies]
accesskit_windows = "0.31"
[target.'cfg(target_os = "linux")'.dependencies]
accesskit_unix = "0.20"
[target.'cfg(target_os = "android")'.dependencies]
accesskit_android = "0.6"
9.3 Top Risks Ranked
- Risk #1 (High): iOS
UITextInput+UITextInteractionedge cases across iOS 17/18/19 (Scribble, Floating Trackpad Cursor, Autofill, Dictation, Hardware Keyboard).- Why: UIKit's
UITextInteractionmakes undocumented synchronous re-entrant calls intoUITextInputduring autocorrect and trackpad gestures. - Mitigation: Port
GPUITextInputView(zed/crates/gpui_ios/src/ios/text_input.rs) and its deferredreconcileTextInputstate machine verbatim, augmented with Flutter'sbeginFloatingCursorAtPoint:(FlutterTextInputPlugin.mm:780-845), and test on real iOS Simulator viafieldwork-prove.
- Why: UIKit's
- Risk #2 (High): Cross-platform stem weight & Apple
.AppleSystemUIFont(SF Pro) optical fidelity when moving from CoreText toharfrust+skrifa.- Why: Users immediately notice if macOS/iOS text looks 5% thinner, wider, or differently tracked than native SwiftUI/AppKit.
- Mitigation: Apply
SF Protraktable optical tracking inharfruston Apple platforms, and support both CoreGraphicsrasterize_glyph(with 5-level luminance dilation fromkitlangton/gpui) on Apple andskrifa+ stem-darkening dilation on Windows/Linux/Android/Web.
- Risk #3 (Medium-High): Animated text jitter and re-wrap stutters during 120 Hz spring layout transitions.
- Why: Naive layout springs re-wrap text at every intermediate width and re-snap glyphs to device pixel grids, causing visible 1px crawling and line-reflow pops.
- Mitigation: Enforce two invariants in the renderer: (a) during an active transform spring, disable integer pixel-grid snapping and lock the glyph atlas lookup to unhinted linear-metric outlines at the target octave scale; (b) during animated width transitions, freeze wrap width to the target width (or use
Overflow::FadeMask) unless explicitly opted into live reflow.
- Risk #4 (Medium): Virtualized list scroll-anchor jumping with dynamic streaming markdown/chat rows.
- Why: When unmeasured items above the viewport resolve to a different height than estimated, naive scroll-top offsets jump visibly.
- Mitigation: Anchor the scroll state to
(anchor_item_id, pixel_offset_within_item)in theSumTree<ListItemSummary>rather than a raw globalscroll_toppixel float.
- Risk #5 (Low-Medium): AccessKit iOS (
accesskit_ios) maturity for complex custom gestures and virtualized lists.- Why:
accesskit_ios(v0.4.0) is the newest AccessKit adapter and requires host cooperation foraccessibilityScroll:and offscreen buffer nodes. - Mitigation: Keep a 1-viewport semantic overscan buffer in virtualized lists and wire
Action::ScrollIntoView+accessibilityPerformEscapedirectly into Rune's scroll and navigation primitives.
- Why:
10. Open Questions (Requiring Prototype or Benchmark)
skrifa+ CPU/GPU stem darkening vs CoreGraphicsCGContextglyph rasterization on macOS/iOS: Canskrifa(Target::Smoothwith custom 5-level luminance dilation in our shader/outline dilator) match CoreGraphicsCTFontDrawGlyphs+AppleFontSmoothingpixel-for-pixel onSF Proat11–15pton 2x Retina, allowing us to dropCGContextglyph rasterization on Apple entirely, or should we keepCGContextrasterization on Apple as anAppleGlyphRasterizerbackend? (Needs a side-by-side pixel-diff prototype at 5 luminance levels.)- Hero vector text threshold (
28ptvs36pt) and GPU cost on mobile: At what exact point size does rendering unhintedskrifaoutlines directly through the Vello/Slug GPU path pipeline match or beat the glyph atlas in frame time and memory bandwidth on an iPhone 16 Pro at 120 Hz? (Needs a GPU frame-time benchmark on iOS device.) - Android
InputConnectionbatch edit behavior on Samsung Keyboard vs Gboard: Samsung Keyboard issues aggressivebeginBatchEdit/setComposingRegionsequences across word boundaries that differ from Gboard. (Needs a small Android IME harness test against ourSumTreeUTF-16 offset mapping.)