PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Crop: Straighten is one box Undo step (#7127)
David Mannb052fd591ef2
diff --git a/crates/ui-egui/src/crop_straighten.rs b/crates/ui-egui/src/crop_straighten.rsindex 9f8128b80..d3ea8e479 100644--- a/crates/ui-egui/src/crop_straighten.rs+++ b/crates/ui-egui/src/crop_straighten.rs@@ -231,6 +231,21 @@ mod tests {assert_eq!(frame_angle([0.0, 0.0], [f64::INFINITY, 1.0], 1.0), None);}+ /// A straighten is one box Undo step (#3145): Undo turns the frame back instead of undoing the+ /// document under the pending crop, and Redo turns it again.+ #[test]+ fn straighten_is_a_box_undo_step() {+ let mut app = app(SampleType::U8);+ let before = (app.ui.crop_rect, app.ui.crop_angle);+ drag(&mut app, &[[0.0, 0.0], [100.0, 17.6]], CMD);+ let turned = (app.ui.crop_rect, app.ui.crop_angle);+ assert!(turned.1.abs() > 5.0, "{turned:?}");+ assert!(crate::crop_ui::intercept(&mut app, "edit.undo").is_some(), "Undo steps the box");+ assert_eq!((app.ui.crop_rect, app.ui.crop_angle), before);+ assert!(crate::crop_ui::intercept(&mut app, "edit.redo").is_some());+ assert_eq!((app.ui.crop_rect, app.ui.crop_angle), turned);+ }+#[test]fn the_fitted_frame_is_the_largest_of_its_proportions_inside_the_canvas() {// Upright, the canvas's own proportions fill it.diff --git a/crates/ui-egui/src/crop_ui.rs b/crates/ui-egui/src/crop_ui.rsindex f1df63ff1..bffc1b46e 100644--- a/crates/ui-egui/src/crop_ui.rs+++ b/crates/ui-egui/src/crop_ui.rs@@ -706,9 +706,17 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> boolif crate::crop_straighten::pointer(app, ev, mods) {claim(app);// Default mode: the image turns so the line ends up level (the press keeps its point).+ // The turn is one box Undo step, like any other frame gesture.match ev {- ToolEvent::Down { .. } => crate::crop_mode::sync(app, Some(p)),- _ => crate::crop_mode::sync_frame(app),+ ToolEvent::Down { .. } => {+ app.crop.press_step = Some(step_of(app));+ crate::crop_mode::sync(app, Some(p));+ }+ ToolEvent::Move { .. } => crate::crop_mode::sync_frame(app),+ ToolEvent::Up { .. } => {+ crate::crop_mode::sync_frame(app);+ push_press_step(app);+ }}return true;}@@ -774,18 +782,23 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool}_ => {}}- if let Some(before) = app.crop.press_step.take()- && step_of(app) != before- {- app.crop.undo.push(before);- app.crop.redo.clear();- }+ push_press_step(app);}}crate::crop_mode::sync_frame(app);true}+/// On release: the frame state at the press becomes a box Undo step when the gesture changed it.+fn push_press_step(app: &mut PhotocraftApp) {+ if let Some(before) = app.crop.press_step.take()+ && step_of(app) != before+ {+ app.crop.undo.push(before);+ app.crop.redo.clear();+ }+}+/// The frame follows the pointer at `p`.fn update(app: &mut PhotocraftApp, p: [f64; 2], mods: Modifiers) {let ratio = preset_ratio(app);