From 858201597b0e9737b9af3315fdb308aaa8fcd110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 10:15:41 -0500 Subject: [PATCH 1/8] feat(ui): on a touch screen, tabs and rows reorder only after a long press (#2958) --- crates/ui-egui/src/mapview.rs | 6 +-- crates/ui-egui/src/panes.rs | 93 ++++++++++++++++++++++++++++++++--- crates/ui-egui/src/widgets.rs | 43 ++++++++++++++++ docs/user-guide/workspace.md | 2 +- 4 files changed, 132 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 059524bd34..e20f7f4a7a 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -4856,7 +4856,7 @@ fn view_tab_row(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, follow: bool) -> let mut map_tabs = Vec::with_capacity(names.len()); for (i, n) in names.iter().enumerate() { let tr = next_view_tab(ui, view_tab_w(ui, n)); - let resp = ui.interact(tr, egui::Id::unique(("maptab", i)), Sense::click_and_drag()); + let resp = ui.interact(tr, egui::Id::unique(("maptab", i)), crate::widgets::reorder_sense(ui, true)); // Painted, so named for screen readers (and tests). resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, n)); let dragging = drag_tab(ui, &resp, false, n); @@ -4907,7 +4907,7 @@ fn view_tab_row(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, follow: bool) -> let mut layout_tabs = Vec::with_capacity(layouts.len()); for (i, n) in layouts.iter().enumerate() { let tr = next_view_tab(ui, view_tab_w(ui, n)); - let resp = ui.interact(tr, egui::Id::unique(("layouttab", i)), Sense::click_and_drag()); + let resp = ui.interact(tr, egui::Id::unique(("layouttab", i)), crate::widgets::reorder_sense(ui, true)); resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, n)); let dragging = drag_tab(ui, &resp, true, n); layout_tabs.push(tr); @@ -5010,7 +5010,7 @@ struct DraggedTab { /// Starts dragging the map or layout tab or row `name` when `resp` starts a drag; whether that one /// is being dragged. pub(crate) fn drag_tab(ui: &Ui, resp: &egui::Response, layout: bool, name: &str) -> bool { - if resp.drag_started_by(egui::PointerButton::Primary) { + if crate::widgets::reorder_drag(ui, resp, true) { egui::DragAndDrop::set_payload(ui.ctx(), DraggedTab { layout, name: name.to_string() }); } egui::DragAndDrop::payload::(ui.ctx()).is_some_and(|d| d.layout == layout && d.name == name) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index dce678f84d..dcce023ff3 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -1337,10 +1337,10 @@ fn layer_group_row( let filtering = !q.is_empty(); ui.push_id(("layer_group", group.id), |ui| { let name = row_name(ui, group.name.clone(), semibold(12.5), ui.available_width() - NAME_X - 8.0); - let sense = if reorder { Sense::click_and_drag() } else { Sense::click() }; + let sense = crate::widgets::reorder_sense(ui, reorder); let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), name.row_h), sense); resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, &group.name)); - if reorder && resp.drag_started_by(egui::PointerButton::Primary) { + if crate::widgets::reorder_drag(ui, &resp, reorder) { egui::DragAndDrop::set_payload(ui.ctx(), DraggedLayer(group.id)); } let dragging = egui::DragAndDrop::payload::(ui.ctx()).is_some_and(|d| d.0 == group.id); @@ -1658,12 +1658,12 @@ fn tile_row(app: &mut RustGisApp, ui: &mut Ui, i: usize, moves: [bool; 2], reord shown = format!("{shown} {note}"); } let name = row_name(ui, shown.clone(), regular(12.5), ui.available_width() - NAME_X - 8.0); - let sense = if reorder { Sense::click_and_drag() } else { Sense::click() }; + let sense = crate::widgets::reorder_sense(ui, reorder); let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), name.row_h), sense); // Named for screen readers as a layer's row is. resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, &tile.name)); // Dragged to another place in the drawing order, as a layer's row is. - if reorder && resp.drag_started_by(egui::PointerButton::Primary) { + if crate::widgets::reorder_drag(ui, &resp, reorder) { egui::DragAndDrop::set_payload(ui.ctx(), DraggedTile(i)); } let dragging = egui::DragAndDrop::payload::(ui.ctx()).is_some_and(|d| d.0 == i); @@ -2052,12 +2052,12 @@ fn layer_row(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, scale: f64, reorder: let font = regular(12.5); let room = ui.available_width() - NAME_X - badge.as_ref().map_or(8.0, |(_, w)| w + 18.0); let name = row_name(ui, shown.clone(), font, room); - let sense = if reorder { Sense::click_and_drag() } else { Sense::click() }; + let sense = crate::widgets::reorder_sense(ui, reorder); let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), name.row_h), sense); // The icons and the badge line up with the name's first line. let cy = r.min.y + 13.0; resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, &l.name)); - if reorder && resp.drag_started_by(egui::PointerButton::Primary) { + if crate::widgets::reorder_drag(ui, &resp, reorder) { egui::DragAndDrop::set_payload(ui.ctx(), DraggedLayer(l.id)); } let dragging = egui::DragAndDrop::payload::(ui.ctx()).is_some_and(|d| d.0 == l.id); @@ -2663,7 +2663,7 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { icons::paint(ui.painter(), r, "map", t.icon, t.accent); let active = i == app.session.project.active_map; // Dragged to another place among the maps, as its tab is (#2829). - let resp = ui.selectable_label(active, m).interact(Sense::drag()); + let resp = ui.selectable_label(active, m).interact(crate::widgets::reorder_sense(ui, true)); let dragging = crate::mapview::drag_tab(ui, &resp, false, m); if resp.clicked() { let _ = app.run("map.activate", json!({"name": m})); @@ -2726,7 +2726,7 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { .is_some_and(|l| l.name == *n), n, ) - .interact(Sense::drag()); + .interact(crate::widgets::reorder_sense(ui, true)); let dragging = crate::mapview::drag_tab(ui, &resp, true, n); if resp.clicked() { let _ = app.run("layout.activate", json!({"name": n})); @@ -8512,6 +8512,83 @@ mod tests { h.step(); } + /// A finger on `from` that moves through `to` in steps, as winit reports a touch (touch event + /// and pointer events together), `held` frames before it starts moving and let go at the end. + fn touch_drag(h: &mut egui_kittest::Harness<'_, RustGisApp>, from: egui::Pos2, to: egui::Pos2, held: usize) { + use egui::{Event, Modifiers, PointerButton, TouchDeviceId, TouchId, TouchPhase}; + let touch = |phase, pos| Event::Touch { device_id: TouchDeviceId(1), id: TouchId(1), phase, pos, force: None }; + let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; + h.event(Event::PointerMoved(from)); + h.step(); + h.event(touch(TouchPhase::Start, from)); + h.event(button(from, true)); + h.step(); + for _ in 0..held { + h.step(); + } + for step in 1..=8 { + let pos = from + (to - from) * (step as f32 / 8.0); + h.event(touch(TouchPhase::Move, pos)); + h.event(Event::PointerMoved(pos)); + h.step(); + } + h.event(touch(TouchPhase::End, to)); + h.event(button(to, false)); + h.event(Event::PointerGone); + h.step(); + } + + /// #2958: a swipe of a finger over the layer rows scrolls the list; it does not take the row + /// under the finger to another place, as the mouse does. + #[test] + fn a_swipe_over_the_layers_does_not_reorder_them() { + use egui_kittest::kittest::Queryable; + let app = RustGisApp::with_sample(); + let original: Vec<_> = app.session.map().layers.iter().map(|l| l.id).collect(); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(6); + let from = h.get_by_label("Countries").rect().center(); + let first = h.get_by_label("Cities").rect(); + touch_drag(&mut h, from, pos2(first.center().x, first.min.y + 2.0), 0); + h.run_steps(3); + assert_eq!(h.state().session.map().layers.iter().map(|l| l.id).collect::>(), original); + assert_eq!(h.state().session.undo_depth(), 0); + } + + /// #2958: a finger held on a layer row and then moved takes the row to another place, as the + /// mouse does at once, and the menu the long press opened is gone. + #[test] + fn a_long_press_then_a_move_reorders_a_layer() { + use egui_kittest::kittest::Queryable; + let app = RustGisApp::with_sample(); + let original: Vec<_> = app.session.map().layers.iter().map(|l| l.id).collect(); + let moved = layer(&app, "Countries"); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(6); + let from = h.get_by_label("Countries").rect().center(); + let first = h.get_by_label("Cities").rect(); + touch_drag(&mut h, from, pos2(first.center().x, first.min.y + first.height() * 0.125), 6); + h.run_steps(3); + let order: Vec<_> = h.state().session.map().layers.iter().map(|l| l.id).collect(); + assert_eq!(order.first(), Some(&moved), "{order:?} from {original:?}"); + assert_eq!(h.state().session.undo_depth(), 1); + assert!(h.query_by_label("Zoom to Layer").is_none(), "the menu of the long press is still open"); + } + /// #1321: double-clicking a layer opens its Symbology pane even at 4 frames a second (CPU /// rendering of a large map), where egui's default 0.3 s missed the second click. #[test] diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 56c5db9efe..557f2d717b 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -60,6 +60,49 @@ impl Dragged { } } +/// What a row that can be dragged to another place (`reorder`) senses (#2958): clicks, and drags +/// unless a finger is on the screen. A drag is what the list's own drag-to-scroll gives way to, +/// so under a finger the row senses clicks only and a swipe scrolls the list; `reorder_drag` arms +/// the drag by a long press. The mouse of a touch-screen laptop keeps dragging rows. +pub(crate) fn reorder_sense(ui: &Ui, reorder: bool) -> Sense { + if reorder && !ui.input(|i| i.any_touches()) { Sense::click_and_drag() } else { Sense::click() } +} + +/// Whether the drag of the row `resp` starts this frame (#2958): with the mouse, when it starts a +/// drag; with a finger, when it moves after a long press (egui reads the long press as a click of +/// the context menu and lets go of the row's drag, so the pressed row is kept until the finger +/// is up, and the menu closes as the item is taken). Without `reorder` it never does. +pub(crate) fn reorder_drag(ui: &Ui, resp: &Response, reorder: bool) -> bool { + if !reorder { + return false; + } + if resp.drag_started_by(egui::PointerButton::Primary) { + return true; + } + let armed = egui::Id::NULL.with("reorder_long_press"); + let ctx = ui.ctx(); + if resp.long_touched() { + ctx.data_mut(|d| d.insert_temp(armed, Some(resp.id))); + return false; + } + if ctx.data(|d| d.get_temp::>(armed)).flatten() != Some(resp.id) { + return false; + } + let (down, moved) = ui.input(|i| { + let moved = i.pointer.press_origin().zip(i.pointer.latest_pos()).is_some_and(|(a, b)| (b - a).length() > 8.0); + (i.pointer.primary_down(), moved) + }); + if !down { + ctx.data_mut(|d| d.insert_temp(armed, None::)); + return false; + } + if moved { + ctx.data_mut(|d| d.insert_temp(armed, None::)); + egui::Popup::close_all(ctx); + } + moved +} + /// Makes the command the caller runs next, for a change of `r`, part of the undo step of the /// pointer press making it: a number dragged, or a colour picked in its picker, is one step to /// undo however many changes it makes (#1194). A number typed into `r` is a step of its own, even diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index d28e820c46..85a2bbbbfa 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -489,7 +489,7 @@ at least one map. Drag a map or layout tab to another place to change the order the layouts (maps stay before layouts); near the ends of a strip whose tabs don't all fit, the tabs scroll. In Browser, drag a map or layout up or down its list the same way; near the Browser's top or bottom, the list scrolls, the row you drag is filled, and a line across the list -shows where it will land. The map or layout in view stays in view, each move is +shows where it will land. On a touch screen a swipe scrolls those lists; to drag a tab, a row or a layer, hold it until its menu opens, then move your finger (the menu closes and the item follows). The map or layout in view stays in view, each move is one undo step, and the order is saved with the project. From scripts: `map.move` and `layout.move`, with the name and the new place (`"to"`: 0 for the first). From dc0e3185850115c9848b01bc441841d3255ca300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 10:21:00 -0500 Subject: [PATCH 2/8] test(ui): the swipe test proves the list scrolls; a long press still opens the menu (#2958) --- crates/ui-egui/src/panes.rs | 48 +++++++++++++++++++++++++++++------- docs/user-guide/workspace.md | 4 ++- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index dcce023ff3..c6f0d80758 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -8541,11 +8541,17 @@ mod tests { /// #2958: a swipe of a finger over the layer rows scrolls the list; it does not take the row /// under the finger to another place, as the mouse does. #[test] - fn a_swipe_over_the_layers_does_not_reorder_them() { + fn a_swipe_over_the_layers_scrolls_and_does_not_reorder_them() { use egui_kittest::kittest::Queryable; - let app = RustGisApp::with_sample(); + let _turn = crate::fetching::turn(); + let mut app = RustGisApp::with_sample(); + for i in 0..30 { + app.run("map.addTiles", json!({"url": format!("https://wms.example.org/{i}/{{z}}/{{x}}/{{y}}.png"), "name": format!("Depths {i}"), "overlay": true})) + .unwrap(); + } let original: Vec<_> = app.session.map().layers.iter().map(|l| l.id).collect(); - let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).with_max_steps(64).build_ui_state( + let tiles: Vec<_> = app.session.map().tiles.iter().map(|t| t.name.clone()).collect(); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 700.0)).with_max_steps(64).build_ui_state( |ui, app: &mut RustGisApp| { let ctx = ui.ctx().clone(); app.logic(&ctx); @@ -8554,12 +8560,16 @@ mod tests { app, ); h.run_steps(6); - let from = h.get_by_label("Countries").rect().center(); - let first = h.get_by_label("Cities").rect(); - touch_drag(&mut h, from, pos2(first.center().x, first.min.y + 2.0), 0); + let row = h.get_by_label("Depths 29").rect(); + assert!(row.max.y < 650.0, "the row is on screen: {row:?}"); + let from = row.center(); + touch_drag(&mut h, from, from - vec2(0.0, 3.0 * row.height()), 0); h.run_steps(3); - assert_eq!(h.state().session.map().layers.iter().map(|l| l.id).collect::>(), original); - assert_eq!(h.state().session.undo_depth(), 0); + let state = h.state().session.map(); + assert_eq!(state.layers.iter().map(|l| l.id).collect::>(), original); + assert_eq!(state.tiles.iter().map(|t| t.name.clone()).collect::>(), tiles); + assert_eq!(h.state().session.undo_depth(), 30); + assert!(h.get_by_label("Depths 29").rect().center().y < from.y - 1.0, "the swipe did not scroll the list"); } /// #2958: a finger held on a layer row and then moved takes the row to another place, as the @@ -8586,7 +8596,27 @@ mod tests { let order: Vec<_> = h.state().session.map().layers.iter().map(|l| l.id).collect(); assert_eq!(order.first(), Some(&moved), "{order:?} from {original:?}"); assert_eq!(h.state().session.undo_depth(), 1); - assert!(h.query_by_label("Zoom to Layer").is_none(), "the menu of the long press is still open"); + assert!(h.query_by_label("Labeling Properties…").is_none(), "the menu of the long press is still open"); + } + + /// #2958: a finger held on a layer row without moving opens the row's menu, as today. + #[test] + fn a_long_press_on_a_layer_still_opens_its_menu() { + use egui_kittest::kittest::Queryable; + let app = RustGisApp::with_sample(); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(6); + let from = h.get_by_label("Countries").rect().center(); + touch_drag(&mut h, from, from, 6); + h.run_steps(2); + assert!(h.query_by_label("Labeling Properties…").is_some(), "no menu after the long press"); } /// #1321: double-clicking a layer opens its Symbology pane even at 4 frames a second (CPU diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index 85a2bbbbfa..de1bb3685a 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -489,7 +489,9 @@ at least one map. Drag a map or layout tab to another place to change the order the layouts (maps stay before layouts); near the ends of a strip whose tabs don't all fit, the tabs scroll. In Browser, drag a map or layout up or down its list the same way; near the Browser's top or bottom, the list scrolls, the row you drag is filled, and a line across the list -shows where it will land. On a touch screen a swipe scrolls those lists; to drag a tab, a row or a layer, hold it until its menu opens, then move your finger (the menu closes and the item follows). The map or layout in view stays in view, each move is +shows where it will land. On a touch screen a swipe scrolls the tab strips and the Browser's +lists; to drag a tab, a row or a layer, hold it until its menu opens, then move your finger (the +menu closes and the item follows). The map or layout in view stays in view, each move is one undo step, and the order is saved with the project. From scripts: `map.move` and `layout.move`, with the name and the new place (`"to"`: 0 for the first). From 70327fb2322ad453dbf120a8e6a8ca125529c941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 11:54:43 -0500 Subject: [PATCH 3/8] refactor(ui): hold the long-pressed row as a plain id; name the tile swipe test (#2958) --- crates/ui-egui/src/panes.rs | 4 ++-- crates/ui-egui/src/widgets.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index c6f0d80758..d9971a3ff5 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -8538,10 +8538,10 @@ mod tests { h.step(); } - /// #2958: a swipe of a finger over the layer rows scrolls the list; it does not take the row + /// #2958: a swipe of a finger over the web tile rows scrolls the list; it does not take the row /// under the finger to another place, as the mouse does. #[test] - fn a_swipe_over_the_layers_scrolls_and_does_not_reorder_them() { + fn a_swipe_over_the_tile_rows_scrolls_and_does_not_reorder_them() { use egui_kittest::kittest::Queryable; let _turn = crate::fetching::turn(); let mut app = RustGisApp::with_sample(); diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 557f2d717b..30cf0a72e0 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -82,10 +82,10 @@ pub(crate) fn reorder_drag(ui: &Ui, resp: &Response, reorder: bool) -> bool { let armed = egui::Id::NULL.with("reorder_long_press"); let ctx = ui.ctx(); if resp.long_touched() { - ctx.data_mut(|d| d.insert_temp(armed, Some(resp.id))); + ctx.data_mut(|d| d.insert_temp(armed, resp.id)); return false; } - if ctx.data(|d| d.get_temp::>(armed)).flatten() != Some(resp.id) { + if ctx.data(|d| d.get_temp::(armed)) != Some(resp.id) { return false; } let (down, moved) = ui.input(|i| { @@ -93,11 +93,11 @@ pub(crate) fn reorder_drag(ui: &Ui, resp: &Response, reorder: bool) -> bool { (i.pointer.primary_down(), moved) }); if !down { - ctx.data_mut(|d| d.insert_temp(armed, None::)); + ctx.data_mut(|d| d.remove::(armed)); return false; } if moved { - ctx.data_mut(|d| d.insert_temp(armed, None::)); + ctx.data_mut(|d| d.remove::(armed)); egui::Popup::close_all(ctx); } moved From 3d481d82a775d933e09f7bf5b4da828a60ec41e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 12:27:16 -0500 Subject: [PATCH 4/8] fix(ui): a long press arms only the press that made it (#2958) --- crates/ui-egui/src/widgets.rs | 62 ++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 30cf0a72e0..dabea61503 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -81,23 +81,19 @@ pub(crate) fn reorder_drag(ui: &Ui, resp: &Response, reorder: bool) -> bool { } let armed = egui::Id::NULL.with("reorder_long_press"); let ctx = ui.ctx(); + // The row and when its press began: a later press never matches, so an arm left behind by a + // row that was not drawn when the finger lifted is dead. + let press = (resp.id, ui.input(|i| i.pointer.press_start_time())); if resp.long_touched() { - ctx.data_mut(|d| d.insert_temp(armed, resp.id)); + ctx.data_mut(|d| d.insert_temp(armed, press)); return false; } - if ctx.data(|d| d.get_temp::(armed)) != Some(resp.id) { - return false; - } - let (down, moved) = ui.input(|i| { - let moved = i.pointer.press_origin().zip(i.pointer.latest_pos()).is_some_and(|(a, b)| (b - a).length() > 8.0); - (i.pointer.primary_down(), moved) - }); - if !down { - ctx.data_mut(|d| d.remove::(armed)); + if ctx.data(|d| d.get_temp::<(egui::Id, Option)>(armed)) != Some(press) { return false; } + let moved = ui.input(|i| i.pointer.press_origin().zip(i.pointer.latest_pos()).is_some_and(|(a, b)| (b - a).length() > 8.0)); if moved { - ctx.data_mut(|d| d.remove::(armed)); + ctx.data_mut(|d| d.remove::<(egui::Id, Option)>(armed)); egui::Popup::close_all(ctx); } moved @@ -1035,6 +1031,50 @@ pub fn picked_colour(hsva: egui::ecolor::Hsva, before: egui::ecolor::Hsva, old: mod tests { use egui_kittest::kittest::Queryable; + /// #2958: a long press whose row is gone when the finger lifts arms no later press, even when + /// the row comes back under a finger already down. + #[test] + fn a_long_press_arms_only_its_own_press() { + use egui::{Event, Modifiers, PointerButton, TouchDeviceId, TouchId, TouchPhase}; + // Whether the row is drawn, and how many drags it started. + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(200.0, 200.0)).build_ui_state( + |ui, (shown, drags): &mut (bool, usize)| { + if *shown { + let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(200.0, 100.0)); + let resp = ui.interact(rect, egui::Id::unique("row"), super::reorder_sense(ui, true)); + *drags += usize::from(super::reorder_drag(ui, &resp, true)); + } + }, + (true, 0), + ); + let touch = |phase, pos| Event::Touch { device_id: TouchDeviceId(1), id: TouchId(1), phase, pos, force: None }; + let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; + let at = egui::pos2(50.0, 50.0); + let press = |h: &mut egui_kittest::Harness<'_, (bool, usize)>| { + h.event(Event::PointerMoved(at)); + h.event(touch(TouchPhase::Start, at)); + h.event(button(at, true)); + h.step(); + }; + h.step(); + press(&mut h); + for _ in 0..6 { + h.step(); + } + h.state_mut().0 = false; + h.event(touch(TouchPhase::End, at)); + h.event(button(at, false)); + h.event(Event::PointerGone); + h.step(); + press(&mut h); + h.state_mut().0 = true; + let moved = at + egui::vec2(0.0, 40.0); + h.event(touch(TouchPhase::Move, moved)); + h.event(Event::PointerMoved(moved)); + h.step(); + assert_eq!(h.state().1, 0); + } + /// Opens a colour button's picker and says whether it offers additive blending. fn offers_additive(button: fn(&mut egui::Ui, &mut egui::Color32)) -> bool { let mut h = egui_kittest::Harness::builder() From 3df97ef8f8ef2f88fa78e6c052c33e36eb968625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 12:39:51 -0500 Subject: [PATCH 5/8] fix(ui): a swipe starting on a reorderable row scrolls the list on a first contact (#2958) --- crates/ui-egui/src/mapview.rs | 3 +- crates/ui-egui/src/panes.rs | 61 ++++++++++++++++++++++++++++++++--- crates/ui-egui/src/ribbon.rs | 3 +- crates/ui-egui/src/widgets.rs | 19 +++++++++++ 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index e20f7f4a7a..48bb2a0a52 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -4823,12 +4823,13 @@ fn view_tabs(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { let area = egui::ScrollArea::horizontal().id_salt("view_tabs").max_width(room); let tips = [tl!("Scroll the map tabs left"), tl!("Scroll the map tabs right")]; let mut close = None; - crate::ribbon::arrow_scroll_area(&mut tabs_ui, t, "view_tabs", area, tips, |ui| { + let strip_area = crate::ribbon::arrow_scroll_area(&mut tabs_ui, t, "view_tabs", area, tips, |ui| { ui.horizontal(|ui| { ui.spacing_mut().item_spacing = vec2(2.0, 0.0); close = view_tab_row(app, ui, t, follow); }); }); + crate::widgets::yield_touch_drag(ui.ctx(), strip_area); // Right after the tabs, or at the strip's right edge once they scroll. let x = tabs_ui.min_rect().max.x + 2.0; let pr = Rect::from_min_size(pos2(x + 2.0, r.min.y + 6.0), vec2(NEW_TAB_W, 20.0)); diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index d9971a3ff5..a8d8b991db 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -745,7 +745,7 @@ fn contents(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { }); } ui.add_space(2.0); - egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| { + let area = egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| { let header = ui .horizontal(|ui| { ui.add_space(8.0); @@ -937,6 +937,7 @@ fn contents(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } } }); + crate::widgets::yield_touch_drag(ui.ctx(), area.id); } /// What pasting the copy adds (#491), translated: the copied group(s), or else the layer(s). @@ -2648,7 +2649,7 @@ fn fill_dragged_row(ui: &Ui, fill: egui::layers::ShapeIdx, dragging: bool, row: /// Draws the Browser; toolbox identities use source names so translations can share labels. fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { - egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| { + let area = egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| { egui::Frame::NONE.inner_margin(egui::Margin::symmetric(10, 8)).show(ui, |ui| { egui::CollapsingHeader::new(egui::RichText::new(tl!("Maps")).font(semibold(12.5))).default_open(true).show(ui, |ui| { let maps: Vec = app.session.project.maps.iter().map(|m| m.name.clone()).collect(); @@ -2863,6 +2864,7 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } }); }); + crate::widgets::yield_touch_drag(ui.ctx(), area.id); } fn folder_browser(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { @@ -8520,8 +8522,8 @@ mod tests { let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; h.event(Event::PointerMoved(from)); h.step(); - h.event(touch(TouchPhase::Start, from)); - h.event(button(from, true)); + // As winit sends a first contact: the touch and its press in one frame. + h.input_mut().events.extend([touch(TouchPhase::Start, from), button(from, true)]); h.step(); for _ in 0..held { h.step(); @@ -8599,6 +8601,57 @@ mod tests { assert!(h.query_by_label("Labeling Properties…").is_none(), "the menu of the long press is still open"); } + /// #2958: a tap of a finger on a layer row still picks the layer. + #[test] + fn a_tap_on_a_layer_still_picks_it() { + use egui_kittest::kittest::Queryable; + let app = RustGisApp::with_sample(); + let picked = layer(&app, "Rivers"); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(6); + assert_ne!(h.state().session.active_layer, Some(picked)); + let at = h.get_by_label("Rivers").rect().center(); + touch_drag(&mut h, at, at, 0); + h.run_steps(3); + assert_eq!(h.state().session.active_layer, Some(picked)); + } + + /// #2958: a swipe over the view tabs scrolls the strip and leaves the maps in their order. + #[test] + fn a_swipe_over_the_view_tabs_scrolls_and_does_not_reorder_them() { + use egui_kittest::kittest::Queryable; + let mut app = RustGisApp::with_sample(); + for i in 0..20 { + app.run("map.new", json!({"name": format!("Sheet {i}")})).unwrap(); + } + app.run("map.activate", json!({"name": "Sheet 0"})).unwrap(); + let names = |app: &RustGisApp| app.session.project.maps.iter().map(|m| m.name.clone()).collect::>(); + let original = names(&app); + // The Browser, which lists the maps by the same names, closed. + app.ui.left = None; + let mut h = egui_kittest::Harness::builder().with_size(vec2(900.0, 700.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(8); + let from = h.get_by_label("Sheet 1").rect().center(); + touch_drag(&mut h, from, from - vec2(120.0, 0.0), 0); + h.run_steps(3); + assert_eq!(names(h.state()), original); + assert!(h.get_by_label("Sheet 1").rect().center().x < from.x - 1.0, "the swipe did not scroll the tabs"); + } + /// #2958: a finger held on a layer row without moving opens the row's menu, as today. #[test] fn a_long_press_on_a_layer_still_opens_its_menu() { diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 081d4e3e01..431519c309 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -229,7 +229,7 @@ pub(crate) fn arrow_scroll_area( area: egui::ScrollArea, tips: [&str; 2], add: impl FnOnce(&mut Ui) -> R, -) { +) -> egui::Id { // egui sets a scroll area's offset only as it is built, so a click moves it on the next frame. // It is asked for once, on a frame egui keeps: a discarded one doesn't move the area, and asking // on every frame would pin the area there against the wheel. @@ -250,6 +250,7 @@ pub(crate) fn arrow_scroll_area( ui.data_mut(|d| d.insert_temp(key, x)); ui.ctx().request_repaint(); } + scroll.id } /// The collapse button at the right of the tab strip. diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index dabea61503..007ee7cf32 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -68,6 +68,20 @@ pub(crate) fn reorder_sense(ui: &Ui, reorder: bool) -> Sense { if reorder && !ui.input(|i| i.any_touches()) { Sense::click_and_drag() } else { Sense::click() } } +fn touched_row() -> egui::Id { + egui::Id::NULL.with("reorder_touched_row") +} + +/// After the scroll area `area` of a list of reorderable rows: gives it the drag of a finger that +/// came down on one of them, so a swipe scrolls the list (#2958). +pub(crate) fn yield_touch_drag(ctx: &egui::Context, area: egui::Id) { + if ctx.data(|d| d.get_temp::(touched_row())) == Some(true) { + ctx.data_mut(|d| d.remove::(touched_row())); + // The id egui gives the drag of a scroll area's content. + ctx.set_dragged_id(area.with("area")); + } +} + /// Whether the drag of the row `resp` starts this frame (#2958): with the mouse, when it starts a /// drag; with a finger, when it moves after a long press (egui reads the long press as a click of /// the context menu and lets go of the row's drag, so the pressed row is kept until the finger @@ -79,6 +93,11 @@ pub(crate) fn reorder_drag(ui: &Ui, resp: &Response, reorder: bool) -> bool { if resp.drag_started_by(egui::PointerButton::Primary) { return true; } + // A first contact is read with the senses of the frame before, when no finger was down, so + // the row owns its drag: noted for the list to take it (`yield_touch_drag`). + if resp.is_pointer_button_down_on() && ui.input(|i| i.any_touches() && i.pointer.any_pressed()) { + ui.ctx().data_mut(|d| d.insert_temp(touched_row(), true)); + } let armed = egui::Id::NULL.with("reorder_long_press"); let ctx = ui.ctx(); // The row and when its press began: a later press never matches, so an arm left behind by a From 6a23daabb54736f2015b94bc085b893467febd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 13:13:40 -0500 Subject: [PATCH 6/8] test(ui): the tap test is a short tap that opens no menu (#2958) --- crates/ui-egui/src/panes.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index a8d8b991db..ca734d2919 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -8618,8 +8618,16 @@ mod tests { h.run_steps(6); assert_ne!(h.state().session.active_layer, Some(picked)); let at = h.get_by_label("Rivers").rect().center(); - touch_drag(&mut h, at, at, 0); + // Down and up at once: no long press, whose menu would pick the row itself. + use egui::{Event, Modifiers, PointerButton, TouchDeviceId, TouchId, TouchPhase}; + let touch = |phase| Event::Touch { device_id: TouchDeviceId(1), id: TouchId(1), phase, pos: at, force: None }; + let button = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; + h.input_mut().events.extend([Event::PointerMoved(at), touch(TouchPhase::Start), button(true)]); + h.step(); + h.input_mut().events.extend([touch(TouchPhase::End), button(false), Event::PointerGone]); + h.step(); h.run_steps(3); + assert!(h.query_by_label("Labeling Properties…").is_none(), "a tap opened the menu"); assert_eq!(h.state().session.active_layer, Some(picked)); } From d486c135d5edb50bb5b84b16fef5868217b518ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 13:39:03 -0500 Subject: [PATCH 7/8] docs(ui): the long press arms the row for that press only (#2958) --- crates/ui-egui/src/widgets.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 007ee7cf32..c21dd46aa7 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -84,8 +84,8 @@ pub(crate) fn yield_touch_drag(ctx: &egui::Context, area: egui::Id) { /// Whether the drag of the row `resp` starts this frame (#2958): with the mouse, when it starts a /// drag; with a finger, when it moves after a long press (egui reads the long press as a click of -/// the context menu and lets go of the row's drag, so the pressed row is kept until the finger -/// is up, and the menu closes as the item is taken). Without `reorder` it never does. +/// the context menu and lets go of the row's drag, so the long press arms the row for that press +/// only, and the menu closes as the item is taken). Without `reorder` it never does. pub(crate) fn reorder_drag(ui: &Ui, resp: &Response, reorder: bool) -> bool { if !reorder { return false; From cddcba4a4557652702d67d889fe903327648bda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 13:58:40 -0500 Subject: [PATCH 8/8] test(ui): a long-press drag leaves the list still; say what the drag hand-over relies on (#2958) --- crates/ui-egui/src/panes.rs | 29 +++++++++++++++++++++++++++++ crates/ui-egui/src/widgets.rs | 12 +++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index ca734d2919..4bd3b2b3b2 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -8631,6 +8631,35 @@ mod tests { assert_eq!(h.state().session.active_layer, Some(picked)); } + /// #2958: a finger held on a row of a long list and then moved drags the row; the list under + /// it stays where it was. + #[test] + fn a_long_press_then_a_move_does_not_scroll_the_list() { + use egui_kittest::kittest::Queryable; + let _turn = crate::fetching::turn(); + let mut app = RustGisApp::with_sample(); + for i in 0..30 { + app.run("map.addTiles", json!({"url": format!("https://wms.example.org/{i}/{{z}}/{{x}}/{{y}}.png"), "name": format!("Depths {i}"), "overlay": true})) + .unwrap(); + } + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 700.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(6); + let from = h.get_by_label("Depths 25").rect().center(); + // A row the drag does not pass, so only a scroll would move it. + let still = h.get_by_label("Depths 15").rect().center(); + touch_drag(&mut h, from, from - vec2(0.0, 80.0), 6); + h.run_steps(10); + let now = h.get_by_label("Depths 15").rect().center(); + assert!((now.y - still.y).abs() < 0.5, "the list scrolled: {still:?} to {now:?}"); + } + /// #2958: a swipe over the view tabs scrolls the strip and leaves the maps in their order. #[test] fn a_swipe_over_the_view_tabs_scrolls_and_does_not_reorder_them() { diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index c21dd46aa7..1e3d609596 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -61,9 +61,9 @@ impl Dragged { } /// What a row that can be dragged to another place (`reorder`) senses (#2958): clicks, and drags -/// unless a finger is on the screen. A drag is what the list's own drag-to-scroll gives way to, -/// so under a finger the row senses clicks only and a swipe scrolls the list; `reorder_drag` arms -/// the drag by a long press. The mouse of a touch-screen laptop keeps dragging rows. +/// unless a finger is on the screen. While a finger is down the list's drag-to-scroll must win a +/// swipe, so the row senses clicks only and `reorder_drag` arms its drag by a long press. The +/// mouse of a touch-screen laptop keeps dragging rows. pub(crate) fn reorder_sense(ui: &Ui, reorder: bool) -> Sense { if reorder && !ui.input(|i| i.any_touches()) { Sense::click_and_drag() } else { Sense::click() } } @@ -73,11 +73,13 @@ fn touched_row() -> egui::Id { } /// After the scroll area `area` of a list of reorderable rows: gives it the drag of a finger that -/// came down on one of them, so a swipe scrolls the list (#2958). +/// came down on one of them, so a swipe scrolls the list (#2958). Every such row must sit inside +/// a list that calls this, or the next list that does takes its drag. pub(crate) fn yield_touch_drag(ctx: &egui::Context, area: egui::Id) { if ctx.data(|d| d.get_temp::(touched_row())) == Some(true) { ctx.data_mut(|d| d.remove::(touched_row())); - // The id egui gives the drag of a scroll area's content. + // The id egui 0.37 gives the drag of a scroll area's content (`scroll_area.rs`); the + // swipe tests in `panes.rs` fail if it changes. ctx.set_dragged_id(area.with("area")); } }