mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
ui-canvas: a rulers corner drag lands at its release only while its edit is open: after the host cancelled it, the release proposed and committed again and moved the zero point
This commit is contained in:
1 parent
503ccd4cd9
commit
0c633a83cd
2 files changed
+28
-1
No files matched your search
@@ -439,6 +439,7 @@ impl Component for Rulers<'_> {
|
||||
let started = press.phase.start().filter(|start| start.button == PointerButton::Primary);
|
||||
if started.is_some() && !self.origin_locked {
|
||||
// Every step of the drag proposes where it lands, its start and its release too: a drag of one move lands.
|
||||
// A release lands only while the drag's edit is open: a cancelled drag stays cancelled.
|
||||
let land =
|
||||
|pos: Pos2, start: Point| if corner.contains(pos) { start } else { Self::landing(&space, self.snap.as_ref(), pos, press.mods, zero) };
|
||||
match press.phase {
|
||||
@@ -451,7 +452,7 @@ impl Component for Rulers<'_> {
|
||||
let start = cx.press_slot::<Point>().unwrap_or(zero);
|
||||
cx.propose(land(pos, start));
|
||||
}
|
||||
PressPhase::Release { pos, click: false, .. } => {
|
||||
PressPhase::Release { pos, click: false, .. } if matches!(cx.gesture(), Some(GesturePhase::Begin | GesturePhase::Update)) => {
|
||||
let start = cx.press_slot::<Point>().unwrap_or(zero);
|
||||
cx.propose(land(pos, start));
|
||||
cx.commit();
|
||||
|
||||
@@ -190,3 +190,29 @@ fn a_corner_drag_of_one_move_lands_the_zero_point() {
|
||||
fixture.settle();
|
||||
assert_ne!(*zero.borrow(), Point::ZERO, "the zero point lands where the one-move drag released");
|
||||
}
|
||||
|
||||
/// A host that moves the zero point under a corner drag cancels the drag's edit while the press goes on; the release
|
||||
/// that follows lands nothing, so the host's zero point stays.
|
||||
#[trial]
|
||||
fn a_corner_drag_the_host_cancelled_lands_nothing_at_its_release() {
|
||||
let zero = Rc::new(RefCell::new(Point::ZERO));
|
||||
let view = |room: Rect| CanvasView::new(room, Point::new(f64::from(room.center().x), f64::from(room.center().y)), 1.0);
|
||||
let snap = Snap::new(std::sync::Arc::new(SnapTargets::new()), SnapOptions::default());
|
||||
let mut fixture = ToolFixture::with_rulers("Document", Overpaint, view, snap, zero.clone(), |_, _| {});
|
||||
fixture.fixture().room(Vec2::new(500.0, 400.0)).settle();
|
||||
let canvas = fixture.canvas().rect;
|
||||
let (from, to) = (canvas.min + Vec2::splat(4.0), canvas.center());
|
||||
let fixture = fixture.fixture();
|
||||
fixture.frame(vec![craft_ui::testing::pointer::moved(from)]);
|
||||
fixture.frame(vec![craft_ui::testing::pointer::press(from)]);
|
||||
fixture.frame(vec![craft_ui::testing::pointer::moved(to)]);
|
||||
fixture.settle();
|
||||
let dragged = *zero.borrow();
|
||||
assert_ne!(dragged, Point::ZERO, "the drag moves the zero point");
|
||||
let host = Point::new(-dragged.x, -dragged.y);
|
||||
*zero.borrow_mut() = host;
|
||||
fixture.frame(vec![craft_ui::testing::pointer::moved(to + Vec2::splat(10.0))]);
|
||||
fixture.frame(vec![craft_ui::testing::pointer::release(to + Vec2::splat(10.0))]);
|
||||
fixture.settle();
|
||||
assert_eq!(*zero.borrow(), host, "the release after the host's change leaves the zero point where the host put it");
|
||||
}
|
||||
Reference in new issue
Block a user