accessibility text scale: global font multiplier synced to the desktop's text-scaling-factor
Some checks failed
CI / build + test (push) Has been cancelled
CI / cargo audit (push) Has been cancelled

New set_text_scale / text_scale process global (clamped [0.5, 3.0]) multiplied into every resolved font size — Canvas::resolve_font for explicit Lengths and the Physical branch of font_px (the Fluid branch routes through resolve_font) — so the whole tree's text follows the accessibility "large text" factor while geometry stays untouched, mirroring GNOME's text-scaling-factor semantics. Unit test covers fonts-scale-geometry-doesn't.
The run loop keeps the factor synced on its own: a watcher thread (event_loop/text_scale.rs) reads org.gnome.desktop.interface text-scaling-factor via gsettings get at startup and streams external changes from gsettings monitor into a calloop channel; on a change the loop stores the factor, invalidates the view caches and repaints main and overlays. Since fonts resolve at paint time nothing else needs rebuilding. Every ltk app tracks the settings slider live with zero app-side wiring, the same way GTK apps follow the key; missing gsettings degrades silently to a fixed 1.0. Embedders driving core::UiSurface (forge) call set_text_scale themselves — the multiplication only runs at widget font resolution, so raw Canvas::draw_text callers keep hand-computed sizes.
architecture.md documents the multiplier in the font-space paragraph and CHANGELOG gains the entry.
This commit is contained in:
2026-08-02 22:50:19 +02:00
parent e343142347
commit d9652dce98
8 changed files with 155 additions and 5 deletions

View File

@@ -710,6 +710,25 @@ pub fn fluid_reference() -> f32
f32::from_bits( FLUID_REFERENCE_BITS.load( Ordering::Relaxed ) )
}
static TEXT_SCALE_BITS: AtomicU32 = AtomicU32::new( 1.0_f32.to_bits() );
/// Set the global text scale multiplier applied to every resolved font
/// size (the accessibility "large text" factor). Clamped to `[0.5, 3.0]`.
/// The run loop keeps it synced to the desktop's
/// `org.gnome.desktop.interface text-scaling-factor` GSettings key and
/// repaints on change, so apps normally never call this themselves;
/// embedders driving [`crate::core::UiSurface`] directly do.
pub fn set_text_scale( s: f32 )
{
TEXT_SCALE_BITS.store( s.clamp( 0.5, 3.0 ).to_bits(), Ordering::Relaxed );
}
/// Current text scale multiplier. Default `1.0`.
pub fn text_scale() -> f32
{
f32::from_bits( TEXT_SCALE_BITS.load( Ordering::Relaxed ) )
}
static DENSITY_BITS: AtomicU32 = AtomicU32::new( 1.0_f32.to_bits() );
/// Set the process-wide pixel density used by [`Length::dp`] (the