Mature ltk to host an externally-laid-out Android view tree
Some checks failed
CI / build + test (push) Has been cancelled
CI / cargo audit (push) Has been cancelled

Add the primitives rustdroid needs to project an Android view hierarchy onto an ltk surface, all kept general rather than Android-specific.
Canvas gains arbitrary vector path fill and stroke: `Canvas::fill_path` / `stroke_path` over a new `PathCmd` command list (MoveTo/LineTo/QuadTo/CubicTo/Close in surface coordinates). The software backend rasterises directly with tiny-skia; the GLES backend rasterises into a tiny-skia pixmap and blits it (CPU fallback, no GPU path shader). This is what renders an Android `Path`, a `VectorDrawable`, or a Lottie frame.
`ExternalSource::Cpu` (and the `External::cpu` constructor) adds an immediate-mode CPU drawing closure, invoked once per frame with the canvas and the widget's laid-out rect, working on both the GLES and software backends. It hosts a custom `View.onDraw` straight onto the ltk canvas without a GL texture round-trip, unlike the existing `Texture` source which only renders on GLES.
`Stack::push_placed` appends a child at an exact rect, bypassing alignment and intrinsic sizing. This lets a view tree whose geometry is computed elsewhere — Android's measure/layout pass, which yields an absolute rect per view — be projected onto a Stack in paint order.
New `RichText` widget: wrapped paragraph text carrying a message per clickable link range, with the layout pass emitting one hit rect per link line so taps land on the link rather than the whole paragraph. It is the ltk side of an Android `Spanned` carrying `URLSpan` / `ClickableSpan`.
gesture: only drive the horizontal pager once the axis locks horizontal
`on_move` emitted horizontal swipe progress whenever `swipe_axis != Vertical`, which includes the pre-lock window where `swipe_axis` is still `None` (the first ~8 px of travel). But `horizontal_drag_started` only flips once `dx.abs() > 8`. A vertical gesture that opened with a few pixels of lateral drift — a swipe-up to the launcher, a scroll — therefore emitted a tiny horizontal progress sample, which armed the consumer's pager, then locked vertical without `dx` ever passing 8, so `horizontal_drag_started` stayed false. On release the horizontal branch was skipped, no `on_swipe_horizontal_progress(0.0)` fired, and the pager stayed stuck active — on the crustace homescreen that froze the surface (the main stays motion-only behind stale page subsurfaces) until an unrelated gesture reset it.
Emit horizontal progress only once `swipe_axis == Some(Horizontal)`. Locking onto the horizontal axis already implies `dx.abs() > 8`, so `horizontal_drag_started` is set in the same step, restoring the invariant that a frame which drives the pager always has a matching release event to settle it. The cost is that the first ~8 px of a horizontal drag no longer move the page, which is the same deadband the axis lock already imposes on the vertical panels. Adds `pre_lock_lateral_drift_does_not_drive_horizontal_pager`.
This commit is contained in:
2026-06-12 22:14:02 +02:00
parent df8fcbf757
commit b00cf460bb
21 changed files with 840 additions and 43 deletions

View File

@@ -93,6 +93,12 @@ pub enum ExternalSource
/// allocation (e.g. resize a WPEToplevel on layout change) and
/// translate input coordinates by `rect.origin`.
Texture( Arc<dyn Fn( &glow::Context, Rect ) -> Option<glow::Texture> + Send + Sync> ),
/// Closure invoked once per frame with LTK's [`Canvas`] and the widget's
/// laid-out rect, for immediate-mode CPU drawing (no GL texture). Used to
/// host an Android `View`'s custom `onDraw` straight onto the LTK canvas.
/// Works on both the GLES and software backends.
Cpu( Arc<dyn Fn( &mut Canvas, Rect ) + Send + Sync> ),
}
impl External
@@ -104,6 +110,13 @@ impl External
Self { width, height, source, opacity: 1.0 }
}
/// Build an external widget that paints via an immediate-mode CPU closure
/// reserving `width × height` logical pixels.
pub fn cpu( width: f32, height: f32, draw: impl Fn( &mut Canvas, Rect ) + Send + Sync + 'static ) -> Self
{
Self::new( width, height, ExternalSource::Cpu( Arc::new( draw ) ) )
}
/// Override the opacity multiplier. Default: `1.0`.
pub fn opacity( mut self, opacity: f32 ) -> Self
{
@@ -118,23 +131,23 @@ impl External
pub fn draw( &self, canvas: &mut Canvas, rect: Rect )
{
// SAFETY-ish: this is the only call site of the source closure;
// LTK's draw pass guarantees the GLES context is current and
// the canvas is bound to its FBO. The rect we pass is the
// widget's laid-out rect in physical pixels — the same
// coordinate space pointer events arrive in, so the producer
// can use `rect.origin` to translate input.
// External content only renders against the GLES backend — the
// software backend has no GL texture to sample. Skip silently.
let gl = match canvas
{
Canvas::Software( _ ) => return,
Canvas::Gles( c ) => c.gl.clone(),
};
match &self.source
{
// Immediate CPU drawing works against any backend; the producer
// paints straight into the canvas at `rect`.
ExternalSource::Cpu( draw ) =>
{
draw( canvas, rect );
}
// External GL content only renders against the GLES backend — the
// software backend has no GL texture to sample. Skip silently.
ExternalSource::Texture( get ) =>
{
let gl = match canvas
{
Canvas::Software( _ ) => return,
Canvas::Gles( c ) => c.gl.clone(),
};
if let Some( tex ) = get( &gl, rect )
{
canvas.draw_external_texture( tex, rect, self.opacity );