PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Brushes: dragging a preset to the list's edge scrolls the list (#5741) (#5862)
Michael Higginsf44d3b6f0601
diff --git a/crates/ui-egui/src/brushes_tab.rs b/crates/ui-egui/src/brushes_tab.rsindex 709c91c15..3f45526e5 100644--- a/crates/ui-egui/src/brushes_tab.rs+++ b/crates/ui-egui/src/brushes_tab.rs@@ -885,6 +885,15 @@ pub fn preset_list(ui: &mut egui::Ui, presets: &[BrushPreset], current: Option<&let show = (st.show_name, st.show_stroke, st.show_tip);let collapsed = &st.collapsed;egui::ScrollArea::vertical().id_salt(layout.id).max_height(layout.max_height).auto_shrink([false, true]).show(ui, |ui| {+ // A preset, group or folder dragged to the list's top or bottom edge (or past it) scrolls+ // the list, as the Layers panel's rows do, so it can be dropped on rows out of view (#5741).+ let dragging = egui::DragAndDrop::has_payload_of_type::<BrushDrag>(ui.ctx()) && ui.input(|i| i.pointer.primary_down());+ let pointer = ui.ctx().pointer_interact_pos();+ let delta = crate::panels::layer_drag_edge_scroll(pointer, ui.clip_rect(), dragging, ui.input(|i| i.stable_dt));+ if delta != 0.0 {+ ui.scroll_with_delta(vec2(0.0, delta));+ ui.ctx().request_repaint();+ }ui.spacing_mut().item_spacing.y = 1.0;for (label, items) in grouped_presets(presets) {let items: Vec<&BrushPreset> =diff --git a/crates/ui-egui/src/brushes_tab_tests.rs b/crates/ui-egui/src/brushes_tab_tests.rsindex 4672c062b..0d0a8b790 100644--- a/crates/ui-egui/src/brushes_tab_tests.rs+++ b/crates/ui-egui/src/brushes_tab_tests.rs@@ -51,6 +51,43 @@ fn dragging_a_brush_shows_its_tip_preview() {}}+/// #5741: a brush dragged to the list's bottom edge (or below it) scrolls the list, so it can be+/// dropped on rows out of view; the list used to stay put, and the drag stopped at the last+/// visible row.+#[test]+fn dragging_a_brush_to_the_list_edge_scrolls_the_list() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());+ app.ui.panels.brush_settings = true;+ app.ui.brush_tab = 1;+ app.ui.brushes_panel.view = BrushesView::List;+ app.ui.brushes_panel.collapsed.clear();+ let name = app.session.tools.presets[0].name.clone();+ let (w, h_px) = (1200.0, 520.0);+ let mut h = Harness::builder().with_size(vec2(w, h_px)).build_eframe(move |cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, crate::theme::ThemeKind::ALL[0]);+ app+ });+ h.run_steps(4);+ let start = h.get_by_role_and_label(Role::Button, &name).rect();+ h.hover_at(start.center());+ h.run_steps(1);+ h.event(egui::Event::PointerButton { pos: start.center(), button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE });+ h.run_steps(1);+ h.event(egui::Event::PointerMoved(start.center() + vec2(0.0, 12.0)));+ h.run_steps(2);+ assert!(egui::DragAndDrop::has_payload_of_type::<BrushDrag>(&h.ctx), "the brush is being dragged");+ // Held at the bottom of the window, below the list's last visible row.+ let bottom = egui::pos2(start.center().x, h_px - 2.0);+ for _ in 0..12 {+ h.event(egui::Event::PointerMoved(bottom));+ h.run_steps(1);+ }+ let moved = h.query_by_role_and_label(Role::Button, &name).map(|n| n.rect());+ assert!(moved.is_none_or(|r| r.top() < start.top() - 1.0), "the list scrolled down: {start:?} → {moved:?}");+ h.event(egui::Event::PointerButton { pos: bottom, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE });+ h.run_steps(2);+}+#[test]fn grid_columns_centre_whole_columns_past_the_indent() {// 6 × 44 + 5 × 3 = 279 of the 290 past a 4 pt indent: 5 spare on each side (rounded down).diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex fcdbe4bb2..9fbb765a9 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -2166,7 +2166,7 @@ fn blend_options(groups: bool, current: BlendMode) -> Vec<(BlendMode, &'static s/// list downward (reveals rows above) and negative upward (reveals rows below)./// The speed ramps with proximity to the edge and clamps to the maximum speed when/// dragged outside, using elapsed time instead of assuming a particular refresh rate.-fn layer_drag_edge_scroll(pointer: Option<Pos2>, viewport: Rect, dragging: bool, dt: f32) -> f32 {+pub(crate) fn layer_drag_edge_scroll(pointer: Option<Pos2>, viewport: Rect, dragging: bool, dt: f32) -> f32 {if !dragging || viewport.width() <= 0.0 || viewport.height() <= 0.0 || dt.is_nan() || dt <= 0.0 {return 0.0;}