mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(ui): Reset keeps the box's preview state and ratio preset (#9730)
Undo after Reset now brings back the pixels beyond the frame: the box Undo step also keeps whether the frame is being edited. Reset fits the first frame to the ratio preset or output size picked in the bar, as a new frame is, so a 1:1 preset does not end up with the 2:1 canvas.
This commit is contained in:
1 parent
03823f0d02
commit
22765eb352
2 files changed
+25
-1
No files matched your search
@@ -75,6 +75,8 @@ struct CropStep {
|
||||
rect: Option<[f64; 4]>,
|
||||
angle: f64,
|
||||
default_frame: bool,
|
||||
/// The canvas shows the pixels past the frame ([`shows_beyond_canvas`]).
|
||||
editing: bool,
|
||||
}
|
||||
|
||||
/// A crop gesture in progress. Rects are `[x0, y0, x1, y1]` in document coordinates.
|
||||
@@ -521,6 +523,8 @@ pub fn reset(app: &mut PhotocraftApp) {
|
||||
app.crop.press_step = None;
|
||||
claim(app);
|
||||
crate::crop_straighten::reset(app);
|
||||
// As a new default frame is: held to the ratio preset (or output size) picked in the bar.
|
||||
fit_frame(app);
|
||||
if step_of(app) != before {
|
||||
app.crop.undo.push(before);
|
||||
app.crop.redo.clear();
|
||||
@@ -538,7 +542,7 @@ pub fn clear_history(app: &mut PhotocraftApp) {
|
||||
|
||||
/// The frame's current state, as an undo step.
|
||||
fn step_of(app: &PhotocraftApp) -> CropStep {
|
||||
CropStep { rect: app.ui.crop_rect, angle: app.ui.crop_angle, default_frame: app.crop.default_frame }
|
||||
CropStep { rect: app.ui.crop_rect, angle: app.ui.crop_angle, default_frame: app.crop.default_frame, editing: app.crop.editing }
|
||||
}
|
||||
|
||||
/// Put a frame state back.
|
||||
@@ -546,6 +550,7 @@ fn apply_step(app: &mut PhotocraftApp, s: CropStep) {
|
||||
app.ui.crop_rect = s.rect;
|
||||
app.ui.crop_angle = s.angle;
|
||||
app.crop.default_frame = s.default_frame;
|
||||
app.crop.editing = s.editing;
|
||||
}
|
||||
|
||||
/// The pending frame, its box Undo/Redo and the view's turn, kept while `image.crop` runs so a
|
||||
|
||||
@@ -127,8 +127,10 @@ fn reset_frames_the_canvas_again_and_can_be_undone() {
|
||||
assert_eq!(app.session.active().unwrap().doc.size, Size::new(200, 100), "nothing is cropped");
|
||||
|
||||
// The box's own Undo brings the drawn frame back, and Redo resets it again.
|
||||
assert!(!shows_beyond_canvas(&app), "the reset frame is not being edited");
|
||||
assert!(intercept(&mut app, "edit.undo").is_some());
|
||||
assert_eq!(app.ui.crop_rect, Some([50.0, 20.0, 120.0, 70.0]));
|
||||
assert!(shows_beyond_canvas(&app), "the drawn frame is being edited again: the canvas shows the pixels past it");
|
||||
assert!(intercept(&mut app, "edit.redo").is_some());
|
||||
assert_eq!(app.ui.crop_rect, Some([0.0, 0.0, 200.0, 100.0]));
|
||||
|
||||
@@ -150,6 +152,23 @@ fn reset_frames_the_canvas_again_and_can_be_undone() {
|
||||
assert!(!modified(&app));
|
||||
}
|
||||
|
||||
/// Reset frames the canvas as a new frame is: held to the ratio preset picked in the bar.
|
||||
#[test]
|
||||
fn reset_holds_the_frame_to_the_ratio_preset() {
|
||||
let mut app = app(SampleType::U8);
|
||||
ensure_frame(&mut app);
|
||||
drag(&mut app, &[[50.0, 20.0], [80.0, 40.0], [120.0, 70.0]], NONE);
|
||||
let drawn = Some([50.0, 20.0, 120.0, 70.0]);
|
||||
assert_eq!(app.ui.crop_rect, drawn);
|
||||
// A 1:1 preset on the 200 x 100 canvas: the first frame is the largest square, centred.
|
||||
app.ui.tool_options.crop_ratio = "1:1".into();
|
||||
reset(&mut app);
|
||||
assert_eq!(app.ui.crop_rect, Some([50.0, 0.0, 150.0, 100.0]), "not the whole canvas, a 2:1 frame under a 1:1 preset");
|
||||
assert!(!modified(&app) && app.crop.default_frame);
|
||||
assert!(intercept(&mut app, "edit.undo").is_some());
|
||||
assert_eq!(app.ui.crop_rect, drawn, "Undo brings the drawn frame back");
|
||||
}
|
||||
|
||||
/// #9730: the Crop tool's options bar has a Reset button beside Cancel and Commit, live once
|
||||
/// the frame was changed.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user