From 26d66298cf3fde7716b4533626b780773cae71e1 Mon Sep 17 00:00:00 2001 From: James Lindsay <78500760+0HyperCube@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:00:01 +0000 Subject: [PATCH] Give the current snapping target layer(s) an outline (#2224) * Outline layer when snapping * Outline layers when snapping to anchors --- .../tool/common_functionality/snapping.rs | 10 +++---- .../snapping/grid_snapper.rs | 5 ---- .../snapping/layer_snapper.rs | 29 ++++++++++++------- .../snapping/snap_results.rs | 3 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/editor/src/messages/tool/common_functionality/snapping.rs b/editor/src/messages/tool/common_functionality/snapping.rs index 9e402d41..858cdd50 100644 --- a/editor/src/messages/tool/common_functionality/snapping.rs +++ b/editor/src/messages/tool/common_functionality/snapping.rs @@ -11,7 +11,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye use crate::messages::portfolio::document::utility_types::misc::{GridSnapTarget, PathSnapTarget, SnapTarget}; use crate::messages::prelude::*; -use bezier_rs::{Subpath, TValue}; +use bezier_rs::TValue; use graphene_core::renderer::Quad; use graphene_core::vector::PointId; use graphene_std::renderer::Rect; @@ -151,7 +151,7 @@ fn get_closest_intersection(snap_to: DVec2, curves: &[SnappedCurve]) -> Option, + /// This layer is outlined if the snap candidate is used. + pub outline_layer: Option, pub neighbors: Vec, pub alignment: bool, } impl SnapCandidatePoint { - pub fn new(document_point: DVec2, source: SnapSource, target: SnapTarget) -> Self { - Self::new_quad(document_point, source, target, None, true) + pub fn new(document_point: DVec2, source: SnapSource, target: SnapTarget, outline_layer: Option) -> Self { + Self::new_quad(document_point, source, target, None, outline_layer, true) } - pub fn new_quad(document_point: DVec2, source: SnapSource, target: SnapTarget, quad: Option, alignment: bool) -> Self { + pub fn new_quad(document_point: DVec2, source: SnapSource, target: SnapTarget, quad: Option, outline_layer: Option, alignment: bool) -> Self { Self { document_point, source, target, quad, + outline_layer, alignment, ..Default::default() } } pub fn new_source(document_point: DVec2, source: SnapSource) -> Self { - Self::new(document_point, source, SnapTarget::None) + Self::new(document_point, source, SnapTarget::None, None) } pub fn handle(document_point: DVec2) -> Self { @@ -409,15 +413,15 @@ pub fn get_bbox_points(quad: Quad, points: &mut Vec, values: let start = quad.0[index]; let end = quad.0[(index + 1) % 4]; if document.snapping_state.target_enabled(values.corner_target) { - points.push(SnapCandidatePoint::new_quad(start, values.corner_source, values.corner_target, Some(quad), false)); + points.push(SnapCandidatePoint::new_quad(start, values.corner_source, values.corner_target, Some(quad), None, false)); } if document.snapping_state.target_enabled(values.edge_target) { - points.push(SnapCandidatePoint::new_quad((start + end) / 2., values.edge_source, values.edge_target, Some(quad), false)); + points.push(SnapCandidatePoint::new_quad((start + end) / 2., values.edge_source, values.edge_target, Some(quad), None, false)); } } if document.snapping_state.target_enabled(values.center_target) { - points.push(SnapCandidatePoint::new_quad(quad.center(), values.center_source, values.center_target, Some(quad), false)); + points.push(SnapCandidatePoint::new_quad(quad.center(), values.center_source, values.center_target, Some(quad), None, false)); } } @@ -445,6 +449,7 @@ fn subpath_anchor_snap_points(layer: LayerNodeIdentifier, subpath: &Subpath, pub source_bounds: Option, - pub curves: [Option; 2], + /// These layer(s) are outlined in the overlays when the snap is used. + pub outline_layers: [Option; 2], pub distance: f64, pub tolerance: f64, pub distribution_boxes_x: VecDeque,