responsive fluid/physical scaling, widget-API stabilization, and perf guardrails
CI / build + test (push) Has been cancelled
CI / cargo audit (push) Has been cancelled

Responsive scaling. ltk now offers two first-class ways to size a UI so it adapts across screens, chosen per process via `WidgetScaling { Fluid, Physical }` (`set_widget_scaling` / `widget_scaling`, default `Fluid`). Fluid sizing (`Length::fluid( px )`) makes a design pixel a proportion of the surface's smaller side, calibrated against a reference width (`set_fluid_reference` / `fluid_reference`, 412 px default) and bounded by `FLUID_MIN` / `FLUID_MAX`; physical sizing (`Length::dp( px )`) is a constant-physical-size pixel scaled by display density (`set_density` / `density`). `Length` gains `orient( portrait, landscape )` — resolve one value in portrait, another in landscape — plus `widget( px )`, which picks fluid or dp per the active mode. Canvas exposes `geom_px` (geometry, resolved in physical layout space) and `font_px` (font size, bridging logical / physical per mode) so widgets and apps share one resolution path. Note the rename: `set_design_reference` / `design_reference` became `set_fluid_reference` / `fluid_reference`, and `Length::dp` changed meaning — the old surface-proportional behaviour now lives on `Length::fluid`.
Widgets. Every stock widget resolves its default geometry and font through the widget-scaling mode instead of frozen pixels, so a whole UI scales coherently without per-call units. New size builders where they were missing: `button` gains `font_size` / `height`, `text_edit` gains `height` / `font_size_fluid`, `separator` gains `pad_v`, and assorted widgets accept a `Length` where they previously took only `f32`.
Overlays. `OverlaySpec::size` is now `( Length, Length )` instead of `( u32, u32 )`, resolved against the main surface when the overlay is materialized, so overlays can scale with the display; `Length::px( … )` reproduces the old fixed sizing.
API stabilization (toward 1.0). Widget struct fields are now `pub( crate )` — they are configured through builders, not field access — except the value / state types apps genuinely read or construct (`Time`, `Date`, `ComboState`), which stay public. The internal `test_support` helpers move behind a `test-support` Cargo feature (off by default, so third-party builds never see them; ltk's own `make test` enables it). `Separator` drops its `0.0`-means-mode sentinel for `Option<Length>`, so an explicit `pad_v( 0.0 )` is a real flush divider distinct from the mode-following default.
Performance guardrails. Opt-in diagnostics via `LTK_PERF_WARN=1` warn about stuck animations, sustained software-render animation, and low `poll_interval`; software-rendered animation is capped near 30 Hz to spare CPU on machines that fall back off EGL. Apps can override the cap with `App::cap_software_animation`.
Docs and build. The two scaling modes are documented in README, onboarding and architecture, with the earlier gradient / backdrop doc drift cleaned up. The Makefile now ships the `locales/` directory into the packaged crate (fixing i18n keys rendering raw for downstreams), builds the new `responsive` example, and runs tests with `--features test-support`.
This commit is contained in:
2026-07-07 17:40:33 +02:00
parent d4d7ee742e
commit ce893ac776
83 changed files with 1850 additions and 526 deletions
+16 -14
View File
@@ -213,9 +213,14 @@ pub struct OverlaySpec<Message: Clone>
/// Screen edges to anchor to.
pub anchor: Anchor,
/// Desired size `( width, height )` in logical pixels. `0` in either
/// component means "fill available space in that dimension".
pub size: ( u32, u32 ),
/// Desired size `( width, height )`, resolved to logical pixels against
/// the main surface (output) when the overlay is materialized. A
/// [`Length::px`](crate::Length::px) keeps a fixed size; a
/// [`Length::widget`](crate::Length::widget) / `vmin` / `dp` makes the
/// overlay surface scale with the display like any other sized element.
/// A component that resolves to `0` (e.g. `Length::px( 0.0 )`) means
/// "fill available space in that dimension".
pub size: ( crate::types::Length, crate::types::Length ),
/// Exclusive zone in pixels reserved from the anchored edge.
/// `-1` requests focus without reserving space, `0` is the default for
@@ -722,6 +727,14 @@ pub trait App: 'static
/// The event loop will keep requesting redraws at ~60 fps until this returns `false`.
fn is_animating( &self ) -> bool { false }
/// Cap [`Self::is_animating`] redraws to ~30 Hz when the **software**
/// renderer is active. Default `true`: 60 fps software rasterization is a
/// common battery sink on mobile (no GPU offload), and halving it is
/// usually imperceptible for the animations software fallback can afford.
/// The GLES backend is never capped. Return `false` to keep the full
/// display rate on software.
fn cap_software_animation( &self ) -> bool { true }
/// Return `true` when a finger-tracked swipe or an [`Self::is_animating`]
/// slide only repositions the app's input-transparent subsurfaces
/// ([`Self::subsurfaces`]) while the main surface buffer stays unchanged.
@@ -733,17 +746,6 @@ pub trait App: 'static
/// panel over a static main surface.
fn subsurface_motion_only( &self ) -> bool { false }
/// Return `true` while the next frame should swap the expensive
/// Glass passes for cheap fallbacks — currently the
/// `backdrop-filter` blur drops from a 41-tap kernel to a 9-tap
/// kernel, with the snapshot region shrunk to match. The event
/// loop sets this on the renderer right before drawing through an
/// internal low-quality-paint flag.
///
/// Default: matches [`Self::is_animating`], so a settle animation
/// automatically downgrades. Override to include other "in motion"
/// states the runtime cannot observe — e.g. a finger-tracked
/// Background color for the canvas. Override to make the surface
/// transparent or to deviate from the theme. Default: the active
/// theme's `bg` token, so the window matches the rest of the