Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Crop tool: the drawing crosshair, not the move cursor, inside the untouched default frame (fixes #4461) (#4481)

Marco Arnulfo2cb3b70d97fb
diff --git a/crates/ui-egui/src/crop_ui.rs b/crates/ui-egui/src/crop_ui.rs
index df25c568f..54ec3795d 100644
--- a/crates/ui-egui/src/crop_ui.rs
+++ b/crates/ui-egui/src/crop_ui.rs
@@ -863,7 +863,8 @@ pub(crate) fn resize_ratio(app: &PhotocraftApp, rect: [f64; 4], mods: Modifiers)
preset_ratio(app).or(if mods.shift { keep } else { None })
}
-/// Cursor over the canvas at document point `p`: resize arrows on the edges, move inside.
+/// Cursor over the canvas at document point `p`: resize arrows on the edges, move inside (the
+/// crosshair inside the untouched default frame, where a drag draws a new one).
pub fn cursor(app: &PhotocraftApp, p: [f64; 2]) -> Option<CursorIcon> {
if app.ui.tool != Tool::Crop {
return None;
@@ -882,6 +883,8 @@ pub fn cursor(app: &PhotocraftApp, p: [f64; 2]) -> Option<CursorIcon> {
Some(match h {
// The arrow as the handle faces on screen: the frame's turn plus the view's.
Hit::Handle(hx, hy) => resize_icon(hx, hy, deg + f64::from(crate::crop_mode::view_rotation(app))),
+ // Inside the untouched default frame a drag draws a new one (`pointer`), so nothing moves (#4461).
+ Hit::Inside if app.crop.default_frame => CursorIcon::Crosshair,
Hit::Inside => CursorIcon::Move,
// Photoshop's curved two-headed arrow (`draw_turn_cursor`, from `turn_cursor_dir`).
Hit::Outside => CursorIcon::None,
@@ -1787,6 +1790,20 @@ mod tests {
assert_eq!(cursor(&app, [60.0, 40.0]), None);
}
+ /// #4461: inside the untouched default frame a drag draws a new frame, so the pointer is the
+ /// drawing crosshair there, not the move cursor; once the frame is changed a drag moves it.
+ #[test]
+ fn cursor_inside_the_default_frame_draws() {
+ let mut app = app(SampleType::U8);
+ ensure_frame(&mut app);
+ assert!(app.crop.default_frame && app.ui.crop_rect == Some([0.0, 0.0, 200.0, 100.0]));
+ assert_eq!(cursor(&app, [100.0, 50.0]), Some(CursorIcon::Crosshair));
+ assert_eq!(cursor(&app, [200.0, 50.0]), Some(CursorIcon::ResizeHorizontal), "its handles still resize");
+ drag(&mut app, &[[200.0, 50.0], [150.0, 50.0]], NONE);
+ assert!(!app.crop.default_frame && app.ui.crop_rect == Some([0.0, 0.0, 150.0, 100.0]));
+ assert_eq!(cursor(&app, [100.0, 50.0]), Some(CursorIcon::Move));
+ }
+
/// One key press through the app's keyboard handling (`shortcuts::handle`).
fn key(app: &mut PhotocraftApp, key: egui::Key, modifiers: Modifiers) {
let ctx = egui::Context::default();