Upstream: crates/rune/README.md § High-frequency values at
65f8eb43f710, MIT © Anomaly. Bundled by build-rune-apps; links point at this snapshot or at GitHub at that rev.
High-frequency values
LiveText updates a plain text run without rebuilding the view or moving its
siblings. Reserve a box with a placeholder or an explicit size:
let clock = rune::LiveText::new("00:00");
text("00:00").live_text(&clock).font(TextStyle::new(14.0, 400.0).features("'tnum' 1"));
clock.set("00:01");
The placeholder determines layout even after a view rebuild. Only the changed
run reshapes; overflow clips to that box. Equal strings do not shape or wake a
host. Hidden hosts keep the latest value and sample it on return. Publication
uses a short mutex and can allocate; it is not an audio-callback API. Live text
supports plain single-line labels, including .truncate_fade(), but not rich
spans, wrapping, editors, ellipsis truncation or streaming word reveals.
TextStyle::features("'tnum' 1, 'ss01' 1") enables OpenType features, and
.variations("'wght' 500, 'opsz' 14") selects variation axes. Both use CSS syntax
and participate in the layout cache key. Tokens remain Copy and const-friendly;
these strings have static lifetime. .optical_size(value) accepts a runtime value.
Register extra font bytes in AppSpec::fonts, then select their embedded family
name with TextStyle::new(32.0, 400.0).family(Family::Named("Anton")). The name is a
literal family name, not a CSS list or filename. Named families fall back to the
sans slot when absent or missing a glyph, followed by the existing symbol/script
fallbacks. Family::Sans, Family::Mono, and .mono() keep their existing meaning;
mono rich spans still use the mono slot. Named styles remain Copy and const-friendly
and the family name participates in the layout cache key.
Monospace text (mono rich spans, Family::Mono and Family::SystemMono) turns off liga,
clig and calt, so -> and != stay two characters, and a tab in it advances to the next
4-column stop, counted from the line or the mono span's start. A tab stays one byte, so byte
ranges, carets and copies are unchanged; elsewhere a tab is one space wide.
.family(Family::SystemMono) uses the platform's monospaced UI font without bundling it:
SF Mono on macOS (the face AppKit's monospacedSystemFont returns, matched to within
0.05 pt per glyph at 8 to 34 pt), Cascadia Mono, then Consolas, on Windows, and whatever
fontconfig resolves monospace to on Linux (then DejaVu Sans Mono, Liberation Mono, Noto
Sans Mono). Its files load the first time a text asks for it. Where none is installed it
falls back to the mono slot. SF Mono has no trak table, so it is untracked, as in AppKit;
tracking still adds, and glyphs that fall back to the system font get that font's own
tracking. Mono rich spans keep using the mono slot.
To put the mono slot itself (so Family::Mono, .mono() and mono rich spans) in that
font, name CSS's ui-monospace in it: families: ("Inter", "ui-monospace"). It stands for
the same families as Family::SystemMono, and the rest of the list follows it, so
"ui-monospace, Menlo" falls back to Menlo where none is installed. Inline code then
matches a code block set in Family::SystemMono.
tx.set_font_families(sans, mono) swaps what's behind the slots while the app runs, for a
UI or code font picker; it takes the same lists as AppSpec::families. Every window and
overlay follows on its next frame, and one opened later starts in them. Each drops the layouts it shaped in the old families,
re-runs memoized subtrees, lays out again and draws one frame. rune::text::measure follows
too. A cache of measured sizes outside Rune should key on rune::text::font_epoch(). A family
that isn't installed falls back as it would at launch, and asking for the families the slots
already hold costs nothing.
Optical sizing defaults to each run's point size, including rich spans with a
different size. An explicit opsz variation wins over the default; .optical_size
wins over both. .optical_sizing(OpticalSize::FontDefault) restores Parley's old
selection. The point-size default tracks CoreText more closely in measured SF samples.
Fonts without an opsz axis are unaffected.
.truncate_fade() shrinks a single-line label and fades its trailing 1.5 em edge
only when text overflows (.truncate_fade_width(em) sets another width). It keeps the full string and paints no ellipsis. For
end-aligned labels the overflow fades on the left.
.truncate_middle() cuts like .truncate() but keeps both ends, "…" replacing the
middle (AppKit's NSLineBreakByTruncatingMiddle), for paths and file names;
.truncate_head() keeps the end. Cuts fall between graphemes and refit on resize, and
selecting, copying and --tree keep the whole string.
.max_lines(n) wraps and stops after n lines, "…" ending the last when more would
follow (CSS line-clamp). The element measures at most n lines tall; the cut falls
between graphemes (inside a word too wide for the box too), spans and links keep their
looks up to it, and copying and the accessibility text keep the whole string. Text fields
ignore it.
Native hosts populate cx.system_reduced_motion() at creation and refresh it on
window focus changes. Rune uses it by default; cx.reduced_motion(value) overrides
it for the current commit only. Call it each time the view runs to keep an
override; otherwise the next commit uses the host preference. macOS reads the accessibility preference, Windows reads client
area animation, and Linux reads KDE's duration factor or GNOME's enable-animations
setting when available. The preference lives on Runtime/Cx, so existing
Env { system_dark, scale } literals remain valid. Headless runtimes default to
false; tests can call rt.set_system_reduced_motion(value) and inspect
rt.system_reduced_motion().
A root .on_window_focus(|state: &mut State, focused, tx| ...) receives native
activation/deactivation in order. It applies to regular windows and interactive
overlays, independently of text-field focus. Headless tests inject the same events
with Runtime::window_focus(bool).
Live<T> is a cloneable, thread-safe latest-wins handle (f32, [f32; 2],
[f32; 4], Color). Call set(value) from a producer thread; Rune coalesces a
wake for each visible subscribed window. Equal values and hidden windows do not
wake. Bind with .live_opacity(&level), .live_offset(&cursor),
.live_scale(&scale), .live_fill(&color) or .live_rect(&rect), and colours with
.live_text_color, .live_border, .live_shadow (the first shadow's colour) and
.live_gradient(&top, &bottom). A rebuild keeps what a colour binding last set.
cursor.smooth(Spring::new(0.16, 0.0)) opts a binding into rune-motion smoothing.
Views and layout do not rerun. Rects are presentation [x,y,w,h] in parent points,
so text does not rewrap and siblings do not reflow. See
examples/live-values for background producers,
deterministic snapshots/traces, allocation gates and the rebuild comparison.
The native shell samples after acquiring a drawable. This is still the main-thread
renderer, not a dedicated late-uniform/render-thread path. Live::new requires
lock-free 128-bit atomics on the host CPU. Publication allocates nothing; platform
wake callbacks are not hard-real-time guarantees.
For a countdown, keep a Tween in app state and bind it through a live property:
let bar = rune::Tween::linear(
[0.0, 0.0, 272.0, 4.0], [0.0, 0.0, 0.0, 4.0],
std::time::Duration::from_secs(30),
);
// In the view:
el().size(272.0, 4.0).live_rect(&s.bar)
The track starts on first attachment to a runtime and uses elapsed real time
(virtual time in headless runs). Rebuilds retain progress; replacing the Tween
starts a new track. It needs no app ticks, layout, shaping, or timer wakes.
Hidden windows stop sampling and resume at the elapsed value. At the endpoint
the renderer sleeps. This is a timed value, including under reduced motion;
it does not use the decorative motion spring or jump to the end on settle.
The shared handle retains each runtime's start across unmount/remount (including
virtual-list culling). Replacing the handle, rather than remounting the view,
starts a new countdown.