Skip to content

Commit 8dfdc2b

Browse files
mTvare6Keavon
andauthored
Update the bounding box snapping modes to use Align with Edges for edges and alignment (#2185)
* Fix snapping to respect rotation of bounding box Fixes snapping behaviour which defaulted to X and Y axes. * Remove redundant align along edges * Code review * Update manual --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent d692538 commit 8dfdc2b

File tree

5 files changed

+13
-33
lines changed

5 files changed

+13
-33
lines changed

editor/src/messages/portfolio/document/utility_types/misc.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ impl SnappingState {
9191
match target {
9292
SnapTarget::BoundingBox(target) => match target {
9393
BoundingBoxSnapTarget::CornerPoint => self.bounding_box.corner_point,
94-
BoundingBoxSnapTarget::AlongEdge => self.bounding_box.along_edge,
9594
BoundingBoxSnapTarget::EdgeMidpoint => self.bounding_box.edge_midpoint,
9695
BoundingBoxSnapTarget::CenterPoint => self.bounding_box.center_point,
9796
},
@@ -106,7 +105,7 @@ impl SnappingState {
106105
SnapTarget::Artboard(_) => self.artboards,
107106
SnapTarget::Grid(_) => self.grid_snapping,
108107
SnapTarget::Alignment(AlignmentSnapTarget::AlignWithAnchorPoint) => self.path.align_with_anchor_point,
109-
SnapTarget::Alignment(_) => self.bounding_box.align_with_corner_point,
108+
SnapTarget::Alignment(_) => self.bounding_box.align_with_edges,
110109
SnapTarget::DistributeEvenly(_) => self.bounding_box.distribute_evenly,
111110
_ => false,
112111
}
@@ -119,8 +118,7 @@ pub struct BoundingBoxSnapping {
119118
pub center_point: bool,
120119
pub corner_point: bool,
121120
pub edge_midpoint: bool,
122-
pub along_edge: bool,
123-
pub align_with_corner_point: bool,
121+
pub align_with_edges: bool,
124122
pub distribute_evenly: bool,
125123
}
126124

@@ -130,8 +128,7 @@ impl Default for BoundingBoxSnapping {
130128
center_point: true,
131129
corner_point: true,
132130
edge_midpoint: true,
133-
along_edge: true,
134-
align_with_corner_point: true,
131+
align_with_edges: true,
135132
distribute_evenly: true,
136133
}
137134
}
@@ -378,13 +375,11 @@ impl fmt::Display for SnapSource {
378375
}
379376

380377
type GetSnapState = for<'a> fn(&'a mut SnappingState) -> &'a mut bool;
381-
pub const SNAP_FUNCTIONS_FOR_BOUNDING_BOXES: [(&str, GetSnapState, &str); 6] = [
378+
pub const SNAP_FUNCTIONS_FOR_BOUNDING_BOXES: [(&str, GetSnapState, &str); 5] = [
382379
(
383-
// TODO: Rename to "Beyond Edges" and update behavior to snap to an infinite extension of the bounding box edges
384-
// TODO: (even when the layer is locally rotated) instead of horizontally/vertically aligning with the corner points
385-
"Align with Corner Points",
386-
(|snapping_state| &mut snapping_state.bounding_box.align_with_corner_point) as GetSnapState,
387-
"Snaps to horizontal/vertical alignment with the corner points of any layer's bounding box",
380+
"Align with Edges",
381+
(|snapping_state| &mut snapping_state.bounding_box.align_with_edges) as GetSnapState,
382+
"Snaps to horizontal/vertical alignment with the edges of any layer's bounding box",
388383
),
389384
(
390385
"Corner Points",
@@ -401,11 +396,6 @@ pub const SNAP_FUNCTIONS_FOR_BOUNDING_BOXES: [(&str, GetSnapState, &str); 6] = [
401396
(|snapping_state| &mut snapping_state.bounding_box.edge_midpoint) as GetSnapState,
402397
"Snaps to any of the four points at the middle of the edges of any layer's bounding box",
403398
),
404-
(
405-
"Along Edges",
406-
(|snapping_state| &mut snapping_state.bounding_box.along_edge) as GetSnapState,
407-
"Snaps anywhere along the four edges of any layer's bounding box",
408-
),
409399
(
410400
"Distribute Evenly",
411401
(|snapping_state| &mut snapping_state.bounding_box.distribute_evenly) as GetSnapState,
@@ -463,7 +453,6 @@ pub enum BoundingBoxSnapTarget {
463453
CornerPoint,
464454
CenterPoint,
465455
EdgeMidpoint,
466-
AlongEdge,
467456
}
468457

469458
impl fmt::Display for BoundingBoxSnapTarget {
@@ -472,7 +461,6 @@ impl fmt::Display for BoundingBoxSnapTarget {
472461
BoundingBoxSnapTarget::CornerPoint => write!(f, "Bounding Box: Corner Point"),
473462
BoundingBoxSnapTarget::CenterPoint => write!(f, "Bounding Box: Center Point"),
474463
BoundingBoxSnapTarget::EdgeMidpoint => write!(f, "Bounding Box: Edge Midpoint"),
475-
BoundingBoxSnapTarget::AlongEdge => write!(f, "Bounding Box: Along Edge"),
476464
}
477465
}
478466
}

editor/src/messages/tool/common_functionality/snapping.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use {alignment_snapper::*, distribution_snapper::*, grid_snapper::*, layer_s
88
use crate::consts::{COLOR_OVERLAY_BLUE, COLOR_OVERLAY_SNAP_BACKGROUND, COLOR_OVERLAY_WHITE};
99
use crate::messages::portfolio::document::overlays::utility_types::{OverlayContext, Pivot};
1010
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
11-
use crate::messages::portfolio::document::utility_types::misc::{BoundingBoxSnapTarget, GridSnapTarget, PathSnapTarget, SnapTarget};
11+
use crate::messages::portfolio::document::utility_types::misc::{GridSnapTarget, PathSnapTarget, SnapTarget};
1212
use crate::messages::prelude::*;
1313

1414
use bezier_rs::{Subpath, TValue};
@@ -135,14 +135,7 @@ fn get_closest_line(lines: &[SnappedLine]) -> Option<&SnappedPoint> {
135135
fn get_closest_intersection(snap_to: DVec2, curves: &[SnappedCurve]) -> Option<SnappedPoint> {
136136
let mut best = None;
137137
for curve_i in curves {
138-
if curve_i.point.target == SnapTarget::BoundingBox(BoundingBoxSnapTarget::AlongEdge) {
139-
continue;
140-
}
141-
142138
for curve_j in curves {
143-
if curve_j.point.target == SnapTarget::BoundingBox(BoundingBoxSnapTarget::AlongEdge) {
144-
continue;
145-
}
146139
if curve_i.start == curve_j.start && curve_i.layer == curve_j.layer {
147140
continue;
148141
}

editor/src/messages/tool/common_functionality/snapping/alignment_snapper.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl AlignmentSnapper {
1919
let document = snap_data.document;
2020

2121
self.bounding_box_points.clear();
22-
if !document.snapping_state.bounding_box.align_with_corner_point {
22+
if !document.snapping_state.bounding_box.align_with_edges {
2323
return;
2424
}
2525

@@ -74,7 +74,9 @@ impl AlignmentSnapper {
7474
Quad::intersect_rays(target_point.document_point, DVec2::X, origin, direction),
7575
]
7676
} else {
77-
[DVec2::new(point.document_point.x, target_position.y), DVec2::new(target_position.x, point.document_point.y)].map(Some)
77+
let Some(quad) = target_point.quad.map(|quad| quad.0) else { continue };
78+
let edges = [quad[1] - quad[0], quad[3] - quad[0]];
79+
edges.map(|edge| edge.try_normalize().map(|edge| (point.document_point - target_position).project_onto(edge) + target_position))
7880
};
7981

8082
let target_path = matches!(target_point.target, SnapTarget::Path(_));

editor/src/messages/tool/common_functionality/snapping/layer_snapper.rs

-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ impl LayerSnapper {
8686
}
8787
}
8888
}
89-
if !snap_data.ignore_bounds(layer) {
90-
self.add_layer_bounds(document, layer, SnapTarget::BoundingBox(BoundingBoxSnapTarget::AlongEdge));
91-
}
9289
}
9390
}
9491

website/content/learn/interface/document-panel.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The right side of the control bar has controls related to the active document an
5555
| | |
5656
|-|-|
5757
| Overlays | <p>When checked (default), overlays are shown. When unchecked, they are hidden. Overlays are the temporary contextual visualizations (like bounding boxes and vector manipulators) that are usually blue and appear atop the viewport when using tools.</p> |
58-
| Snapping | <p>When checked (default), drawing and dragging shapes and vector points means they will snap to other areas of geometric interest like corners or anchor points. When unchecked, the selection moves freely.<br /><br />Fine-grained options are available by clicking the overflow button to access its options popover menu:</p><p><img src="https://static.graphite.rs/content/learn/interface/document-panel/snapping-popover__4.avif" onerror="this.onerror = null; this.src = this.src.replace('.avif', '.png')" onload="this.width = this.naturalWidth / 2" alt="Snapping options popover menu" /></p><p>Snapping options relating to **Bounding Boxes**:</p><p><ul><li>**Align with Corner Points**: Snaps to horizontal/vertical alignment with the corner points of any layer's bounding box.</li><li>**Corner Points**: Snaps to the four corners of any layer's bounding box.</li><li>**Center Points**: Snaps to the center point of any layer's bounding box.</li><li>**Edge Midpoints**: Snaps to any of the four points at the middle of the edges of any layer's bounding box.</li><li>**Along Edges**: Snaps anywhere along the four edges of any layer's bounding box.</li><li>**Distribute Evenly**: Snaps to a consistent distance offset established by the bounding boxes of nearby layers (due to a bug, **Center Points** and **Corner Points** must be enabled).</li></ul></p><p>Snapping options relating to **Paths**:</p><p><ul><li>**Align with Anchor Points**: Snaps to horizontal/vertical alignment with the anchor points of any vector path.</li><li>**Anchor Points**: Snaps to the anchor point of any vector path.</li><li>**Line Midpoints**: Snaps to the point at the middle of any straight line segment of a vector path.</li><li>**Path Intersection Points**: Snaps to any points where vector paths intersect.</li><li>**Along Paths**: Snaps along the length of any vector path.</li><li>**Normal to Paths**: Snaps a line to a point perpendicular to a vector path (due to a bug, **Intersections of Paths** must be enabled).</li><li>**Tangent to Paths**: Snaps a line to a point tangent to a vector path (due to a bug, **Intersections of Paths** must be enabled).</li></ul></p> |
58+
| Snapping | <p>When checked (default), drawing and dragging shapes and vector points means they will snap to other areas of geometric interest like corners or anchor points. When unchecked, the selection moves freely.<br /><br />Fine-grained options are available by clicking the overflow button to access its options popover menu. Each option has a tooltip explaining what it does by hovering the cursor over it.</p><p><img src="https://static.graphite.rs/content/learn/interface/document-panel/snapping-popover__5.avif" onerror="this.onerror = null; this.src = this.src.replace('.avif', '.png')" onload="this.width = this.naturalWidth / 2" alt="Snapping options popover menu" /></p><p>Snapping options relating to **Bounding Boxes**:</p><p><ul><li>**Align with Edges**: Snaps to horizontal/vertical alignment with the edges of any layer's bounding box.</li><li>**Corner Points**: Snaps to the four corners of any layer's bounding box.</li><li>**Center Points**: Snaps to the center point of any layer's bounding box.</li><li>**Edge Midpoints**: Snaps to any of the four points at the middle of the edges of any layer's bounding box.</li><li>**Distribute Evenly**: Snaps to a consistent distance offset established by the bounding boxes of nearby layers (due to a bug, **Corner Points** and **Center Points** must be enabled).</li></ul></p><p>Snapping options relating to **Paths**:</p><p><ul><li>**Align with Anchor Points**: Snaps to horizontal/vertical alignment with the anchor points of any vector path.</li><li>**Anchor Points**: Snaps to the anchor point of any vector path.</li><li>**Line Midpoints**: Snaps to the point at the middle of any straight line segment of a vector path.</li><li>**Path Intersection Points**: Snaps to any points where vector paths intersect.</li><li>**Along Paths**: Snaps along the length of any vector path.</li><li>**Normal to Paths**: Snaps a line to a point perpendicular to a vector path (due to a bug, **Intersections of Paths** must be enabled).</li><li>**Tangent to Paths**: Snaps a line to a point tangent to a vector path (due to a bug, **Intersections of Paths** must be enabled).</li></ul></p> |
5959
| Grid | <p>When checked (off by default), grid lines are shown and snapping to them becomes active. The initial grid scale is 1 document unit, helping you draw pixel-perfect artwork.</p><ul><li><p>**Type** sets whether the grid pattern is made of squares or triangles.</p><p>**Rectangular** is a pattern of horizontal and vertical lines:</p><p><img src="https://static.graphite.rs/content/learn/interface/document-panel/grid-rectangular-popover__2.avif" onerror="this.onerror = null; this.src = this.src.replace('.avif', '.png')" onload="this.width = this.naturalWidth / 2" alt="Snapping options popover menu" /></p><p>It has one option unique to this mode:</p><ul><li>**Spacing** is the width and height of the rectangle grid cells.</li></ul><p>**Isometric** is a pattern of triangles:</p><p><img src="https://static.graphite.rs/content/learn/interface/document-panel/grid-isometric-popover__2.avif" onerror="this.onerror = null; this.src = this.src.replace('.avif', '.png')" onload="this.width = this.naturalWidth / 2" alt="Snapping options popover menu" /></p><p>It has two options unique to this mode:</p><ul><li>**Y Spacing** is the height between vertical repetitions of the grid.</li><li>**Angles** is the slant of the upward and downward sloped grid lines.</li></ul></li><li>**Display** gives control over the appearance of the grid. The **Display as dotted grid** checkbox (off by default) replaces the solid lines with dots at their intersection points.</li><li>**Origin** is the position in the canvas where the repeating grid pattern begins from. If you need an offset for the grid where an intersection occurs at a specific location, set those coordinates.</li></ul> |
6060
| View Mode | <p>**Normal** (default): The artwork is rendered normally.</p><p>**Outline**: The artwork is rendered as a wireframe.</p><p>**Pixels**: **Not implemented yet.** The artwork is rendered as it would appear when exported as a bitmap image at 100% scale regardless of the viewport zoom level.</p> |
6161
| Zoom In | <p>Zooms the viewport in to the next whole increment.</p> |

0 commit comments

Comments
 (0)