diff --git a/crates/ui-egui/src/panels/toolbar.rs b/crates/ui-egui/src/panels/toolbar.rs index e3cf32a56c..5bfdd4983b 100644 --- a/crates/ui-egui/src/panels/toolbar.rs +++ b/crates/ui-egui/src/panels/toolbar.rs @@ -21,6 +21,9 @@ mod toolbar_docking_tests; #[path = "toolbar_flyout_mark_tests.rs"] mod toolbar_flyout_mark_tests; #[cfg(test)] +#[path = "toolbar_rotate_view_reset_tests.rs"] +mod toolbar_rotate_view_reset_tests; +#[cfg(test)] #[path = "toolbar_tab_reveal_tests.rs"] mod toolbar_tab_reveal_tests; @@ -318,7 +321,7 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { if let Some(tool) = out.select { crate::tool_memory::select(app, tool); } - // A double click on Hand fits the image on screen, on Zoom shows it at 100% (Photoshop); with no document open there + // A double click on Hand fits the image on screen, Rotate View resets its angle, and Zoom shows it at 100%; with no document open there // is nothing to do. The framework reports no double click after a modified click. match out.double_clicked { Some(Tool::Hand) => { @@ -327,6 +330,9 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { Some(Tool::Zoom) => { let _ = crate::menus::invoke(app, &ctx, "view.actualPixels", json!({})); } + Some(Tool::RotateView) => { + let _ = crate::menus::invoke(app, &ctx, "view.resetView", json!({})); + } _ => {} } if let Some(next) = &out.last_used { diff --git a/crates/ui-egui/src/panels/toolbar_rotate_view_reset_tests.rs b/crates/ui-egui/src/panels/toolbar_rotate_view_reset_tests.rs new file mode 100644 index 0000000000..64a9e28e8e --- /dev/null +++ b/crates/ui-egui/src/panels/toolbar_rotate_view_reset_tests.rs @@ -0,0 +1,98 @@ +//! Double-clicking the Rotate View icon in the Hand slot runs Reset View (#18744). + +use super::*; +use egui::{Modifiers, PointerButton}; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; + +fn harness(documents: usize) -> Harness<'static, Box> { + let mut h = Harness::builder().with_size(egui::vec2(1200.0, 1100.0)).with_max_steps(64).build_eframe(move |cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, crate::theme::AppTheme::pro()); + let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default()); + for _ in 0..documents { + app.run("file.new", json!({"width": 3000, "height": 2000})).expect("new document"); + } + app.ui.tool = Tool::RotateView; + app.ui.remember_group_tool(Tool::RotateView); + app + }); + h.run_steps(4); + h +} + +/// The shown tool's rail button, excluding the options-bar button and the flyout corner. +fn slot(h: &Harness<'static, Box>, label: &str) -> egui::Pos2 { + h.query_all_by_label(label).rfind(|node| node.rect().width() >= 16.0).expect("the toolbar shows the tool").rect().center() +} + +fn click(h: &mut Harness<'static, Box>, at: egui::Pos2) { + h.event(egui::Event::PointerMoved(at)); + for pressed in [true, false] { + h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.run_steps(1); + } +} + +#[test] +fn double_click_on_the_rotate_view_slot_resets_only_the_active_angle() { + let mut h = harness(2); + h.state_mut().ui.views[0].rotation = -23.0; + let active = &mut h.state_mut().ui.views[1]; + active.rotation = 37.0; + active.zoom = 0.75; + active.center = [1400.0, 900.0]; + h.run_steps(4); + let before = h.state().ui.views[1].clone(); + let other = h.state().ui.views[0].clone(); + let doc = h.state().session.active().expect("active document").doc.clone(); + let history = h.state().session.active().expect("active document").history.past_len(); + let at = slot(&h, "Rotate View Tool"); + click(&mut h, at); + assert_eq!(h.state().ui.views[1].rotation, 37.0, "one click only selects Rotate View"); + click(&mut h, at); + h.run_steps(4); + let after = &h.state().ui.views[1]; + assert_eq!(after.rotation, 0.0, "the second click runs Reset View"); + assert_eq!((after.zoom, after.center), (before.zoom, before.center)); + assert_eq!(h.state().ui.views[0], other, "the other document keeps its view"); + assert_eq!(h.state().ui.tool, Tool::RotateView); + let session = h.state().session.active().expect("active document"); + assert!(std::sync::Arc::ptr_eq(&session.doc, &doc)); + assert_eq!(session.history.past_len(), history); +} + +#[test] +fn double_click_on_rotate_view_without_a_document_keeps_the_tool_selected() { + let mut h = harness(0); + let at = slot(&h, "Rotate View Tool"); + click(&mut h, at); + click(&mut h, at); + h.run_steps(4); + assert_eq!(h.state().ui.tool, Tool::RotateView); + assert!(h.state().ui.views.is_empty()); + assert!(h.state().session.active().is_none()); +} + +#[test] +fn hand_and_zoom_keep_their_double_click_actions() { + for (tool, label) in [(Tool::Hand, "Hand Tool"), (Tool::Zoom, "Zoom Tool")] { + let mut h = harness(1); + h.state_mut().ui.tool = tool; + h.state_mut().ui.remember_group_tool(tool); + let view = &mut h.state_mut().ui.views[0]; + view.zoom = 0.75; + view.center = [1400.0, 900.0]; + h.run_steps(4); + let at = slot(&h, label); + click(&mut h, at); + click(&mut h, at); + h.run_steps(4); + let view = &h.state().ui.views[0]; + if tool == Tool::Hand { + assert!(view.zoom > 0.0 && view.zoom < 0.75, "Hand fits the large document on screen"); + assert_eq!(view.center, [1500.0, 1000.0]); + } else { + assert_eq!(view.zoom, 1.0, "Zoom shows actual pixels"); + } + } +}