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:
bflatastic
2026-10-07 13:44:46 +07:00
co-authored by Claude Opus 5.5
parent 21641d5dee
commit 83f17dda37
4 changed files with 121 additions and 41 deletions
+7 -3
View File
@@ -93,6 +93,8 @@ enum Gesture {
start: [f64; 2],
inv: Mat3,
l2p: Mat3,
/// The layer's own snap targets as the drag began (its box and path vertices).
own: Vec<effectcraft_engine::viewer::SnapTarget>,
},
Pan {
start_pan: [f32; 2],
@@ -1057,6 +1059,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
start: map.to_comp(press),
inv: l2c.inverse().unwrap_or(Mat3::IDENTITY),
l2p,
own: effectcraft_engine::viewer::layer_targets(&ectx, layer, false),
})
}),
t if t.is_shape() => Some(Gesture::Create { tool: t, start: cpt }),
@@ -1225,11 +1228,12 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
let _ = app.session.execute("prop.set", json!({"layer": layer.0, "path": "transform/rotation", "value": r, "merge": merge}));
}
Gesture::Anchor { layer, start_anchor, start_pos, start, inv, l2p } => {
// Pan Behind snaps the anchor point (to layer features, guides and the grid).
Gesture::Anchor { layer, start_anchor, start_pos, start, inv, l2p, own } => {
// Pan Behind snaps the anchor point (to its own layer's box, other layers' features,
// guides and the grid).
let anchor_c = inv.inverse().map(|m| m.apply(gv2(start_anchor[0], start_anchor[1]))).unwrap_or(gv2(start[0], start[1]));
let want = [anchor_c.x + cpt[0] - start[0], anchor_c.y + cpt[1] - start[1]];
let sc = vt::snap(app, &ctx, &ectx, &map, &[layer], &[want], mods);
let sc = vt::snap_with(app, &ctx, &ectx, &map, &[layer], &[want], mods, &own);
let cpt = [cpt[0] + sc[0], cpt[1] + sc[1]];
let a = inv.apply(gv2(start[0], start[1]));
let b = inv.apply(gv2(cpt[0], cpt[1]));
+15
View File
@@ -45,6 +45,20 @@ pub(crate) fn snap(
exclude: &[LayerId],
sources: &[[f64; 2]],
mods: egui::Modifiers,
) -> [f64; 2] {
snap_with(app, ctx, ectx, map, exclude, sources, mods, &[])
}
/// [`snap`] with `extra` layer targets (the Pan Behind layer's own box).
pub(crate) fn snap_with(
app: &EffectcraftApp,
ctx: &egui::Context,
ectx: &EvalCtx,
map: &ViewerMap,
exclude: &[LayerId],
sources: &[[f64; 2]],
mods: egui::Modifiers,
extra: &[vw::SnapTarget],
) -> [f64; 2] {
let layers = snapping_on(app, mods);
let v = &app.ui.viewer;
@@ -55,6 +69,7 @@ pub(crate) fn snap(
}
let opts = vw::SnapOptions { guides, grid, grid_spacing: app.session.prefs.grids.grid_spacing };
let mut targets = vw::targets(ectx, exclude, opts);
targets.extend_from_slice(extra);
if !layers {
targets.retain(|t| matches!(t.source, SnapSource::Guide | SnapSource::Grid));
}