responsive fluid/physical scaling, widget-API stabilization, and perf guardrails
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:
@@ -53,17 +53,17 @@ mod tests;
|
||||
/// ```
|
||||
pub struct Container<Msg: Clone>
|
||||
{
|
||||
pub child: Box<Element<Msg>>,
|
||||
pub( crate ) child: Box<Element<Msg>>,
|
||||
/// Optional background paint — flat colour, linear or radial
|
||||
/// gradient. Constructed via [`Container::background`], which
|
||||
/// accepts anything `Into<Paint>` (a plain [`Color`] gets
|
||||
/// promoted to [`Paint::Solid`] via the trait impl).
|
||||
pub background: Option<Paint>,
|
||||
pub( crate ) background: Option<Paint>,
|
||||
/// Slot id of a themed surface (resolved via
|
||||
/// [`crate::theme::resolve_surface`]). When set, takes precedence
|
||||
/// over `background` and paints the full Glass stack instead of a
|
||||
/// flat colour fill.
|
||||
pub surface: Option<String>,
|
||||
pub( crate ) surface: Option<String>,
|
||||
/// Per-corner radii applied to every painted layer of the
|
||||
/// container chrome — flat fill, themed surface (gradient + outer
|
||||
/// shadows + insets + backdrop blur). Stored as [`Corners`] so
|
||||
@@ -71,33 +71,33 @@ pub struct Container<Msg: Clone>
|
||||
/// panel pinned to the screen bottom, a side panel pinned to the
|
||||
/// left edge, …) without hitting the renderer with an offset
|
||||
/// trick.
|
||||
pub corners: Corners,
|
||||
pub( crate ) corners: Corners,
|
||||
/// Padding on the top edge — gap between the container's top boundary
|
||||
/// and its child. Stored as a [`Length`] so it can scale with the
|
||||
/// viewport via [`Length::dp`] / [`Length::vmin`].
|
||||
pub pad_top: Length,
|
||||
/// viewport via [`Length::fluid`] / [`Length::vmin`].
|
||||
pub( crate ) pad_top: Length,
|
||||
/// Padding on the right edge.
|
||||
pub pad_right: Length,
|
||||
pub( crate ) pad_right: Length,
|
||||
/// Padding on the bottom edge.
|
||||
pub pad_bottom: Length,
|
||||
pub( crate ) pad_bottom: Length,
|
||||
/// Padding on the left edge.
|
||||
pub pad_left: Length,
|
||||
pub opacity: f32,
|
||||
pub( crate ) pad_left: Length,
|
||||
pub( crate ) opacity: f32,
|
||||
/// Optional `( color, width_px )` border stroke painted around the
|
||||
/// container's rounded rectangle, after the fill / surface and
|
||||
/// before the child draws. `None` leaves the chrome flat.
|
||||
pub border: Option<( Color, f32 )>,
|
||||
pub( crate ) border: Option<( Color, f32 )>,
|
||||
/// Optional hard cap on the container's outer width. When the parent
|
||||
/// offers more, the container reports its preferred width as
|
||||
/// `min( offered, max_width )` so it does not stretch to fill.
|
||||
/// Mirrors the same flag on [`Column`](crate::layout::column::Column)
|
||||
/// and [`Row`](crate::layout::row::Row).
|
||||
pub max_width: Option<f32>,
|
||||
pub( crate ) max_width: Option<f32>,
|
||||
/// When true, the contents of this container are announced by
|
||||
/// assistive technologies as a `Live::Polite` region — useful for
|
||||
/// toasts, status banners and OSDs that need to be read on
|
||||
/// appearance even when the user has not navigated to them.
|
||||
pub a11y_live: bool,
|
||||
pub( crate ) a11y_live: bool,
|
||||
}
|
||||
|
||||
impl<Msg: Clone> Container<Msg>
|
||||
|
||||
Reference in New Issue
Block a user