From 91b9e34f638e7626f1c2168d43c198b30b8b12c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 12:58:43 -0500 Subject: [PATCH 1/2] feat(ui): the Browser fills the Maps or Layouts row being dragged and draws its drop line across the list (#2956) --- crates/ui-egui/src/panes.rs | 22 +++++++++- crates/ui-egui/tests/smoke.rs | 81 +++++++++++++++++++++++++++++++++++ docs/user-guide/workspace.md | 3 +- 3 files changed, 103 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 3cef055f76..4ad6177166 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -2644,6 +2644,14 @@ fn layer_menu(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, reorder: bool) { // --------------------------------------------------------------------------------------------- // Catalog +/// Fills the `row` of a Maps or Layouts entry of the Browser while it is `dragging` (what +/// `drag_tab` answered), behind its icon and name: `fill` is the shape reserved before it was drawn. +fn fill_dragged_row(ui: &Ui, fill: egui::layers::ShapeIdx, dragging: bool, row: Rect, t: &Tokens) { + if dragging { + ui.painter().set(fill, egui::Shape::rect_filled(row, CornerRadius::same(5), t.hover)); + } +} + /// 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| { @@ -2652,18 +2660,24 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { let maps: Vec = app.session.project.maps.iter().map(|m| m.name.clone()).collect(); let mut rows = Vec::with_capacity(maps.len()); for (i, m) in maps.iter().enumerate() { + // The row spans the list, so the drop line (#2829) and the fill do too (#2956); the fill + // is painted once the row's rectangle is known, behind its icon and name. + let fill = ui.painter().add(egui::Shape::Noop); let row = ui.horizontal(|ui| { + ui.set_min_width(ui.available_width()); let (r, _) = ui.allocate_exact_size(vec2(16.0, 16.0), Sense::hover()); 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()); - crate::mapview::drag_tab(ui, &resp, false, m); + let dragging = crate::mapview::drag_tab(ui, &resp, false, m); if resp.clicked() { let _ = app.run("map.activate", json!({"name": m})); } resp.context_menu(|ui| map_menu(app, ui, m)); + dragging }); + fill_dragged_row(ui, fill, row.inner, row.response.rect, t); rows.push(row.response.rect); } crate::mapview::tab_drop(app, ui, t, &rows, &maps, false, true); @@ -2704,7 +2718,9 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { egui::CollapsingHeader::new(egui::RichText::new(tl!("Layouts")).font(semibold(12.5))).default_open(true).show(ui, |ui| { let mut rows = Vec::with_capacity(layouts.len()); for n in &layouts { + let fill = ui.painter().add(egui::Shape::Noop); let row = ui.horizontal(|ui| { + ui.set_min_width(ui.available_width()); let (r, _) = ui.allocate_exact_size(vec2(16.0, 16.0), Sense::hover()); icons::paint(ui.painter(), r, "new_layout", t.icon, t.accent); let resp = ui @@ -2717,13 +2733,15 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { n, ) .interact(Sense::drag()); - crate::mapview::drag_tab(ui, &resp, true, n); + let dragging = crate::mapview::drag_tab(ui, &resp, true, n); if resp.clicked() { let _ = app.run("layout.activate", json!({"name": n})); app.ui.tab = "Publish".into(); } resp.context_menu(|ui| layout_menu(app, ui, n)); + dragging }); + fill_dragged_row(ui, fill, row.inner, row.response.rect, t); rows.push(row.response.rect); } crate::mapview::tab_drop(app, ui, t, &rows, &layouts, true, true); diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs index c86f0beece..6f1837dd39 100644 --- a/crates/ui-egui/tests/smoke.rs +++ b/crates/ui-egui/tests/smoke.rs @@ -1551,6 +1551,87 @@ fn dragging_browser_rows_reorders_maps_or_layouts_in_one_undo_step() { assert_eq!(active_view(&h), "M2"); } +/// Every shape the last frame drew, nested ones flattened. +fn drawn_shapes(h: &egui_kittest::Harness<'_, RustGisApp>) -> Vec { + fn flatten(s: &egui::Shape, out: &mut Vec) { + match s { + egui::Shape::Vec(v) => v.iter().for_each(|s| flatten(s, out)), + s => out.push(s.clone()), + } + } + let mut out = Vec::new(); + h.output().shapes.iter().for_each(|c| flatten(&c.shape, &mut out)); + out +} + +/// While a Browser row is dragged it is filled, as a tab and a layer are, and the line where it +/// would land spans the list, not just the name of the last row; let go, the fill goes (#2956). +#[test] +fn a_browser_row_being_dragged_is_filled_and_its_drop_line_spans_the_list() { + let mut h = harness(); + h.state_mut().run("ui.pane.catalog", json!(null)).unwrap(); + activate_world(&mut h); + for n in ["M2", "M3"] { + h.state_mut().run("map.new", json!({"name": n})).unwrap(); + } + for n in ["L1", "L2"] { + h.state_mut().run("layout.new", json!({"name": n})).unwrap(); + } + activate_world(&mut h); + settle(&mut h); + let t = rustgis_ui_egui::theme::Tokens::get(&h.ctx); + // Rects of at least this width are a row's fill or a line across the list: a name is narrower. + let wide = 120.0; + let fills = |h: &egui_kittest::Harness<'_, RustGisApp>, y: f32| { + drawn_shapes(h) + .iter() + .filter(|s| matches!(s, egui::Shape::Rect(r) if r.fill == t.hover && r.rect.width() >= wide && r.rect.y_range().contains(y))) + .count() + }; + let lines = |h: &egui_kittest::Harness<'_, RustGisApp>| { + let across = |s: &egui::Shape| match s { + egui::Shape::LineSegment { points, stroke } => { + stroke.color == t.accent && stroke.width == 2.0 && points[0].y == points[1].y && (points[0].x - points[1].x).abs() >= wide + } + _ => false, + }; + drawn_shapes(h).iter().filter(|s| across(s)).count() + }; + let button = + |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + // `dragged` held over the upper half of `onto`'s row: `dragged` filled, one line across the list. + // Then let go (the pointer leaves) and nothing stays marked. + let hold_and_drop = |h: &mut egui_kittest::Harness<'_, RustGisApp>, dragged: &str, onto: &str| { + let (row, target) = (browser_row(h, dragged), browser_row(h, onto)); + assert_eq!((fills(h, row.center().y), lines(h)), (0, 0), "nothing marked before a drag"); + let (from, to) = (row.center(), egui::pos2(target.center().x, target.min.y + 3.0)); + h.event(egui::Event::PointerMoved(from)); + h.event(button(from, true)); + h.step(); + for i in 1..=6 { + h.event(egui::Event::PointerMoved(from + (to - from) * (i as f32 / 6.0))); + h.step(); + } + h.event(egui::Event::PointerMoved(to)); + h.step(); + assert_eq!(fills(h, row.center().y), 1, "{dragged} being dragged is filled"); + assert_eq!(lines(h), 1, "the drop line spans the list"); + h.event(button(to, false)); + settle(h); + h.event(egui::Event::PointerMoved(egui::pos2(5.0, 5.0))); + settle(h); + let moved = browser_row(h, dragged); + assert_eq!((fills(h, moved.center().y), lines(h)), (0, 0), "nothing marked once let go"); + }; + hold_and_drop(&mut h, "M3", "World"); + assert_eq!(map_names(&h), ["M3", "World", "M2"]); + // The map in view is dragged like any other. + hold_and_drop(&mut h, "World", "M3"); + assert_eq!(map_names(&h), ["World", "M3", "M2"]); + hold_and_drop(&mut h, "L2", "L1"); + assert_eq!(layout_names(&h), ["L2", "L1"]); +} + /// Held near the Browser's bottom edge, a dragged map row scrolls the list down past the rows in /// view, and lands there when let go (#2829). #[test] diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index 8240513820..d28e820c46 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -488,7 +488,8 @@ Right-click a map or layout tab (or its entry in Browser) to **Rename**, **Dupli at least one map. Drag a map or layout tab to another place to change the order of the maps or 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 map or layout in view stays in view, each move is +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 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 fbd364dc88404678fbf091807520c3e672deff58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 15:07:43 -0500 Subject: [PATCH 2/2] test(ui): the Browser drag test checks the line runs the filled row's width, and the guide paragraph is reflowed (#2956) --- crates/ui-egui/tests/smoke.rs | 45 ++++++++++++++++++++--------------- docs/user-guide/workspace.md | 6 ++--- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs index 6f1837dd39..3191fbe335 100644 --- a/crates/ui-egui/tests/smoke.rs +++ b/crates/ui-egui/tests/smoke.rs @@ -1580,30 +1580,34 @@ fn a_browser_row_being_dragged_is_filled_and_its_drop_line_spans_the_list() { activate_world(&mut h); settle(&mut h); let t = rustgis_ui_egui::theme::Tokens::get(&h.ctx); - // Rects of at least this width are a row's fill or a line across the list: a name is narrower. - let wide = 120.0; - let fills = |h: &egui_kittest::Harness<'_, RustGisApp>, y: f32| { - drawn_shapes(h) - .iter() - .filter(|s| matches!(s, egui::Shape::Rect(r) if r.fill == t.hover && r.rect.width() >= wide && r.rect.y_range().contains(y))) - .count() + // The hover-filled rects over `y` and the accent lines across a row, as the last frame drew them. + // Anything under 100 pt wide is not a row's fill or a line across a list: a name is narrower. + let fills = |h: &egui_kittest::Harness<'_, RustGisApp>, y: f32| -> Vec { + let rects = drawn_shapes(h).into_iter().filter_map(|s| match s { + egui::Shape::Rect(r) if r.fill == t.hover && r.rect.y_range().contains(y) => Some(r.rect), + _ => None, + }); + rects.filter(|r| r.width() >= 100.0).collect() }; - let lines = |h: &egui_kittest::Harness<'_, RustGisApp>| { - let across = |s: &egui::Shape| match s { - egui::Shape::LineSegment { points, stroke } => { - stroke.color == t.accent && stroke.width == 2.0 && points[0].y == points[1].y && (points[0].x - points[1].x).abs() >= wide + let lines = |h: &egui_kittest::Harness<'_, RustGisApp>| -> Vec<(f32, f32)> { + let spans = drawn_shapes(h).into_iter().filter_map(|s| match s { + egui::Shape::LineSegment { points, stroke } + if stroke.color == t.accent && stroke.width == 2.0 && points[0].y == points[1].y => + { + Some((points[0].x, points[1].x)) } - _ => false, - }; - drawn_shapes(h).iter().filter(|s| across(s)).count() + _ => None, + }); + spans.filter(|(a, b)| (b - a).abs() >= 100.0).collect() }; let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; - // `dragged` held over the upper half of `onto`'s row: `dragged` filled, one line across the list. + // `dragged` held over the upper half of `onto`'s row: its row is filled across the list, wider than + // its name, and the one line runs the row's width (2 pt in from each end, as `tab_drop` draws it). // Then let go (the pointer leaves) and nothing stays marked. let hold_and_drop = |h: &mut egui_kittest::Harness<'_, RustGisApp>, dragged: &str, onto: &str| { let (row, target) = (browser_row(h, dragged), browser_row(h, onto)); - assert_eq!((fills(h, row.center().y), lines(h)), (0, 0), "nothing marked before a drag"); + assert_eq!((fills(h, row.center().y).len(), lines(h).len()), (0, 0), "nothing marked before a drag"); let (from, to) = (row.center(), egui::pos2(target.center().x, target.min.y + 3.0)); h.event(egui::Event::PointerMoved(from)); h.event(button(from, true)); @@ -1614,14 +1618,17 @@ fn a_browser_row_being_dragged_is_filled_and_its_drop_line_spans_the_list() { } h.event(egui::Event::PointerMoved(to)); h.step(); - assert_eq!(fills(h, row.center().y), 1, "{dragged} being dragged is filled"); - assert_eq!(lines(h), 1, "the drop line spans the list"); + let (filled, drawn) = (fills(h, row.center().y), lines(h)); + assert_eq!((filled.len(), drawn.len()), (1, 1), "{dragged} being dragged is filled, with one drop line"); + let (filled, (from_x, to_x)) = (filled[0], drawn[0]); + assert!(filled.width() > row.width() + 60.0, "the fill spans the list, not just the name of {dragged}"); + assert!((from_x - (filled.min.x + 2.0)).abs() < 1.0 && (to_x - (filled.max.x - 2.0)).abs() < 1.0, "the line runs the row's width"); h.event(button(to, false)); settle(h); h.event(egui::Event::PointerMoved(egui::pos2(5.0, 5.0))); settle(h); let moved = browser_row(h, dragged); - assert_eq!((fills(h, moved.center().y), lines(h)), (0, 0), "nothing marked once let go"); + assert_eq!((fills(h, moved.center().y).len(), lines(h).len()), (0, 0), "nothing marked once let go"); }; hold_and_drop(&mut h, "M3", "World"); assert_eq!(map_names(&h), ["M3", "World", "M2"]); diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index d28e820c46..3ed7c0d7ab 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -489,9 +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 -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). +shows where it will land. 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). Click **Command Search** at the right of the title bar or on the Help tab, or press ++ctrl+k++ (++cmd+k++ on macOS). Search by command name, ID or ribbon location; analysis tools, workflow