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:
+22
-18
@@ -40,14 +40,14 @@ pub struct Radio<Msg: Clone>
|
||||
{
|
||||
/// Whether this option is currently selected. Drawn from this field
|
||||
/// every frame.
|
||||
pub selected: bool,
|
||||
pub( crate ) selected: bool,
|
||||
/// Message emitted when the user picks this option. `None` leaves the
|
||||
/// radio inert.
|
||||
pub on_select: Option<Msg>,
|
||||
pub( crate ) on_select: Option<Msg>,
|
||||
/// Optional label drawn to the right of the circle.
|
||||
pub label: Option<String>,
|
||||
pub( crate ) label: Option<String>,
|
||||
/// Optional stable identifier for focus management.
|
||||
pub id: Option<WidgetId>,
|
||||
pub( crate ) id: Option<WidgetId>,
|
||||
}
|
||||
|
||||
impl<Msg: Clone> Radio<Msg>
|
||||
@@ -83,14 +83,15 @@ impl<Msg: Clone> Radio<Msg>
|
||||
|
||||
pub fn preferred_size( &self, max_width: f32, canvas: &Canvas ) -> (f32, f32)
|
||||
{
|
||||
let outer = canvas.geom_px( theme::OUTER_SIZE );
|
||||
let w = if let Some( ref label ) = self.label
|
||||
{
|
||||
let text_w = canvas.measure_text( label, theme::FONT_SIZE );
|
||||
( theme::OUTER_SIZE + theme::GAP + text_w ).min( max_width )
|
||||
let text_w = canvas.measure_text( label, canvas.font_px( theme::FONT_SIZE ) );
|
||||
( outer + canvas.geom_px( theme::GAP ) + text_w ).min( max_width )
|
||||
} else {
|
||||
theme::OUTER_SIZE.min( max_width )
|
||||
outer.min( max_width )
|
||||
};
|
||||
( w, theme::HEIGHT )
|
||||
( w, canvas.geom_px( theme::HEIGHT ) )
|
||||
}
|
||||
|
||||
/// Focus ring on the outer circle extends `FOCUS_W + 2 + FOCUS_W/2 ≈ 6.5 px`
|
||||
@@ -102,28 +103,30 @@ impl<Msg: Clone> Radio<Msg>
|
||||
|
||||
pub fn draw( &self, canvas: &mut Canvas, rect: Rect, focused: bool )
|
||||
{
|
||||
let circle_y = rect.y + ( rect.height - theme::OUTER_SIZE ) / 2.0;
|
||||
let outer_r = theme::OUTER_SIZE / 2.0;
|
||||
let outer_size = canvas.geom_px( theme::OUTER_SIZE );
|
||||
let circle_y = rect.y + ( rect.height - outer_size ) / 2.0;
|
||||
let outer_r = outer_size / 2.0;
|
||||
let outer_rect = Rect
|
||||
{
|
||||
x: rect.x,
|
||||
y: circle_y,
|
||||
width: theme::OUTER_SIZE,
|
||||
height: theme::OUTER_SIZE,
|
||||
width: outer_size,
|
||||
height: outer_size,
|
||||
};
|
||||
|
||||
if self.selected
|
||||
{
|
||||
canvas.fill_rect( outer_rect, theme::selected(), outer_r );
|
||||
let dot_r = theme::DOT_SIZE / 2.0;
|
||||
let dot_size = canvas.geom_px( theme::DOT_SIZE );
|
||||
let dot_r = dot_size / 2.0;
|
||||
let cx = rect.x + outer_r;
|
||||
let cy = circle_y + outer_r;
|
||||
let dot_rect = Rect
|
||||
{
|
||||
x: cx - dot_r,
|
||||
y: cy - dot_r,
|
||||
width: theme::DOT_SIZE,
|
||||
height: theme::DOT_SIZE,
|
||||
width: dot_size,
|
||||
height: dot_size,
|
||||
};
|
||||
canvas.fill_rect( dot_rect, theme::dot_color(), dot_r );
|
||||
} else {
|
||||
@@ -138,9 +141,10 @@ impl<Msg: Clone> Radio<Msg>
|
||||
|
||||
if let Some( ref label ) = self.label
|
||||
{
|
||||
let text_x = rect.x + theme::OUTER_SIZE + theme::GAP;
|
||||
let text_y = rect.y + ( rect.height + theme::FONT_SIZE ) / 2.0 - 2.0;
|
||||
canvas.draw_text( label, text_x, text_y, theme::FONT_SIZE, theme::label_color() );
|
||||
let fs = canvas.font_px( theme::FONT_SIZE );
|
||||
let text_x = rect.x + outer_size + canvas.geom_px( theme::GAP );
|
||||
let text_y = rect.y + ( rect.height + fs ) / 2.0 - 2.0;
|
||||
canvas.draw_text( label, text_x, text_y, fs, theme::label_color() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user