Bump to 0.2.0: SW/GLES paint parity, shared font resolution, FrameState refactor, docs and packaging fixes
Some checks failed
CI / build + test (push) Has been cancelled
CI / cargo audit (push) Has been cancelled

Rendering parity (software ↔ GLES). The software backend now rounds glyph pen positions and image destinations to the nearest integer pixel, matching what the GLES backend already did; previously it truncated, so text and 1:1 images could land up to half a pixel off between the two backends and the bilinear sample read ~1 px softer than the source. Gradients and shadows are deliberately left unimplemented on the software backend, and the GLES multi-rect `glScissor` clip is left coarse on purpose: making it exact would need stencil bits the EGL config does not carry, or routing the partial-redraw path through the offscreen clip layer, which would break its `fill` / `clear_rects_transparent` scissor semantics. Adds software-backend pixel tests covering the snapping.
Font resolution unification. The system-font candidate chain, `find_font_opt` and `load_default_font_bytes` lived in two copies (`render/helpers` and `gles_render/helpers`) that had already diverged — one resolved through `find_font_opt`, the other inlined the candidate loop — and now live once in `system_fonts`. The two per-backend `OnceLock` default-font caches and `primary_handle` collapse into a single `system_fonts::default_handle`. Module docs and the `font_registry` caller are updated accordingly.
Shared image validation and rect inflation. `draw_image_data`'s dimension check and its one-line warning were byte-duplicated across both backends and are now `render::helpers::validate_rgba_dims`. The six manual symmetric `Rect`-inflate literals in the GLES primitives reuse the existing `Rect::expand`.
FrameState and DrawCtx de-duplication. The eleven `SurfaceState` fields the draw pass owns and threads through `DrawCtx` — `widget_rects`, the cursor / selection maps, the scroll state, `accessible_extras`, `prev_focused` / `prev_hovered` / `prev_pressed` — move into a `FrameState` sub-struct. The per-frame `build_draw_ctx` / `commit_draw_ctx` helpers can then borrow `&mut ss.frame`, disjoint from `ss.canvas` and `ss.pool`, so the four frame paths (software / GLES × full / partial) replace their duplicated `DrawCtx` construction and write-back with a single helper call each. A whole-`SurfaceState` borrow could not express this (partial borrows do not cross function boundaries), which is why the helpers take the sub-struct. `content_dirty` stays on `SurfaceState` — it is an invalidation flag, not frame state — and is reset at the call site.
rich_text tests. Adds the previously-missing `tests.rs` for the `RichText` widget: one hit rect per visual line a link spans (the widget's core invariant), the single-line and no-link cases, preferred-size growth with hard line breaks, and `map_msg` range preservation — all headless against a software `Canvas`, with line counts forced by `\n` so they do not depend on any system font's measured width.
Documentation. Fills the rustdoc gaps on the embedder-facing surface: `core::UiSurface` accessors, the `egl_context` public API, the `GlesCanvas` methods, `theme::typography` and `theme::error`, and the `RichText` / `Text` builders; adds a crate-level "Rendering backends" overview. `CHANGELOG.md` is added (0.2.0 / 0.1.0), and `docs/widgets.md` / `docs/cookbook.md` gain `rich_text`, `external`, and the CPU-draw / path-clip / externally-laid-out-tree recipes. `debian/changelog` gets the 0.2.0-1 entry. Private intra-doc links to `system_fonts` are demoted to code spans so `cargo doc` is warning-free.
Packaging. The `libltk-dev` registry crate shipped a `Cargo.toml` declaring the `lookup` bench while the `Makefile` install copied only `src/`, so Cargo refused to parse the manifest over a missing `benches/lookup.rs`; the install now ships `benches/` as well (the file alone satisfies the parse — criterion is a dev-dependency and is not resolved when the crate is consumed as a library). `Cargo.toml` is bumped to 0.2.0 to match the package version and the `ltk-0.2.0` registry directory.
This commit is contained in:
2026-06-25 12:43:40 +02:00
parent fb3552e9f7
commit d4d7ee742e
56 changed files with 936 additions and 549 deletions

View File

@@ -18,12 +18,23 @@
use crate::types::Length;
/// Frozen px sizes for the typographic scale, largest (`H0`, a display
/// heading) to smallest (`BODY_XS`, fine print). `H0`…`H3` are the heading
/// ramp; `BODY` is running text, with `BODY_S` / `BODY_XS` for secondary and
/// caption text. Each is the px size; for sizes that scale with the surface
/// use the responsive [`h0`]…[`body_xs`] functions instead.
pub const H0: f32 = 50.0;
/// See [`H0`]. Px size of the second-largest heading level.
pub const H1: f32 = 34.0;
/// See [`H0`]. Px size of the third heading level.
pub const H2: f32 = 24.0;
/// See [`H0`]. Px size of the fourth heading level.
pub const H3: f32 = 20.0;
/// See [`H0`]. Px size of running body text.
pub const BODY: f32 = 16.0;
/// See [`H0`]. Px size of small (secondary) body text.
pub const BODY_S: f32 = 14.0;
/// See [`H0`]. Px size of the smallest (caption) text.
pub const BODY_XS: f32 = 12.0;
/// Interlineado (line-height) multiplier recommended by the kit. Apply as
@@ -37,12 +48,24 @@ pub const LINE_HEIGHT: f32 = 1.5;
// portrait (~720 px) headings round down sensibly; on a 4K desktop the upper
// clamp kicks in before display titles get absurd.
/// Responsive counterparts of the px constants: each returns a [`Length`]
/// that scales with the surface's smaller dimension (`vmin`) and is clamped
/// to a sensible px range, so the same level reads correctly from a portrait
/// phone to a 4K desktop. Same hierarchy as the constants — `h0` the largest
/// display heading down to `body_xs` the smallest caption. Largest display
/// heading: scales as 5% of `vmin`, clamped to `32..=80` px.
pub fn h0() -> Length { Length::vmin( 5.0 ).clamp( 32.0, 80.0 ) }
/// See [`h0`]. Second heading level: 3.4% of `vmin`, clamped to `24..=56` px.
pub fn h1() -> Length { Length::vmin( 3.4 ).clamp( 24.0, 56.0 ) }
/// See [`h0`]. Third heading level: 2.4% of `vmin`, clamped to `18..=40` px.
pub fn h2() -> Length { Length::vmin( 2.4 ).clamp( 18.0, 40.0 ) }
/// See [`h0`]. Fourth heading level: 2.0% of `vmin`, clamped to `16..=32` px.
pub fn h3() -> Length { Length::vmin( 2.0 ).clamp( 16.0, 32.0 ) }
/// See [`h0`]. Running body text: 1.6% of `vmin`, clamped to `14..=22` px.
pub fn body() -> Length { Length::vmin( 1.6 ).clamp( 14.0, 22.0 ) }
/// See [`h0`]. Small body text: 1.4% of `vmin`, clamped to `12..=18` px.
pub fn body_s() -> Length { Length::vmin( 1.4 ).clamp( 12.0, 18.0 ) }
/// See [`h0`]. Smallest caption text: 1.2% of `vmin`, clamped to `11..=15` px.
pub fn body_xs() -> Length { Length::vmin( 1.2 ).clamp( 11.0, 15.0 ) }
#[ cfg( test ) ]