Bump to 0.2.0: SW/GLES paint parity, shared font resolution, FrameState refactor, docs and packaging fixes
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:
@@ -87,7 +87,7 @@ impl<A: App> AppData<A>
|
||||
// already the natural selection unit, so a double-click does
|
||||
// not need to add a word-bound selection on top.
|
||||
let select_on_focus = matches!(
|
||||
find_handlers( &self.surface( focus ).widget_rects, idx ),
|
||||
find_handlers( &self.surface( focus ).frame.widget_rects, idx ),
|
||||
Some( WidgetHandlers::TextEdit { select_on_focus: true, .. } ),
|
||||
);
|
||||
if select_on_focus { return; }
|
||||
@@ -97,7 +97,7 @@ impl<A: App> AppData<A>
|
||||
None => return,
|
||||
};
|
||||
if value.is_empty() { return; }
|
||||
let cursor_pos = self.surface( focus ).cursor_state.get( &idx ).copied().unwrap_or( 0 );
|
||||
let cursor_pos = self.surface( focus ).frame.cursor_state.get( &idx ).copied().unwrap_or( 0 );
|
||||
let click_byte = {
|
||||
let ss = self.surface( focus );
|
||||
let canvas = match ss.canvas.as_ref() { Some( c ) => c, None => return };
|
||||
@@ -107,8 +107,8 @@ impl<A: App> AppData<A>
|
||||
};
|
||||
let ( start, end ) = word_bounds_at( &value, click_byte );
|
||||
let ss = self.surface_mut( focus );
|
||||
ss.selection_anchor.insert( idx, start );
|
||||
ss.cursor_state.insert( idx, end );
|
||||
ss.frame.selection_anchor.insert( idx, start );
|
||||
ss.frame.cursor_state.insert( idx, end );
|
||||
ss.request_redraw();
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ impl<A: App> AppData<A>
|
||||
// this guard the click-to-position below would collapse the
|
||||
// selection right after `set_focus` produced it.
|
||||
let select_on_focus = matches!(
|
||||
find_handlers( &self.surface( focus ).widget_rects, idx ),
|
||||
find_handlers( &self.surface( focus ).frame.widget_rects, idx ),
|
||||
Some( WidgetHandlers::TextEdit { select_on_focus: true, .. } ),
|
||||
);
|
||||
if select_on_focus { return; }
|
||||
@@ -133,7 +133,7 @@ impl<A: App> AppData<A>
|
||||
Some( v ) => v,
|
||||
None => return,
|
||||
};
|
||||
let cursor_pos = self.surface( focus ).cursor_state.get( &idx ).copied().unwrap_or( 0 );
|
||||
let cursor_pos = self.surface( focus ).frame.cursor_state.get( &idx ).copied().unwrap_or( 0 );
|
||||
let byte_offset =
|
||||
{
|
||||
let ss = self.surface( focus );
|
||||
@@ -143,8 +143,8 @@ impl<A: App> AppData<A>
|
||||
)
|
||||
};
|
||||
let ss = self.surface_mut( focus );
|
||||
ss.cursor_state.insert( idx, byte_offset );
|
||||
ss.selection_anchor.insert( idx, byte_offset );
|
||||
ss.frame.cursor_state.insert( idx, byte_offset );
|
||||
ss.frame.selection_anchor.insert( idx, byte_offset );
|
||||
ss.request_redraw();
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ impl<A: App> AppData<A>
|
||||
// short-form field stays whole-selected even if the user
|
||||
// drags the pointer over the digits.
|
||||
let select_on_focus = matches!(
|
||||
find_handlers( &self.surface( focus ).widget_rects, idx ),
|
||||
find_handlers( &self.surface( focus ).frame.widget_rects, idx ),
|
||||
Some( WidgetHandlers::TextEdit { select_on_focus: true, .. } ),
|
||||
);
|
||||
if select_on_focus { return; }
|
||||
@@ -167,7 +167,7 @@ impl<A: App> AppData<A>
|
||||
Some( v ) => v,
|
||||
None => return,
|
||||
};
|
||||
let cursor_pos = self.surface( focus ).cursor_state.get( &idx ).copied().unwrap_or( 0 );
|
||||
let cursor_pos = self.surface( focus ).frame.cursor_state.get( &idx ).copied().unwrap_or( 0 );
|
||||
let byte_offset =
|
||||
{
|
||||
let ss = self.surface( focus );
|
||||
@@ -177,7 +177,7 @@ impl<A: App> AppData<A>
|
||||
)
|
||||
};
|
||||
let ss = self.surface_mut( focus );
|
||||
ss.cursor_state.insert( idx, byte_offset );
|
||||
ss.frame.cursor_state.insert( idx, byte_offset );
|
||||
ss.request_redraw();
|
||||
}
|
||||
|
||||
@@ -187,8 +187,8 @@ impl<A: App> AppData<A>
|
||||
pub( crate ) fn collapse_selection_if_any( &mut self, focus: SurfaceFocus ) -> bool
|
||||
{
|
||||
let idx = match self.surface( focus ).focused_idx { Some( i ) => i, None => return false };
|
||||
let cursor = self.surface( focus ).cursor_state.get( &idx ).copied();
|
||||
let anchor = self.surface( focus ).selection_anchor.get( &idx ).copied();
|
||||
let cursor = self.surface( focus ).frame.cursor_state.get( &idx ).copied();
|
||||
let anchor = self.surface( focus ).frame.selection_anchor.get( &idx ).copied();
|
||||
let ( c, a ) = match ( cursor, anchor )
|
||||
{
|
||||
( Some( c ), Some( a ) ) if c != a => ( c, a ),
|
||||
@@ -196,7 +196,7 @@ impl<A: App> AppData<A>
|
||||
};
|
||||
let _ = a;
|
||||
let ss = self.surface_mut( focus );
|
||||
ss.selection_anchor.insert( idx, c );
|
||||
ss.frame.selection_anchor.insert( idx, c );
|
||||
ss.request_redraw();
|
||||
true
|
||||
}
|
||||
@@ -207,8 +207,8 @@ impl<A: App> AppData<A>
|
||||
{
|
||||
let ( idx, value ) = match self.focused_text_value( focus ) { Some( v ) => v, None => return };
|
||||
let ss = self.surface_mut( focus );
|
||||
*ss.cursor_state.entry( idx ).or_insert( 0 ) = value.len();
|
||||
*ss.selection_anchor.entry( idx ).or_insert( 0 ) = 0;
|
||||
*ss.frame.cursor_state.entry( idx ).or_insert( 0 ) = value.len();
|
||||
*ss.frame.selection_anchor.entry( idx ).or_insert( 0 ) = 0;
|
||||
ss.request_redraw();
|
||||
}
|
||||
|
||||
@@ -218,9 +218,9 @@ impl<A: App> AppData<A>
|
||||
pub( crate ) fn focused_selection_text( &self, focus: SurfaceFocus ) -> Option<String>
|
||||
{
|
||||
let ( idx, value ) = self.focused_text_value( focus )?;
|
||||
let cursor = self.surface( focus ).cursor_state.get( &idx ).copied()
|
||||
let cursor = self.surface( focus ).frame.cursor_state.get( &idx ).copied()
|
||||
.unwrap_or( value.len() ).min( value.len() );
|
||||
let anchor = self.surface( focus ).selection_anchor.get( &idx ).copied()
|
||||
let anchor = self.surface( focus ).frame.selection_anchor.get( &idx ).copied()
|
||||
.unwrap_or( cursor ).min( value.len() );
|
||||
if anchor == cursor { return None; }
|
||||
let s = cursor.min( anchor );
|
||||
@@ -236,9 +236,9 @@ impl<A: App> AppData<A>
|
||||
pub( crate ) fn delete_selection( &mut self, focus: SurfaceFocus ) -> Option<String>
|
||||
{
|
||||
let ( idx, value ) = self.focused_text_value( focus )?;
|
||||
let cursor = self.surface( focus ).cursor_state.get( &idx ).copied()
|
||||
let cursor = self.surface( focus ).frame.cursor_state.get( &idx ).copied()
|
||||
.unwrap_or( value.len() ).min( value.len() );
|
||||
let anchor = self.surface( focus ).selection_anchor.get( &idx ).copied()
|
||||
let anchor = self.surface( focus ).frame.selection_anchor.get( &idx ).copied()
|
||||
.unwrap_or( cursor ).min( value.len() );
|
||||
if anchor == cursor { return None; }
|
||||
let s = cursor.min( anchor );
|
||||
@@ -249,13 +249,13 @@ impl<A: App> AppData<A>
|
||||
// post-update displayed value via the `usize::MAX` sentinel —
|
||||
// see `handle_text_insert` for the reasoning.
|
||||
let select_on_focus = matches!(
|
||||
find_handlers( &self.surface( focus ).widget_rects, idx ),
|
||||
find_handlers( &self.surface( focus ).frame.widget_rects, idx ),
|
||||
Some( WidgetHandlers::TextEdit { select_on_focus: true, .. } ),
|
||||
);
|
||||
let next_cursor = if select_on_focus { usize::MAX } else { s };
|
||||
let ss = self.surface_mut( focus );
|
||||
*ss.cursor_state.entry( idx ).or_insert( 0 ) = next_cursor;
|
||||
*ss.selection_anchor.entry( idx ).or_insert( 0 ) = next_cursor;
|
||||
*ss.frame.cursor_state.entry( idx ).or_insert( 0 ) = next_cursor;
|
||||
*ss.frame.selection_anchor.entry( idx ).or_insert( 0 ) = next_cursor;
|
||||
ss.pending_text_values.insert( idx, new_value.clone() );
|
||||
ss.request_redraw();
|
||||
Some( new_value )
|
||||
|
||||
Reference in New Issue
Block a user