mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
Outline draft: a shift freehand drag locks one line only where the tool asks (the Freeform Pen); the selection Lasso keeps the pointer's path
This commit is contained in:
@@ -152,6 +152,8 @@ pub struct OutlineDraft {
|
||||
document: Option<u64>,
|
||||
/// A ⇧ freehand drag's line: where it began and the unit direction it locked to (the nearest of eight).
|
||||
lock: Option<(Point, Vec2)>,
|
||||
/// Whether ⇧ holds a freehand drag to one line ([`locking_drags`](Self::locking_drags)).
|
||||
locks_drag: bool,
|
||||
}
|
||||
|
||||
impl OutlineDraft {
|
||||
@@ -168,9 +170,19 @@ impl OutlineDraft {
|
||||
alt_from_press: false,
|
||||
document: None,
|
||||
lock: None,
|
||||
locks_drag: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a Mixed draft's freehand drag with ⇧ held stays on one line ([`drag_step`](Self::drag_step)). Off, ⇧
|
||||
/// leaves a freehand drag alone: a selection Lasso's ⇧ at the press adds to the selection, and a drag keeps the
|
||||
/// pointer's path. The Freeform Pen turns it on.
|
||||
#[must_use]
|
||||
pub fn locking_drags(mut self, on: bool) -> Self {
|
||||
self.locks_drag = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The rules this draft follows.
|
||||
pub fn kind(&self) -> DraftKind {
|
||||
self.kind
|
||||
@@ -274,7 +286,7 @@ impl OutlineDraft {
|
||||
Some(DraftEvent::Changed)
|
||||
}
|
||||
|
||||
/// Where a freehand point of `at` goes. With ⇧ held a Mixed draft's drag follows one line: once the pointer has
|
||||
/// Where a freehand point of `at` goes. With ⇧ held a [locking](Self::locking_drags) Mixed draft's drag follows one line: once the pointer has
|
||||
/// travelled [`LOCK_DISTANCE`] screen points from the last vertex, the nearest of eight directions from there
|
||||
/// is locked and every later point is the pointer's projection onto it, however the pointer wanders, until ⇧ is
|
||||
/// released. Before the lock the point stays at the vertex. Otherwise [`shift_step`](Self::shift_step).
|
||||
@@ -283,6 +295,10 @@ impl OutlineDraft {
|
||||
self.lock = None;
|
||||
return self.shift_step(at);
|
||||
}
|
||||
if !self.locks_drag {
|
||||
self.lock = None;
|
||||
return at.at;
|
||||
}
|
||||
let Some(&last) = self.points.last() else { return at.at };
|
||||
let (origin, direction) = match self.lock {
|
||||
Some(lock) => lock,
|
||||
|
||||
@@ -72,7 +72,7 @@ fn shift_steps_keep_the_shorter_diagonal_offset() {
|
||||
#[test]
|
||||
fn shift_holds_a_freehand_drag_to_one_line() {
|
||||
let shift = |x: f64, y: f64| DraftPoint::new(Point::new(x, y), Mods::SHIFT, 1.0);
|
||||
let mut draft = OutlineDraft::new(DraftKind::Mixed, REACH);
|
||||
let mut draft = OutlineDraft::new(DraftKind::Mixed, REACH).locking_drags(true);
|
||||
draft.press(at(10.0, 60.0, 1.0), true);
|
||||
for (x, y) in [(30.0, 63.0), (50.0, 55.0), (80.0, 68.0), (100.0, 52.0)] {
|
||||
draft.drag(shift(x, y));
|
||||
@@ -82,6 +82,14 @@ fn shift_holds_a_freehand_drag_to_one_line() {
|
||||
assert!(points.len() >= 3, "{points:?}");
|
||||
assert!(points.iter().all(|p| p.y == 60.0), "the drag stays on the horizontal line through its start: {points:?}");
|
||||
assert_eq!(points.last().map(|p| p.x), Some(100.0), "and follows the pointer along it");
|
||||
|
||||
// A selection Lasso's ⇧ at the press adds to the selection: its drag keeps the pointer's path.
|
||||
let mut lasso = OutlineDraft::new(DraftKind::Mixed, REACH);
|
||||
lasso.press(at(10.0, 60.0, 1.0), true);
|
||||
for (x, y) in [(30.0, 63.0), (50.0, 55.0)] {
|
||||
lasso.drag(shift(x, y));
|
||||
}
|
||||
assert_eq!(lasso.points().last(), Some(&Point::new(50.0, 55.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user