Place cursor: a drag under the threshold is a click, with no frame drawn

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
paaspaas00andClaude Opus 5.5 committed 2026-10-21 15:05:00 +02:00
1 parent 53b8b04141
commit 098613b75d
2 files changed
+21 -2

No files matched your search

+9
View File
@@ -517,6 +517,15 @@ Y: 100.00%")),
s.pointer(&PointerEvent::new(PointerKind::Up, 180.0, 401.0), v).unwrap();
let it = s.doc().unwrap().doc.spreads[0].items.last().unwrap().clone();
assert_eq!(it.bounds(), natural, "the frame previewed");
// A drag under the threshold is a click: no frame drawn, the graphic at actual size where
// the press was.
s.execute("place.load", &json!({"base64": cmd::base64_encode(&png), "name": "a.png"})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 100.0, 500.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, 102.5, 501.25), v).unwrap();
assert!(!s.overlays(v).iter().any(|o| matches!(o, Overlay::Marquee(_))), "no frame yet");
s.pointer(&PointerEvent::new(PointerKind::Up, 102.5, 501.25), v).unwrap();
let it = s.doc().unwrap().doc.spreads[0].items.last().unwrap().clone();
assert_eq!(it.bounds(), designcraft_geom::Rect::new(100.0, 500.0, 140.0, 520.0), "actual size at the press");
}
#[test]
+12 -2
View File
@@ -133,7 +133,8 @@ impl Tool for PlaceGun {
let Some(a) = self.start.take() else { return vec![] };
let Some((sr, sa)) = cx.layout.spread_at(a) else { return vec![] };
let b = cx.layout.to_spread(sr, ev.pos);
if (ev.pos - a).hypot() < cx.tol(3.0)
let click = (ev.pos - a).hypot() < cx.tol(3.0);
if click
&& let Some((_, id)) = cx.hit(a)
&& cx
.doc
@@ -142,6 +143,10 @@ impl Tool for PlaceGun {
{
return vec![Action::Exec("place.drop".into(), json!({"frame": id.0}))];
}
// Under the drag threshold it's a click, as the overlay shows: actual size there.
if click {
return vec![Action::Exec("place.drop".into(), json!({"spread": crate::spread_json(sr), "x": sa.x, "y": sa.y}))];
}
// The frame the drag drew: at the graphic's proportions from where it started.
let r = cx.loaded.map_or_else(|| designcraft_geom::Rect::from_points(sa, b), |size| proportional(sa, b, size).0);
vec![Action::Exec(
@@ -154,9 +159,14 @@ impl Tool for PlaceGun {
}
fn overlays(&self, cx: &ToolContext) -> Vec<crate::Overlay> {
let Some(a) = self.start else { return vec![] };
let (Some(size), true) = (cx.loaded, (self.cur - a).hypot() >= cx.tol(3.0)) else {
let Some(size) = cx.loaded else {
return vec![crate::Overlay::Marquee(designcraft_geom::Rect::from_points(a, self.cur))];
};
// Under the drag threshold the release is a click (actual size where it was pressed):
// no frame is drawn yet, the loaded cursor shows what lands.
if (self.cur - a).hypot() < cx.tol(3.0) {
return vec![];
}
// As InDesign: the frame the graphic will fill, and its scale beside the pointer.
let (r, k) = drawn_frame(a, self.cur, size);
let pct = format!("{:.2}%", k * 100.0);