From bacbfc1ffb7d8252c852f535e9d8edc6ce00edd6 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 12:35:07 +0000 Subject: [PATCH] merge-c4: 3.2: Rotate View Clockwise and Counterclockwise step in screen space, so a mirrored view turns the same way (#4931) --- crates/ui-canvas/src/canvas/tools.rs | 10 ++++++---- crates/ui-canvas/tests/it/canvas/tools.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/crates/ui-canvas/src/canvas/tools.rs b/crates/ui-canvas/src/canvas/tools.rs index aec2dfba2..51d190a12 100644 --- a/crates/ui-canvas/src/canvas/tools.rs +++ b/crates/ui-canvas/src/canvas/tools.rs @@ -139,10 +139,10 @@ pub enum ViewCommands { /// Show the selected layers' bounds, centred. Disabled without them. #[command(label = "Fit Layer(s) on Screen")] FitLayers, - /// Turn the view clockwise by 15 degrees. + /// Turn the view clockwise on screen by 15 degrees, in a mirrored view too. #[command(label = "Rotate View Clockwise")] RotateClockwise, - /// Turn the view counterclockwise by 15 degrees. + /// Turn the view counterclockwise on screen by 15 degrees, in a mirrored view too. #[command(label = "Rotate View Counterclockwise")] RotateCounterclockwise, /// Turn the view back to upright. @@ -202,8 +202,10 @@ impl ViewCommands { zoom::fit_rect(view, bounds, size, pixels_per_point, LAYERS_MARGIN); } } - ViewCommands::RotateClockwise => view.rotation = normalized_angle(view.rotation + ROTATE_STEP_DEG), - ViewCommands::RotateCounterclockwise => view.rotation = normalized_angle(view.rotation - ROTATE_STEP_DEG), + ViewCommands::RotateClockwise => view.rotation = normalized_angle(view.rotation + ViewTurn::screen_delta(ROTATE_STEP_DEG, view.flip_x)), + ViewCommands::RotateCounterclockwise => { + view.rotation = normalized_angle(view.rotation + ViewTurn::screen_delta(-ROTATE_STEP_DEG, view.flip_x)); + } ViewCommands::ResetRotation => view.rotation = 0.0, } *view != before diff --git a/crates/ui-canvas/tests/it/canvas/tools.rs b/crates/ui-canvas/tests/it/canvas/tools.rs index b316baa79..094c8b662 100644 --- a/crates/ui-canvas/tests/it/canvas/tools.rs +++ b/crates/ui-canvas/tests/it/canvas/tools.rs @@ -272,6 +272,28 @@ fn a_hand_pan_reports_its_document_distance_and_its_scroll_all_choice() { rig.release(c + egui::vec2(240.0, 0.0), FRAME); } +/// Rotate View Clockwise turns the image clockwise on screen (screen y points down, so the angle grows), and +/// Counterclockwise the other way, in a mirrored view as in a plain one (#4931). +#[trial] +fn the_rotate_commands_step_fifteen_degrees_on_screen_in_a_flipped_view_too() { + let room = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1000.0, 700.0)); + let probe = Point::new(700.0, 480.0); + let angle = |view: &CanvasView| { + let v = view.to_screen(probe) - view.rect.center(); + f64::from(v.y).atan2(f64::from(v.x)).to_degrees() + }; + let target = ViewTarget::from(DOCUMENT); + for flip_x in [false, true] { + for (command, screen_turn) in [(ViewCommands::RotateClockwise, 15.0), (ViewCommands::RotateCounterclockwise, -15.0)] { + let before = turned(room, 20.0, flip_x); + let mut view = before; + assert!(command.apply(&mut view, &target, 1.0), "{command:?} turns the view"); + let turned_by = (angle(&view) - angle(&before) + 540.0).rem_euclid(360.0) - 180.0; + assert!((turned_by - screen_turn).abs() < 0.01, "flip {flip_x}: {command:?} turns the image {screen_turn} degrees on screen, got {turned_by}"); + } + } +} + #[trial] fn a_rotate_view_drag_follows_the_pointer_in_a_flipped_view_and_shift_steps_fifteen_degrees() { let probe = Point::new(700.0, 480.0);