mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 22:34:09 +00:00
Merge feat/circle-tool into feat/circle-tool-options
This commit is contained in:
@@ -253,6 +253,16 @@ impl CircleTool {
|
||||
}
|
||||
self.draw(&[a, b, at])
|
||||
}
|
||||
|
||||
/// Is the press a drag at `ev`: dragged already, or `ev` is [`DRAG_PX`] or more from the press?
|
||||
fn drags(&self, cx: &ToolContext, ev: &PointerEvent) -> bool {
|
||||
match self.press {
|
||||
Some(Press::First { from, dragged, .. } | Press::Second { from, dragged, .. } | Press::Third { from, dragged, .. }) => {
|
||||
dragged || ev.pos.distance(from) >= cx.tol(DRAG_PX)
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Tool for CircleTool {
|
||||
@@ -264,6 +274,11 @@ impl Tool for CircleTool {
|
||||
if !ev.pos.is_finite() {
|
||||
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 });
|
||||
}
|
||||
match ev.kind {
|
||||
PointerKind::Move => {
|
||||
let leave = self.leave(cx, ev.mods);
|
||||
|
||||
@@ -269,6 +269,32 @@ fn check_options_takes_only_the_values_the_options_take() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A drag ends where it is let go, also when the release is away from the last drag: from a first
|
||||
/// press, from a second press, and from a press on the first point. A release within 2 screen
|
||||
/// points of a second press is still a click and keeps the point of the press.
|
||||
#[test]
|
||||
fn a_drag_ends_where_it_is_let_go() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let (s, p) = (Selection::default(), paint());
|
||||
let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) };
|
||||
let (down, drag, up) = (PointerKind::Down, PointerKind::Drag, PointerKind::Up);
|
||||
let mut t = CircleTool::default();
|
||||
t.pointer(&cx, &ev(down, (300.0, 300.0), Mods::default()));
|
||||
t.pointer(&cx, &ev(drag, (380.0, 300.0), Mods::default()));
|
||||
assert_eq!(t.pointer(&cx, &ev(up, (400.0, 300.0), Mods::default())), circle(&[(300.0, 300.0), (400.0, 300.0)]));
|
||||
click(&mut t, &cx, (300.0, 300.0));
|
||||
t.pointer(&cx, &ev(down, (380.0, 300.0), Mods::default()));
|
||||
t.pointer(&cx, &ev(drag, (300.0, 340.0), Mods::default()));
|
||||
assert_eq!(t.pointer(&cx, &ev(up, (300.0, 360.0), Mods::default())), circle(&[(300.0, 300.0), (380.0, 300.0), (300.0, 360.0)]));
|
||||
click(&mut t, &cx, (300.0, 300.0));
|
||||
t.pointer(&cx, &ev(down, (300.0, 300.0), Mods::default()));
|
||||
t.pointer(&cx, &ev(drag, (300.0, 380.0), Mods::default()));
|
||||
assert_eq!(t.pointer(&cx, &ev(up, (300.0, 400.0), Mods::default())), circle(&[(300.0, 300.0), (300.0, 400.0)]));
|
||||
click(&mut t, &cx, (300.0, 300.0));
|
||||
t.pointer(&cx, &ev(down, (380.0, 360.0), Mods::default()));
|
||||
assert_eq!(t.pointer(&cx, &ev(up, (381.0, 360.0), Mods::default())), circle(&[(300.0, 300.0), (380.0, 360.0)]));
|
||||
}
|
||||
|
||||
/// 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]
|
||||
|
||||
Reference in New Issue
Block a user