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
28 changes: 20 additions & 8 deletions crates/ui-egui/src/mapview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4996,6 +4996,25 @@ pub(crate) fn drag_tab(ui: &Ui, resp: &egui::Response, layout: bool, name: &str)
egui::DragAndDrop::payload::<DraggedTab>(ui.ctx()).is_some_and(|d| d.layout == layout && d.name == name)
}

/// While an item is dragged over a list that scrolls (the view tabs, the Browser or the Layers
/// pane), scrolls the list `ui` is in when the `pointer` is near its edge along the axis
/// (`vertical`, else horizontal), faster the closer it is, and asks for a frame to go on (#2957).
/// `view` is the list's visible rectangle: a `pointer` outside it scrolls nothing.
pub(crate) fn edge_scroll(ui: &Ui, view: Rect, pointer: egui::Pos2, vertical: bool) {
if !view.contains(pointer) {
return;
}
let a = usize::from(vertical);
let edge = 28.0;
let push = ((view.min[a] + edge - pointer[a]).max(0.0) - (pointer[a] - (view.max[a] - edge)).max(0.0)) / edge;
if push != 0.0 {
let dt = ui.input(|i| i.stable_dt).min(0.1);
let step = push * 600.0 * dt;
ui.scroll_with_delta_animation(if vertical { vec2(0.0, step) } else { vec2(step, 0.0) }, egui::style::ScrollAnimation::none());
ui.ctx().request_repaint();
}
}

/// While a map or layout tab is dragged over the strip, or its row over the Browser's list
/// (`vertical`): a mark where it would land among the others of its kind (`tabs`, named `names`;
/// layouts with `layout`, else maps), which `map.move` or `layout.move` takes it to when let go;
Expand All @@ -5009,14 +5028,7 @@ pub(crate) fn tab_drop(app: &mut RustGisApp, ui: &Ui, t: &Tokens, tabs: &[Rect],
let Some(pointer) = ui.ctx().pointer_interact_pos().filter(|p| view.contains(*p)) else { return };
// Along the row (x) or the list (y).
let a = usize::from(vertical);
let edge = 28.0;
let push = ((view.min[a] + edge - pointer[a]).max(0.0) - (pointer[a] - (view.max[a] - edge)).max(0.0)) / edge;
if push != 0.0 {
let dt = ui.input(|i| i.stable_dt).min(0.1);
let step = push * 600.0 * dt;
ui.scroll_with_delta_animation(if vertical { vec2(0.0, step) } else { vec2(step, 0.0) }, egui::style::ScrollAnimation::none());
ui.ctx().request_repaint();
}
edge_scroll(ui, view, pointer, vertical);
let (Some(from), Some(first), Some(last)) = (names.iter().position(|n| *n == dragged.name), tabs.first(), tabs.last()) else {
return;
};
Expand Down
8 changes: 1 addition & 7 deletions crates/ui-egui/src/panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,13 +1496,7 @@ fn layer_drop(app: &mut RustGisApp, ui: &Ui, rows: &[DropRow], t: &Tokens) {
let view = ui.clip_rect();
let Some(pointer) = ui.ctx().pointer_interact_pos().filter(|p| view.contains(*p)) else { return };
// Near the top or bottom edge the list scrolls, faster the closer the pointer is.
let edge = 28.0;
let push = ((view.min.y + edge - pointer.y).max(0.0) - (pointer.y - (view.max.y - edge)).max(0.0)) / edge;
if push != 0.0 {
let dt = ui.input(|i| i.stable_dt).min(0.1);
ui.scroll_with_delta_animation(vec2(0.0, push * 600.0 * dt), egui::style::ScrollAnimation::none());
ui.ctx().request_repaint();
}
crate::mapview::edge_scroll(ui, view, pointer, true);
// Only the layer rows take a drop: not the map's name above them, the basemap or a table below.
let (Some(first), Some(last)) = (rows.first(), rows.last()) else { return };
if pointer.y < first.rect.min.y || pointer.y > last.rect.max.y {
Expand Down
42 changes: 34 additions & 8 deletions crates/ui-egui/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,17 @@ fn a_browser_row_being_dragged_is_filled_and_its_drop_line_spans_the_list() {
assert_eq!(layout_names(&h), ["L2", "L1"]);
}

/// The bottom edge of the side pane's list around `from`, where its scroll bar ends (the map is
/// right of the pane, past 250 points).
fn list_bottom(h: &egui_kittest::Harness<'_, RustGisApp>, from: egui::Pos2) -> f32 {
h.query_all_by_role(egui::accesskit::Role::ScrollBar)
.map(|n| n.rect())
.find(|r| r.max.x < from.x + 250.0)
.expect("the pane's scroll bar")
.max
.y
}

/// 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 All @@ -1644,14 +1655,7 @@ fn a_row_dragged_to_the_edge_of_a_long_browser_scrolls_it() {
h.state_mut().run("ui.pane.catalog", json!(null)).unwrap();
activate_world(&mut h);
let from = browser_row(&h, "World").center();
// The list's bottom edge, where its scroll bar ends (the map is right of the Browser).
let bottom = h
.query_all_by_role(egui::accesskit::Role::ScrollBar)
.map(|n| n.rect())
.find(|r| r.max.x < from.x + 250.0)
.expect("the Browser's scroll bar")
.max
.y;
let bottom = list_bottom(&h, from);
let in_view = map_names(&h).iter().position(|n| browser_row(&h, n).max.y > bottom).expect("more maps than fit");
// A few frames: each scrolls up to 60 points here (the harness steps a quarter second), and
// held longer the list reaches its end and the pointer is past the maps, over Toolboxes.
Expand All @@ -1660,6 +1664,28 @@ fn a_row_dragged_to_the_edge_of_a_long_browser_scrolls_it() {
assert!(landed > in_view, "World landed at {landed}, past the {in_view} rows first in view");
}

/// Held near the Layers pane's bottom edge, a dragged layer scrolls the list down: the rows move
/// up (#2957).
#[test]
fn a_layer_dragged_to_the_edge_of_a_long_layers_pane_scrolls_it() {
use rustgis_ui_egui::rustgis_engine::data::{Dataset, GeometryType};
let mut h = harness();
h.set_size(egui::vec2(900.0, 600.0));
for i in 1..=40 {
h.state_mut().session.map_mut().add_dataset(Dataset::new(format!("Row Layer {i}"), GeometryType::Point, vec![]));
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
}
settle(&mut h);
let row = |h: &egui_kittest::Harness<'_, RustGisApp>, name: &str| h.get_by_label(name).rect();
let from = row(&h, "Row Layer 40").center();
let bottom = list_bottom(&h, from);
let before = row(&h, "Row Layer 30").min.y;
// A few frames, held near the bottom: each scrolls up to 60 points here (the harness steps a
// quarter second).
drag(&mut h, from, egui::pos2(from.x, bottom - 6.0), 5);
let after = row(&h, "Row Layer 30").min.y;
assert!(after < before - 20.0, "the rows moved up from {before} to {after}");
}

#[test]
fn plugins_install_from_a_file_after_a_prompt() {
let _turn = PLUGINS.lock().unwrap_or_else(|e| e.into_inner());
Expand Down
Loading