From 37a649b5103c01f3565cf81dabb48eccb83a6579 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 14 Nov 2026 09:28:52 -0500 Subject: [PATCH 1/4] fix(mobile): the Edit sheet borrows the picked shape, and a streamed layer's features renew the snap (#1902) Follow-up to #2020, from its last review round: - The Edit sheet borrows the picked feature's shape for each look at it instead of cloning it every frame. - The snap cache is keyed on the session's revision and the background reads finished, so a streamed layer's features coming in look for the snap again; tested. --- crates/ui-touch/src/lib.rs | 51 +++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/crates/ui-touch/src/lib.rs b/crates/ui-touch/src/lib.rs index dc8f9a13f9..61144ad890 100644 --- a/crates/ui-touch/src/lib.rs +++ b/crates/ui-touch/src/lib.rs @@ -345,7 +345,8 @@ struct Form { /// Where the cross's place snapped to on the last frame, with snapping on. snap: Option, /// What [`Form::snap`] was found for: it is looked for again only when the cross moved, the - /// map zoomed, the vertex being moved changed or the project did. + /// map zoomed, the vertex being moved changed, the session changed or a background read + /// brought in features. snap_for: Option, /// The height of the window the sheet was last drawn in: when it changes (the soft keyboard /// came or went), the field being typed in is scrolled back into view. @@ -385,13 +386,15 @@ impl Form { } } -/// What the cross's place was snapped for: its place, the vertex being moved, the project's state, -/// the map's resolution and whether snapping was on. +/// What the cross's place was snapped for: its place, the vertex being moved, the session's +/// revision, the background reads finished (a streamed layer's features come in without a change +/// to the session), the map's resolution and whether snapping was on. #[derive(Clone, Copy, Debug, PartialEq)] struct SnapFor { at: Option<(f64, f64)>, moving: Option<(u32, usize, rustgis_ui_egui::rustgis_engine::data::VertexId)>, - state: u64, + revision: u64, + sources: u64, res: f64, on: bool, } @@ -774,7 +777,14 @@ fn capture(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { // on changed, not on every frame. let at = cross_place(app); let map = app.session.map(); - let wants = SnapFor { at, moving, state: app.session.state(), res: map.camera.res, on: map.editing.snapping.enabled }; + let wants = SnapFor { + at, + moving, + revision: app.session.revision, + sources: rustgis_ui_egui::rustgis_engine::map::source::generation(), + res: map.camera.res, + on: map.editing.snapping.enabled, + }; if state.snap_for != Some(wants) { state.snap = at.and_then(|at| edit::snap(app, at, moving)); state.snap_for = Some(wants); @@ -1049,11 +1059,12 @@ fn edit_sheet( } return; }; - let Some(shape) = edit::shape(app, target.id, row) else { + // The shape is borrowed for each look at it, not copied each frame: the buttons change it. + let Some(status) = edit::shape_ref(app, target.id, row).map(|shape| edit::status(target.kind, shape, editing.vertex)) else { state.editing = None; return; }; - ui.label(RichText::new(edit::status(target.kind, &shape, editing.vertex)).size(14.0).color(t.text)); + ui.label(RichText::new(status).size(14.0).color(t.text)); let off = || tl!("Nothing was changed: the cross is off the map. Move the map under it."); if target.kind == GeometryType::Point { if action(ui, t, tl!("Move Point Here"), width, true, true) { @@ -1068,8 +1079,8 @@ fn edit_sheet( let has = editing.vertex.is_some(); if action(ui, t, tl!("Pick Vertex at Cross"), width, !has, true) { let middle = app.map.view_rect.map(|(rect, _)| rect.center()); - match middle.and_then(|at| edit::vertex_near(app, &shape, at)) { - Some(v) => state.editing = Some(editing.picking(Some(v), Some(&shape))), + match middle.and_then(|at| edit::vertex_near(app, edit::shape_ref(app, target.id, row)?, at)) { + Some(v) => state.editing = Some(editing.picking(Some(v), edit::shape_ref(app, target.id, row))), None => app.session.notify(tl!("No vertex is near the cross. Move the map so the cross is on one."), true), } } @@ -1084,14 +1095,15 @@ fn edit_sheet( let at = if act == "delete" { None } else { cross }; if act != "delete" && at.is_none() { app.session.notify(off(), true); - } else if at.is_some_and(|at| edit::doubles(app, &shape, v, act, at)) { + } else if let Some(at) = at + && edit::shape_ref(app, target.id, row).is_some_and(|shape| edit::doubles(app, shape, v, act, at)) + { app.session.notify( tl!("Nothing was changed: the cross is on the vertex next to it, and two in one place make an edge of no length. Move the map."), true, ); } else if let Some(next) = edit::vertex(app, target.id, row, v, act, at) { - let now = edit::shape(app, target.id, row); - state.editing = Some(editing.picking(next, now.as_ref())); + state.editing = Some(editing.picking(next, edit::shape_ref(app, target.id, row))); } } } @@ -1525,6 +1537,21 @@ mod tests { assert!(form(&ctx).calendar.is_some()); } + #[test] + fn the_snap_is_looked_for_again_once_a_background_read_lands() { + let ctx = egui::Context::default(); + let mut app = RustGisApp::with_sample(); + target(&mut app, GeometryType::Polyline); + frame(&mut app, &ctx, Sheet::Capture); + assert!(form(&ctx).snap_for.is_some()); + // A stale snap the cache holds, then features read in the background: it is let go. + let stale = edit::Snapped { lon: 1.0, lat: 2.0, kind: "vertex" }; + set_form(&ctx, Form { snap: Some(stale), ..form(&ctx) }); + rustgis_ui_egui::rustgis_engine::map::source::wake(); + frame(&mut app, &ctx, Sheet::Capture); + assert_ne!(form(&ctx).snap, Some(stale)); + } + #[test] fn a_vertex_put_on_the_one_next_to_it_is_found_and_a_place_apart_is_not() { let ctx = egui::Context::default(); From 87e90db41c38851b3e87ac24d1e3c4a3e87656b4 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 14 Nov 2026 09:58:22 -0500 Subject: [PATCH 2/4] Address review feedback - The snap cache is keyed on the layers' geometry revisions instead of the finished reads: the map view puts a streamed layer's features in place after the sheet has drawn, which bumps the layer's revision but not the read counter. - The test has a control frame that keeps the held snap, then changes a layer's shapes. --- crates/ui-touch/src/lib.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/ui-touch/src/lib.rs b/crates/ui-touch/src/lib.rs index 61144ad890..0f97b56e43 100644 --- a/crates/ui-touch/src/lib.rs +++ b/crates/ui-touch/src/lib.rs @@ -345,8 +345,8 @@ struct Form { /// Where the cross's place snapped to on the last frame, with snapping on. snap: Option, /// What [`Form::snap`] was found for: it is looked for again only when the cross moved, the - /// map zoomed, the vertex being moved changed, the session changed or a background read - /// brought in features. + /// map zoomed, the vertex being moved changed, the session changed or a layer's shapes did + /// (a streamed layer's features put in place). snap_for: Option, /// The height of the window the sheet was last drawn in: when it changes (the soft keyboard /// came or went), the field being typed in is scrolled back into view. @@ -387,14 +387,15 @@ impl Form { } /// What the cross's place was snapped for: its place, the vertex being moved, the session's -/// revision, the background reads finished (a streamed layer's features come in without a change -/// to the session), the map's resolution and whether snapping was on. +/// revision, the layers' geometry revisions summed (a streamed layer's features are put in place +/// by the map view without a change to the session), the map's resolution and whether snapping +/// was on. #[derive(Clone, Copy, Debug, PartialEq)] struct SnapFor { at: Option<(f64, f64)>, moving: Option<(u32, usize, rustgis_ui_egui::rustgis_engine::data::VertexId)>, revision: u64, - sources: u64, + shapes: u64, res: f64, on: bool, } @@ -781,7 +782,7 @@ fn capture(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { at, moving, revision: app.session.revision, - sources: rustgis_ui_egui::rustgis_engine::map::source::generation(), + shapes: map.layers.iter().fold(0u64, |sum, l| sum.wrapping_add(l.geometry_rev)), res: map.camera.res, on: map.editing.snapping.enabled, }; @@ -1538,7 +1539,7 @@ mod tests { } #[test] - fn the_snap_is_looked_for_again_once_a_background_read_lands() { + fn the_snap_is_looked_for_again_once_a_layers_shapes_change() { let ctx = egui::Context::default(); let mut app = RustGisApp::with_sample(); target(&mut app, GeometryType::Polyline); @@ -1547,7 +1548,12 @@ mod tests { // A stale snap the cache holds, then features read in the background: it is let go. let stale = edit::Snapped { lon: 1.0, lat: 2.0, kind: "vertex" }; set_form(&ctx, Form { snap: Some(stale), ..form(&ctx) }); - rustgis_ui_egui::rustgis_engine::map::source::wake(); + frame(&mut app, &ctx, Sheet::Capture); + // Nothing changed since the snap was found: the one held is kept. + assert_eq!(form(&ctx).snap, Some(stale)); + // A layer's shapes put in place, as the map view does with a streamed layer's features. + let id = app.session.map().layers[0].id; + app.session.map_mut().layer_mut(id).unwrap().touch_geometry(); frame(&mut app, &ctx, Sheet::Capture); assert_ne!(form(&ctx).snap, Some(stale)); } From 26b9c99cc10d9338f30d30e77c2c1b4d69eceb0d Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 14 Nov 2026 10:19:52 -0500 Subject: [PATCH 3/4] Address review feedback - When the map view puts a streamed layer's features in place after the Capture sheet looked for the snap, one more frame is asked for, so the snap is looked for again with the cross held still. --- crates/ui-touch/src/lib.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/ui-touch/src/lib.rs b/crates/ui-touch/src/lib.rs index 0f97b56e43..b5bdd43726 100644 --- a/crates/ui-touch/src/lib.rs +++ b/crates/ui-touch/src/lib.rs @@ -116,6 +116,11 @@ pub fn chrome(app: &mut RustGisApp, ui: &mut Ui) { // The shape being drawn, kept while Edit is on but drawn only in Add; the feature // being edited, and where the cross snapped to. let state = form(&ctx); + // A streamed layer's features put in place by the map view this frame, after the + // sheet looked for the snap: one more frame looks again, the cross held still. + if state.snap_for.is_some_and(|f| f.shapes != shapes(app)) { + ctx.request_repaint(); + } if !state.edit_mode { sketch(app, &painter, map.center(), &t, &ctx); } @@ -400,6 +405,11 @@ struct SnapFor { on: bool, } +/// The map's layers' geometry revisions, summed: it moves whenever a layer's shapes change. +fn shapes(app: &RustGisApp) -> u64 { + app.session.map().layers.iter().fold(0u64, |sum, l| sum.wrapping_add(l.geometry_rev)) +} + fn form(ctx: &egui::Context) -> Form { ctx.data(|d| d.get_temp(egui::Id::unique("touch_capture"))).unwrap_or_default() } @@ -778,14 +788,8 @@ fn capture(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { // on changed, not on every frame. let at = cross_place(app); let map = app.session.map(); - let wants = SnapFor { - at, - moving, - revision: app.session.revision, - shapes: map.layers.iter().fold(0u64, |sum, l| sum.wrapping_add(l.geometry_rev)), - res: map.camera.res, - on: map.editing.snapping.enabled, - }; + let wants = + SnapFor { at, moving, revision: app.session.revision, shapes: shapes(app), res: map.camera.res, on: map.editing.snapping.enabled }; if state.snap_for != Some(wants) { state.snap = at.and_then(|at| edit::snap(app, at, moving)); state.snap_for = Some(wants); From 8d6c1ddabcc4ce20624deac3a19defe04725fa3f Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 14 Nov 2026 10:50:02 -0500 Subject: [PATCH 4/4] Address CodeRabbit review feedback - The extra frame for shapes put in place is asked for only while there is a layer to capture into, so a Capture sheet with none doesn't redraw on every frame. --- crates/ui-touch/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-touch/src/lib.rs b/crates/ui-touch/src/lib.rs index b5bdd43726..2ea20eec7e 100644 --- a/crates/ui-touch/src/lib.rs +++ b/crates/ui-touch/src/lib.rs @@ -118,7 +118,8 @@ pub fn chrome(app: &mut RustGisApp, ui: &mut Ui) { let state = form(&ctx); // A streamed layer's features put in place by the map view this frame, after the // sheet looked for the snap: one more frame looks again, the cross held still. - if state.snap_for.is_some_and(|f| f.shapes != shapes(app)) { + // Only while there is a layer to capture into, whose sheet then looks again. + if capture_layer(app, &state).is_some() && state.snap_for.is_some_and(|f| f.shapes != shapes(app)) { ctx.request_repaint(); } if !state.edit_mode {