Viewer: Pan Behind snaps the anchor to its own layer (#147)
The Pan Behind drag passed its layer to the snapper's exclude list, which dropped all of that layer's targets: its corners, edge midpoints and centre as well as the anchor being dragged. The layer's box doesn't move in comp space while the anchor pans (Position compensates), so those points are valid targets. The engine's per-layer snap targets are now one function, layer_targets, which can leave out the anchor point. The gesture records its layer's targets without the anchor as the drag begins and passes them to the snapper (snap_with) as extra targets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
21641d5dee
commit
83f17dda37
@@ -440,23 +440,59 @@ fn pan_behind_snaps_the_anchor_point() {
|
||||
h.run_steps(2);
|
||||
// Drag the anchor (at the box centre) to 3 px from the comp centre: it snaps there, and the
|
||||
// position follows so the box doesn't move.
|
||||
let from = screen(&h, [100.0, 100.0]);
|
||||
let to = screen(&h, [323.0, 182.0]);
|
||||
// (The gesture applies the pointer of the previous frame: hold the end point a frame.)
|
||||
let (from, to) = (screen(&h, [100.0, 100.0]), screen(&h, [323.0, 182.0]));
|
||||
hold_drag(&mut h, from, to, Default::default());
|
||||
let (p, a) = position_and_anchor(&h, box_id);
|
||||
assert!((p[0] - 320.0).abs() < 0.01 && (p[1] - 180.0).abs() < 0.01, "anchor point snapped to the comp centre: {p:?}");
|
||||
assert!((a[0] - 260.0).abs() < 0.01 && (a[1] - 120.0).abs() < 0.01, "{a:?}");
|
||||
}
|
||||
|
||||
/// Issue #147: Pan Behind snaps the anchor to its own layer's corners, edge midpoints and centre
|
||||
/// (only the anchor itself is left out: the box stays put while the anchor moves).
|
||||
#[test]
|
||||
fn pan_behind_snaps_the_anchor_to_its_own_layer() {
|
||||
let mut h = harness();
|
||||
let box_id = h.state().session.active_comp().unwrap().layers[0].id;
|
||||
h.state_mut().session.execute("prop.set", json!({"layer": box_id.0, "path": "transform/position", "value": [100, 100, 0]})).unwrap();
|
||||
h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap();
|
||||
h.state_mut().ui.tool = Tool::PanBehind;
|
||||
h.run_steps(2);
|
||||
// The 80×80 box spans (60, 60)–(140, 140). Its anchor, dragged to 3 px from the top-left
|
||||
// corner, lands on it.
|
||||
let (from, to) = (screen(&h, [100.0, 100.0]), screen(&h, [63.0, 62.0]));
|
||||
hold_drag(&mut h, from, to, Default::default());
|
||||
let (p, a) = position_and_anchor(&h, box_id);
|
||||
assert!(a[0].abs() < 0.01 && a[1].abs() < 0.01, "anchor point snapped to the corner: {a:?}");
|
||||
assert!((p[0] - 60.0).abs() < 0.01 && (p[1] - 60.0).abs() < 0.01, "the box stays put: {p:?}");
|
||||
// And back to near the centre: it snaps there.
|
||||
let (from, to) = (screen(&h, [61.0, 61.0]), screen(&h, [103.0, 98.0]));
|
||||
hold_drag(&mut h, from, to, Default::default());
|
||||
let (p, a) = position_and_anchor(&h, box_id);
|
||||
assert!((a[0] - 40.0).abs() < 0.01 && (a[1] - 40.0).abs() < 0.01, "anchor point snapped to the centre: {a:?}");
|
||||
assert!((p[0] - 100.0).abs() < 0.01 && (p[1] - 100.0).abs() < 0.01, "{p:?}");
|
||||
}
|
||||
|
||||
/// Drag from `from` to `to` with `modifiers` held, holding the end point a frame (the viewer's
|
||||
/// gestures apply the pointer of the previous frame).
|
||||
fn hold_drag(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2, modifiers: egui::Modifiers) {
|
||||
h.input_mut().events.push(Event::ModifiersChanged(modifiers));
|
||||
h.input_mut().events.push(Event::PointerMoved(from));
|
||||
h.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() });
|
||||
h.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers });
|
||||
h.step();
|
||||
for i in 1..=10 {
|
||||
h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (i.min(8) as f32 / 8.0)));
|
||||
h.step();
|
||||
}
|
||||
h.input_mut().events.push(Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() });
|
||||
h.input_mut().events.push(Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers });
|
||||
h.run_steps(2);
|
||||
let l = h.state().session.active_comp().unwrap().layer(box_id).unwrap().clone();
|
||||
let p = l.props.prop("transform/position").unwrap().value.as_vec3();
|
||||
let a = l.props.prop("transform/anchor").unwrap().value.as_vec3();
|
||||
assert!((p[0] - 320.0).abs() < 0.01 && (p[1] - 180.0).abs() < 0.01, "anchor point snapped to the comp centre: {p:?}");
|
||||
assert!((a[0] - 260.0).abs() < 0.01 && (a[1] - 120.0).abs() < 0.01, "{a:?}");
|
||||
h.input_mut().events.push(Event::ModifiersChanged(Default::default()));
|
||||
h.step();
|
||||
}
|
||||
|
||||
/// A layer's Position and Anchor Point.
|
||||
fn position_and_anchor(h: &Harness<'_, EffectcraftApp>, layer: LayerId) -> ([f64; 3], [f64; 3]) {
|
||||
let l = h.state().session.active_comp().unwrap().layer(layer).unwrap().clone();
|
||||
(l.props.prop("transform/position").unwrap().value.as_vec3(), l.props.prop("transform/anchor").unwrap().value.as_vec3())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user