diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 059524bd34..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)); @@ -4856,7 +4857,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 +4908,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 +5011,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..4bd3b2b3b2 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). @@ -1337,10 +1338,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 +1659,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 +2053,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); @@ -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(); @@ -2663,7 +2664,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 +2727,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})); @@ -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) { @@ -8512,6 +8514,201 @@ 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(); + // 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(); + } + 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 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_tile_rows_scrolls_and_does_not_reorder_them() { + 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 original: Vec<_> = app.session.map().layers.iter().map(|l| l.id).collect(); + 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); + app.ui(ui); + }, + app, + ); + h.run_steps(6); + 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); + 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 + /// 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("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(); + // 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)); + } + + /// #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() { + 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() { + 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 /// rendering of a large map), where egui's default 0.3 s missed the second click. #[test] 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 56c5db9efe..1e3d609596 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -60,6 +60,66 @@ 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. 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() } +} + +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). 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 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")); + } +} + +/// 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 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; + } + 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 + // 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, press)); + return false; + } + 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::<(egui::Id, Option)>(armed)); + 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 @@ -992,6 +1052,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() diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index d28e820c46..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. 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).