diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index eb2c072176e..dcad4356e38 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -1152,6 +1152,11 @@ fn parse_pointer_event(i: usize, e: &Value) -> std::result::Result bool { + // A primary release ends a held locator press wherever it lands (another dialog on top, Space + // held, the dialog closed), so a later hover never drags the preview; the event goes on. + if matches!(s.ev, ToolEvent::Up { .. }) && !g.secondary && !g.middle { + crate::filter_preview_ui::clear_pointer_state(app); + } pointer_eyedropper_took(app, ctx, g, s) || color_range_took(app, g, s) || preview_locator_took(app, g, s) @@ -1160,14 +1165,14 @@ fn pointer_event_intercepted(app: &mut PhotocraftApp, ctx: &egui::Context, g: &P /// A filter dialog with a preview window on top: the image is its locator, as for the mouse /// (#9648). A press or drag with the primary button centres the window there; every other event -/// is consumed too, so nothing reaches the tool under the dialog, except the release that ends a -/// tool gesture begun before the dialog opened. +/// is consumed too, so nothing reaches the tool under the dialog, except the moves and release of +/// a tool gesture begun before the dialog opened, which finish it along the path they draw. fn preview_locator_took(app: &mut PhotocraftApp, g: &PointerGesture, s: &PointerSample) -> bool { if crate::filter_preview_ui::locator(app).is_none() { return false; } let (down, up) = (matches!(s.ev, ToolEvent::Down { .. }), matches!(s.ev, ToolEvent::Up { .. })); - if up && !g.secondary && !g.middle && app.drag.is_some() { + if !down && !g.secondary && !g.middle && app.drag.is_some() { return false; } if !g.secondary && !g.middle && !g.space { diff --git a/crates/ui-egui/src/dialogs/filter_preview_ui.rs b/crates/ui-egui/src/dialogs/filter_preview_ui.rs index 8c3ca50e961..af172139800 100644 --- a/crates/ui-egui/src/dialogs/filter_preview_ui.rs +++ b/crates/ui-egui/src/dialogs/filter_preview_ui.rs @@ -197,6 +197,14 @@ pub(crate) fn pointer_event(app: &mut PhotocraftApp, down: bool, up: bool, x: f6 } } +/// A primary `ui.pointer` release, wherever it went: no locator press stays held in any open +/// dialog, even one that was not on top or not taking the pointer when the button came up. +pub(crate) fn clear_pointer_state(app: &mut PhotocraftApp) { + for d in &mut app.ui.dialogs { + d.fields.remove(POINTER_DOWN_FIELD); + } +} + /// The zoom levels the − / + buttons step through, like the Filter Gallery's. const ZOOM_STEPS: [f32; 7] = [0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0]; diff --git a/crates/ui-egui/src/filter_preview_locator_tests.rs b/crates/ui-egui/src/filter_preview_locator_tests.rs index 9aa43b73651..c509d6ffec2 100644 --- a/crates/ui-egui/src/filter_preview_locator_tests.rs +++ b/crates/ui-egui/src/filter_preview_locator_tests.rs @@ -226,7 +226,8 @@ fn ui_pointer_centres_only_while_the_press_is_held() { assert!(near(centre(&h), [80.0, 60.0]), "after the release a move is a hover again: {:?}", centre(&h)); } -/// A Brush stroke an agent began before the dialog opened still ends: its release reaches the tool. +/// A Brush stroke an agent began before the dialog opened still ends along its own path: its moves +/// and release reach the tool, not the locator. #[test] fn a_tool_gesture_begun_before_the_dialog_still_ends_under_it() { let mut h = harness(None, 0.0); @@ -236,8 +237,35 @@ fn a_tool_gesture_begun_before_the_dialog_still_ends_under_it() { crate::filter_dialog::open(h.state_mut(), "filter.sharpen.smartSharpen").unwrap(); h.run_steps(2); assert!(h.state().drag.is_some(), "the stroke is still open under the dialog"); - pointer(&mut h, json!([{"kind": "up", "x": 80, "y": 30}])); + pointer(&mut h, json!([{"kind": "move", "x": 80, "y": 120}, {"kind": "move", "x": 120, "y": 120}])); + let points = h.state().drag.as_ref().map(|d| d.points.clone()).unwrap_or_default(); + assert!(points.iter().any(|p| p[1] > 100.0), "the moves under the dialog reached the stroke: {points:?}"); + pointer(&mut h, json!([{"kind": "up", "x": 120, "y": 120}])); assert!(h.state().drag.is_none(), "the release reached the Brush"); assert_eq!(edits(&h).1, before.1 + 1, "the stroke is one history step"); - assert!(near(centre(&h), [200.0, 150.0]), "the release is not a locator press: {:?}", centre(&h)); + assert!(near(centre(&h), [200.0, 150.0]), "the stroke's moves and release are not locator presses: {:?}", centre(&h)); +} + +/// A release the locator doesn't take (Space held, or another dialog on top) still ends its press, +/// so a later hover doesn't drag the preview with no button down. +#[test] +fn a_release_elsewhere_ends_the_locator_press() { + let mut h = harness(Some("filter.sharpen.smartSharpen"), 0.0); + pointer(&mut h, json!([{"kind": "down", "x": 40, "y": 30}])); + assert!(near(centre(&h), [40.0, 30.0]), "{:?}", centre(&h)); + let (req, _rx) = crate::control::ControlRequest::new("ui.pointer", json!({"events": [{"kind": "up", "x": 40, "y": 30}], "space": true})); + let _ = crate::control::handle(h.state_mut(), &egui::Context::default(), &req); + h.run_steps(2); + pointer(&mut h, json!([{"kind": "move", "x": 120, "y": 90}])); + assert!(near(centre(&h), [40.0, 30.0]), "a Space-held release ends the press: {:?}", centre(&h)); + + // The release lands on a Color Picker opened over the dialog. + pointer(&mut h, json!([{"kind": "down", "x": 60, "y": 50}])); + assert!(near(centre(&h), [60.0, 50.0]), "{:?}", centre(&h)); + let picker = crate::color_picker_ui::open(h.state_mut(), "foreground"); + pointer(&mut h, json!([{"kind": "up", "x": 60, "y": 50}])); + h.state_mut().ui.close_dialog(picker); + h.run_steps(2); + pointer(&mut h, json!([{"kind": "move", "x": 120, "y": 90}])); + assert!(near(centre(&h), [60.0, 50.0]), "a release on another dialog ends the press: {:?}", centre(&h)); }