PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Type move reach: measure on screen with pixel aspect; leave other type to the Type tool
Hector Villarrealb8b8907f7263
diff --git a/crates/ui-egui/src/type_tool_tests.rs b/crates/ui-egui/src/type_tool_tests.rsindex 09aaff253..632d7ccdd 100644--- a/crates/ui-egui/src/type_tool_tests.rs+++ b/crates/ui-egui/src/type_tool_tests.rs@@ -808,6 +808,53 @@ fn a_drag_just_outside_the_typed_text_moves_it() {assert_affine(text(h.state(), id).transform, after.transform);}+/// #5956 review: the reach is screen points as the view draws them, so a pixel-aspect stretch+/// doesn't widen it, and a press on another type layer near the text is still the Type tool's.+#[test]+fn the_move_reach_is_on_screen_and_leaves_other_type_alone() {+ let (mut app, id) = transform_app(false, false, Affine::translate(500.0, 350.0));+ app.ui.view.pixel_aspect_correction = true;+ app.ui.view.pixel_aspect = "anamorphic2To1".into();+ let mut h = harness(1.0, app);+ h.run_steps(1);+ let f = crate::type_transform::frame(h.state_mut()).unwrap();+ let mid = (f.quad[1][1] + f.quad[2][1]) / 2.0;+ let edge = frame_point(h.state(), [f.quad[1][0], mid]);+ let (ctx, view) = (h.ctx.clone(), xf(h.state()));+ assert_eq!(crate::type_transform::cursor(h.state_mut(), &ctx, &view, edge + egui::vec2(30.0, 0.0), Modifiers::NONE), Some(egui::CursorIcon::Move));+ // 50 points out is 25 document points across a 2:1 pixel: out of reach.+ assert_eq!(crate::type_transform::cursor(h.state_mut(), &ctx, &view, edge + egui::vec2(50.0, 0.0), Modifiers::NONE), None);+ let before = text(h.state(), id);+ transform_drag(&mut h, edge + egui::vec2(50.0, 0.0), edge + egui::vec2(110.0, 30.0), Modifiers::NONE, false);+ assert_affine(text(h.state(), id).transform, before.transform);+}++/// #5956 review: a press on another type layer within reach of the text being typed is the Type+/// tool's (it commits and moves to that text), not a move of the edited text.+#[test]+fn a_press_on_other_type_near_the_text_does_not_move_it() {+ let mut app = new_app();+ let id = LayerId(app.run("type.create", json!({"text": "Hi", "size": 32, "x": 300, "y": 420})).unwrap()["layer"].as_u64().unwrap());+ let right = app.session.active().unwrap().doc.layer(id).unwrap().surface().unwrap().content_bounds().x1;+ let other = LayerId(app.run("type.create", json!({"text": "Other", "size": 32, "x": right + 6, "y": 420})).unwrap()["layer"].as_u64().unwrap());+ app.run("layer.select", json!({"layer": id.0})).unwrap();+ super::edit_active(&mut app).unwrap();+ let mut h = harness(1.0, app);+ h.run_steps(1);+ let f = crate::type_transform::frame(h.state_mut()).unwrap();+ let ob = h.state().session.active().unwrap().doc.layer(other).unwrap().surface().unwrap().content_bounds();+ let mid = f64::from(ob.y0 + ob.y1) / 2.0;+ let on_other = frame_point(h.state(), [f64::from(ob.x0) + 4.0, mid]);+ let edge = frame_point(h.state(), [f.quad[1][0], mid]);+ assert!(on_other.x - edge.x > 0.0 && on_other.x - edge.x < 40.0, "the other text is within reach: {} pt", on_other.x - edge.x);+ let (ctx, view) = (h.ctx.clone(), xf(h.state()));+ assert_ne!(crate::type_transform::cursor(h.state_mut(), &ctx, &view, on_other, Modifiers::NONE), Some(egui::CursorIcon::Move));+ let before = text(h.state(), id);+ transform_drag(&mut h, on_other, on_other + egui::vec2(60.0, 30.0), Modifiers::NONE, false);+ assert_affine(text(h.state(), id).transform, before.transform);+ assert_ne!(h.state().ui.text_edit.as_ref().map(|e| e.layer), Some(id.0), "the edit moved on");+}+/// #1091: modifier changes alone draw/hide the oriented frame without touching editing/history.#[test]fn temporary_type_transform_visibility_and_cursors() {diff --git a/crates/ui-egui/src/type_transform.rs b/crates/ui-egui/src/type_transform.rsindex e139edcf6..51ae9a608 100644--- a/crates/ui-egui/src/type_transform.rs+++ b/crates/ui-egui/src/type_transform.rs@@ -144,11 +144,44 @@ fn near_border(t: &TransformSession, p: [f64; 2], tol: f64) -> bool {})}-/// The text's frame when `p` is just outside it, where a plain press moves the text (#5956).+/// Screen points from `p` to the frame's outline, as the view draws it (zoom, rotation and pixel+/// aspect).+fn border_points(app: &PhotocraftApp, t: &TransformSession, p: [f64; 2]) -> f64 {+ let xf = ViewXform::active(app);+ let zoom = f64::from(app.point_zoom().max(0.01));+ let on_screen = |q: [f64; 2]| {+ let d = [q[0] - p[0], q[1] - p[1]];+ match xf {+ Some(xf) => {+ let v = xf.map_vec(egui::vec2(d[0] as f32, d[1] as f32));+ [f64::from(v.x), f64::from(v.y)]+ }+ None => [d[0] * zoom, d[1] * zoom],+ }+ };+ t.quad+ .iter()+ .zip(t.quad.iter().cycle().skip(1))+ .take(4)+ .map(|(a, b)| {+ let (a, b) = (on_screen(*a), on_screen(*b));+ let (dx, dy) = (b[0] - a[0], b[1] - a[1]);+ let len = dx * dx + dy * dy;+ let f = if len > 0.0 { (-a[0] * dx - a[1] * dy) / len } else { 0.0 }.clamp(0.0, 1.0);+ (a[0] + f * dx).hypot(a[1] + f * dy)+ })+ .fold(f64::INFINITY, f64::min)+}++/// The text's frame when `p` is just outside it, where a plain press moves the text (#5956). Over+/// another type layer the press is the Type tool's, as before.fn move_zone(app: &mut PhotocraftApp, p: [f64; 2]) -> Option<TransformSession> {let t = frame(app)?;- let reach = MOVE_REACH_PT / f64::from(app.point_zoom().max(0.01));- (crate::transform_tool::hit(&t, p, 0.0) == Hit::Outside && near_border(&t, p, reach)).then_some(t)+ if crate::transform_tool::hit(&t, p, 0.0) != Hit::Outside || border_points(app, &t, p) > MOVE_REACH_PT {+ return None;+ }+ let other = crate::type_tool::hit_layer(app, p[0], p[1]).is_some_and(|id| id.0 != t.layer);+ (!other).then_some(t)}/// Start a temporary drag of `frame` from `p` on `h`. Returns false when it can't start.