From 7cdb227a9f1dbbc942df484efd9e67f659e92dab Mon Sep 17 00:00:00 2001 From: Nigel Ihza Firdausy <106657905+Ni-zav@users.noreply.github.com> Date: Thu, 8 Oct 2026 22:36:59 +0700 Subject: [PATCH] fix(ui): ignore hidden canvas guides during Move tool hit testing (#1258) --- crates/ui-egui/src/rulers.rs | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/rulers.rs b/crates/ui-egui/src/rulers.rs index 562d339360..b78e130294 100644 --- a/crates/ui-egui/src/rulers.rs +++ b/crates/ui-egui/src/rulers.rs @@ -124,7 +124,9 @@ pub fn draw_guides(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform, /// Existing guide under a document point (within 4 screen px). pub fn guide_at(app: &PhotocraftApp, x: f64, y: f64) -> Option<(bool, usize)> { - if !app.ui.extras.guides || app.ui.extras.lock_guides { + // Hidden canvas guides are not interactive: the Move tool must reach the layer below. + // Keep hit testing consistent with the visibility gate in canvas::draw. + if !app.ui.extras.guides || !app.ui.view.shows(app.ui.view.show.canvas_guides) || app.ui.extras.lock_guides { return None; } let doc = &app.session.active()?.doc; @@ -269,6 +271,45 @@ mod tests { assert_eq!(tick_step(0.25), 500.0); } + #[test] + fn hidden_guides_are_not_hit_tested() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.session.execute("file.new", json!({"width": 200, "height": 100})).unwrap(); + app.sync_views(); + app.session.execute("view.newGuide", json!({"orientation": "vertical", "position": 50})).unwrap(); + app.session.execute("view.newGuide", json!({"orientation": "horizontal", "position": 25})).unwrap(); + let positions = app.session.active().unwrap().doc.guides.clone(); + + // Visible, unlocked guides remain interactive in either orientation. + assert_eq!(guide_at(&app, 50.0, 10.0), Some((true, 0))); + assert_eq!(guide_at(&app, 10.0, 25.0), Some((false, 0))); + + // All ways to hide the canvas guides must also disable hit testing. + app.ui.extras.guides = false; + assert_eq!(guide_at(&app, 50.0, 10.0), None); + assert_eq!(guide_at(&app, 10.0, 25.0), None); + app.ui.extras.guides = true; + + app.ui.view.show.canvas_guides = false; + assert_eq!(guide_at(&app, 50.0, 10.0), None); + assert_eq!(guide_at(&app, 10.0, 25.0), None); + app.ui.view.show.canvas_guides = true; + + app.ui.view.extras = false; + assert_eq!(guide_at(&app, 50.0, 10.0), None); + assert_eq!(guide_at(&app, 10.0, 25.0), None); + app.ui.view.extras = true; + + // Hiding/showing must not change the stored guide positions. + assert_eq!(app.session.active().unwrap().doc.guides, positions); + assert_eq!(guide_at(&app, 50.0, 10.0), Some((true, 0))); + assert_eq!(guide_at(&app, 10.0, 25.0), Some((false, 0))); + + app.ui.extras.lock_guides = true; + assert_eq!(guide_at(&app, 50.0, 10.0), None); + assert_eq!(guide_at(&app, 10.0, 25.0), None); + } + #[test] fn guide_drags_create_move_and_delete() { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());