mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Merge pull request #8621 from dotCooCoo/fix/followup-8448
Shapes: a Circle tool release near the press is a click, also after a drag
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
//! the release, the tool shows the circle as a dashed outline (solid once it is more than 50,000
|
||||
//! screen points around) with its points, its center as a small cross, a line from the center to
|
||||
//! each point and, with Measurement Labels on, the diameter by the pointer. The circle is one undo
|
||||
//! step. Escape, a press dropped part way, and an edit, Undo or Redo made outside the tool drop
|
||||
//! step. A press let go within 2 screen points of where it was pressed is a click, also after a
|
||||
//! drag. Escape, a press dropped part way, and an edit, Undo or Redo made outside the tool drop
|
||||
//! the first point. A second press within 3 screen points
|
||||
//! of the first point, or one that snaps to it, is a press on it: let go there (a double-click) it
|
||||
//! places nothing, and dragged out it draws the circle on the diameter it drags out. Where no
|
||||
@@ -137,10 +138,11 @@ impl CircleTool {
|
||||
vec![Action::Exec(c, v)]
|
||||
}
|
||||
|
||||
/// Is the press a drag at `ev`: dragged already, or `ev` is [`DRAG_PX`] or more from the press?
|
||||
/// Is the press let go at `ev` a drag: is `ev` [`DRAG_PX`] or more from the press? A release
|
||||
/// nearer the press is a click, also after a drag that came back to it.
|
||||
fn drags(&self, cx: &ToolContext, ev: &PointerEvent) -> bool {
|
||||
match self.press {
|
||||
Some(Press::First { from, dragged, .. } | Press::Second { from, dragged, .. }) => dragged || ev.pos.distance(from) >= cx.tol(DRAG_PX),
|
||||
Some(Press::First { from, .. } | Press::Second { from, .. }) => ev.pos.distance(from) >= cx.tol(DRAG_PX),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
@@ -156,9 +158,27 @@ impl Tool for CircleTool {
|
||||
return vec![];
|
||||
}
|
||||
// A drag ends where it is let go: the release moves the points as a drag to it would. A
|
||||
// click, or a release within DRAG_PX of the press, keeps the points of the press.
|
||||
if ev.kind == PointerKind::Up && self.drags(cx, ev) {
|
||||
self.pointer(cx, &PointerEvent { kind: PointerKind::Drag, ..*ev });
|
||||
// click, or a release within DRAG_PX of the press (also after a drag), keeps the points of
|
||||
// the press.
|
||||
if ev.kind == PointerKind::Up {
|
||||
if self.drags(cx, ev) {
|
||||
self.pointer(cx, &PointerEvent { kind: PointerKind::Drag, ..*ev });
|
||||
} else if let Some(press) = &mut self.press {
|
||||
let (at, on_first) = match press {
|
||||
Press::First { at, dragged, .. } => {
|
||||
*dragged = false;
|
||||
(*at, false)
|
||||
}
|
||||
Press::Second { at, on_first, dragged, .. } => {
|
||||
*dragged = false;
|
||||
(*at, *on_first)
|
||||
}
|
||||
};
|
||||
// A click on the first point places nothing: the pointer goes back to that point, so
|
||||
// the tool shows no circle.
|
||||
self.pointer = if on_first { self.first } else { Some(at) };
|
||||
self.snap.clear();
|
||||
}
|
||||
}
|
||||
match ev.kind {
|
||||
PointerKind::Move => {
|
||||
|
||||
@@ -120,6 +120,69 @@ fn a_drag_ends_where_it_is_let_go() {
|
||||
assert_eq!(t.pointer(&cx, &ev(up, (381.0, 360.0), Mods::default())), circle(&[(300.0, 300.0), (380.0, 360.0)]));
|
||||
}
|
||||
|
||||
/// A release within 2 screen points of the press is a click also after a drag that came back to
|
||||
/// it: a second press draws the circle on the diameter to the press, a press on the first point
|
||||
/// places nothing, and a first press places the first point.
|
||||
#[test]
|
||||
fn a_release_near_the_press_is_a_click_after_a_drag() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let (s, p) = (Selection::default(), paint());
|
||||
let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) };
|
||||
let mut t = CircleTool::default();
|
||||
click(&mut t, &cx, (300.0, 300.0));
|
||||
assert_eq!(drag(&mut t, &cx, (380.0, 300.0), &[(300.0, 360.0), (381.0, 300.0)], Mods::default()), circle(&[(300.0, 300.0), (380.0, 300.0)]));
|
||||
click(&mut t, &cx, (300.0, 300.0));
|
||||
assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(300.0, 380.0), (301.0, 300.0)], Mods::default()), vec![]);
|
||||
assert!(t.ends_on_escape(&cx), "the first point stays");
|
||||
assert_eq!(click(&mut t, &cx, (380.0, 360.0)), circle(&[(300.0, 300.0), (380.0, 360.0)]));
|
||||
assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(380.0, 300.0), (301.0, 300.0)], Mods::default()), vec![]);
|
||||
assert!(t.ends_on_escape(&cx), "the press placed the first point");
|
||||
assert_eq!(click(&mut t, &cx, (380.0, 360.0)), circle(&[(300.0, 300.0), (380.0, 360.0)]));
|
||||
// Let go near the press straight from far away, the tool shows no circle to the last drag.
|
||||
t.pointer(&cx, &ev(PointerKind::Down, (300.0, 300.0), Mods::default()));
|
||||
t.pointer(&cx, &ev(PointerKind::Drag, (380.0, 300.0), Mods::default()));
|
||||
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (301.0, 300.0), Mods::default())), vec![]);
|
||||
assert_eq!(preview(&t.overlays(&cx)), None);
|
||||
t.pointer(&cx, &ev(PointerKind::Down, (300.0, 300.0), Mods::default()));
|
||||
t.pointer(&cx, &ev(PointerKind::Drag, (300.0, 380.0), Mods::default()));
|
||||
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (301.0, 300.0), Mods::default())), vec![]);
|
||||
assert_eq!(preview(&t.overlays(&cx)), None);
|
||||
assert!(t.ends_on_escape(&cx));
|
||||
}
|
||||
|
||||
/// A click within 3 screen points of the first point, also one dragged away and let go where it
|
||||
/// was pressed, places nothing and leaves no circle shown.
|
||||
#[test]
|
||||
fn a_click_near_the_first_point_shows_no_circle() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let (s, p) = (Selection::default(), paint());
|
||||
let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) };
|
||||
let mut t = CircleTool::default();
|
||||
click(&mut t, &cx, (300.0, 300.0));
|
||||
assert_eq!(drag(&mut t, &cx, (302.0, 300.0), &[(302.0, 380.0), (302.0, 300.0)], Mods::default()), vec![]);
|
||||
assert_eq!(preview(&t.overlays(&cx)), None);
|
||||
assert_eq!(click(&mut t, &cx, (302.0, 300.0)), vec![]);
|
||||
assert_eq!(preview(&t.overlays(&cx)), None);
|
||||
assert!(t.ends_on_escape(&cx), "the first point stays");
|
||||
assert_eq!(click(&mut t, &cx, (380.0, 360.0)), circle(&[(300.0, 300.0), (380.0, 360.0)]));
|
||||
}
|
||||
|
||||
/// A press on the first point, dragged to snap to the rectangle's corner anchor and let go near
|
||||
/// the press, leaves no guides of the drag.
|
||||
#[test]
|
||||
fn a_release_near_the_press_hides_the_guides_of_the_drag() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let (s, p) = (Selection::default(), paint());
|
||||
let cx = cx(&d, &s, &p);
|
||||
let mut t = CircleTool::default();
|
||||
click(&mut t, &cx, (300.0, 300.0));
|
||||
t.pointer(&cx, &ev(PointerKind::Down, (300.0, 300.0), Mods::default()));
|
||||
t.pointer(&cx, &ev(PointerKind::Drag, (201.0, 201.0), Mods::default()));
|
||||
assert!(!t.snap.guides().is_empty(), "the drag snapped to the corner anchor");
|
||||
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (301.0, 300.0), Mods::default())), vec![]);
|
||||
assert!(t.snap.guides().is_empty(), "{:?}", t.snap.guides());
|
||||
}
|
||||
|
||||
/// Three points on one line show no circle, and the release draws nothing and starts afresh. A
|
||||
/// circle past the canvas is not shown either.
|
||||
#[test]
|
||||
|
||||
@@ -6883,6 +6883,7 @@ the release, the tool shows the circle as a dashed outline (solid once it is mor
|
||||
with its points, a small cross at its center, a line from
|
||||
the center to each point and, with Measurement Labels on, the diameter by the pointer. Three different points on one
|
||||
line, or a circle past the canvas, show "Circle too large" by the pointer instead, and the release draws nothing.
|
||||
A press let go within 2 screen points of where it was pressed is a click, also after a drag that came back to it.
|
||||
Escape, a dropped press, and an edit, Undo or Redo made outside the tool drop the first point. A second press within 3
|
||||
screen points of the first point, or one that snaps to it, is a press on it: let go there (a double-click), it places no second point, and
|
||||
dragged out, it draws the circle on the diameter it drags out.
|
||||
|
||||
Reference in New Issue
Block a user