Skip to content

Commit 66a297d

Browse files
moosama76Keavon
andauthored
Improve the distribution part of the snapping system (#2626)
* fix distribution snapper visualization going far from layers * fix bugs * Remove traces * remove comment * Fix tests * Rename distribution snapper variables from x, y to horizontal, vertical * Fix tests * Fix bug where center point and corner point have to be enabled for distribution_snapper to work * Cleanup --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent ddb2d74 commit 66a297d

File tree

6 files changed

+202
-113
lines changed

6 files changed

+202
-113
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ pub const SNAP_FUNCTIONS_FOR_BOUNDING_BOXES: [(&str, GetSnapState, &str); 5] = [
404404
(
405405
"Distribute Evenly",
406406
(|snapping_state| &mut snapping_state.bounding_box.distribute_evenly) as GetSnapState,
407-
// TODO: Fix the bug/limitation that requires 'Center Points' and 'Corner Points' to be enabled
408-
"Snaps to a consistent distance offset established by the bounding boxes of nearby layers\n(due to a bug, 'Center Points' and 'Corner Points' must be enabled)",
407+
"Snaps to a consistent distance offset established by the bounding boxes of nearby layers",
409408
),
410409
];
411410
pub const SNAP_FUNCTIONS_FOR_PATHS: [(&str, GetSnapState, &str); 7] = [

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ fn get_closest_point(points: Vec<SnappedPoint>) -> Option<SnappedPoint> {
114114
(Some(result), None) | (None, Some(result)) => Some(result),
115115
(Some(mut result), Some(align)) => {
116116
let SnapTarget::DistributeEvenly(distribution) = result.target else { return Some(result) };
117-
if distribution.is_x() && align.alignment_target_x.is_some() {
117+
if distribution.is_x() && align.alignment_target_horizontal.is_some() {
118118
result.snapped_point_document.y = align.snapped_point_document.y;
119-
result.alignment_target_x = align.alignment_target_x;
119+
result.alignment_target_horizontal = align.alignment_target_horizontal;
120120
}
121-
if distribution.is_y() && align.alignment_target_y.is_some() {
121+
if distribution.is_y() && align.alignment_target_vertical.is_some() {
122122
result.snapped_point_document.x = align.snapped_point_document.x;
123-
result.alignment_target_y = align.alignment_target_y;
123+
result.alignment_target_vertical = align.alignment_target_vertical;
124124
}
125125

126126
Some(result)
@@ -456,10 +456,10 @@ impl SnapManager {
456456
}
457457
let viewport = to_viewport.transform_point2(ind.snapped_point_document);
458458

459-
Self::alignment_x_overlay(&ind.distribution_boxes_x, to_viewport, overlay_context);
460-
Self::alignment_y_overlay(&ind.distribution_boxes_y, to_viewport, overlay_context);
459+
Self::alignment_x_overlay(&ind.distribution_boxes_horizontal, to_viewport, overlay_context);
460+
Self::alignment_y_overlay(&ind.distribution_boxes_vertical, to_viewport, overlay_context);
461461

462-
let align = [ind.alignment_target_x, ind.alignment_target_y].map(|target| target.map(|target| to_viewport.transform_point2(target)));
462+
let align = [ind.alignment_target_horizontal, ind.alignment_target_vertical].map(|target| target.map(|target| to_viewport.transform_point2(target)));
463463
let any_align = align.iter().flatten().next().is_some();
464464
for &target in align.iter().flatten() {
465465
overlay_context.line(viewport, target, None, None);
@@ -471,7 +471,7 @@ impl SnapManager {
471471
overlay_context.manipulator_handle(viewport, false, None);
472472
}
473473

474-
if !any_align && ind.distribution_equal_distance_x.is_none() && ind.distribution_equal_distance_y.is_none() {
474+
if !any_align && ind.distribution_equal_distance_horizontal.is_none() && ind.distribution_equal_distance_vertical.is_none() {
475475
let text = format!("[{}] from [{}]", ind.target, ind.source);
476476
let transform = DAffine2::from_translation(viewport - DVec2::new(0., 4.));
477477
overlay_context.text(&text, COLOR_OVERLAY_WHITE, Some(COLOR_OVERLAY_LABEL_BACKGROUND), transform, 4., [Pivot::Start, Pivot::End]);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl AlignmentSnapper {
9090
distance_to_align_target,
9191
fully_constrained: false,
9292
at_intersection: true,
93-
alignment_target_x: Some(endpoint),
93+
alignment_target_horizontal: Some(endpoint),
9494
..Default::default()
9595
};
9696
snap_results.points.push(snap_point);
@@ -129,7 +129,7 @@ impl AlignmentSnapper {
129129
distance: distance_to_snapped,
130130
tolerance,
131131
distance_to_align_target,
132-
alignment_target_x: Some(target_position),
132+
alignment_target_horizontal: Some(target_position),
133133
fully_constrained: true,
134134
at_intersection: matches!(constraint, SnapConstraint::Line { .. }),
135135
..Default::default()
@@ -148,7 +148,7 @@ impl AlignmentSnapper {
148148
distance: distance_to_snapped,
149149
tolerance,
150150
distance_to_align_target,
151-
alignment_target_y: Some(target_position),
151+
alignment_target_vertical: Some(target_position),
152152
fully_constrained: true,
153153
at_intersection: matches!(constraint, SnapConstraint::Line { .. }),
154154
..Default::default()
@@ -174,8 +174,8 @@ impl AlignmentSnapper {
174174
target_bounds: snap_x.target_bounds,
175175
distance,
176176
tolerance,
177-
alignment_target_x: snap_x.alignment_target_x,
178-
alignment_target_y: snap_y.alignment_target_y,
177+
alignment_target_horizontal: snap_x.alignment_target_horizontal,
178+
alignment_target_vertical: snap_y.alignment_target_vertical,
179179
constrained: true,
180180
at_intersection: true,
181181
..Default::default()

0 commit comments

Comments
 (0)