Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions crates/ui-egui/src/panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -2652,18 +2660,24 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) {
let maps: Vec<String> = 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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
88 changes: 88 additions & 0 deletions crates/ui-egui/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,94 @@ 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<egui::Shape> {
fn flatten(s: &egui::Shape, out: &mut Vec<egui::Shape>) {
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);
// 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<egui::Rect> {
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>| -> 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))
}
_ => 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: 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).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));
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();
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).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"]);
// 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]
Expand Down
7 changes: 4 additions & 3 deletions docs/user-guide/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,10 @@ 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
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).
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).

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
Expand Down
Loading