Smart Guides: Alt over another object or the artboard shows the selection's distances to it

Distance Guides, from the public "Use Distance Guides for accurate
placement" and "Smart Guides options" (Invoke Distance Guides) pages:
with Smart Guides on, something selected and the Selection tool,
holding Alt/Option over another object shows the horizontal and
vertical distances between the selection and it, and over an empty
part of an artboard the selection's distances from the artboard's left,
right, top and bottom edges.

- guides::distance_guides measures the selection's bounds to a box: on
  an axis on which they lie apart, the gap between their facing edges;
  otherwise the offsets of both pairs of matching edges. Each line runs
  across the middle of the overlap on the other axis (else the
  selection's middle), with a dashed line out to the target's edge when
  it passes beside it. An artboard is always measured edge to edge.
  Labels are in the General unit, in the smart guide colour.
- The Selection tool keeps what its Alt hover points at and draws the
  guides while idle; letting Alt go (the canvas re-hovers on a modifier
  change), a press or moving off clears them.
- Overlay::Distance: the line with end ticks and its length in a pill;
  the canvas draws it.
- Preferences › Smart Guides › Invoke Distance Guides (`distanceGuides`,
  on by default), with i18n rows; View › Smart Guides gates it too.
- Hover only, as the pages describe: nothing while moving or nudging.

Tests: select::tests::alt_over_* (gap and edges beside and below,
artboard edges in pt and mm), distance_guides_need_alt_a_selection_and_
smart_guides, tests_prefs::invoke_distance_guides_measures_the_selection_
to_the_object_under_alt, canvas::tests::alt_over_another_object_draws_
the_distance_guide_label (frame test of the drawn label and line).
This commit is contained in:
Taha-Mahmoodi
2026-10-24 03:09:09 +07:00
committed by bflatastic
parent bfc2d6e439
commit a301760aa6
36 changed files with 389 additions and 4 deletions
+1
View File
@@ -234,6 +234,7 @@ pub const PREF_SPECS: &[PrefSpec] = &[
p!("anchorPathLabels", "Smart Guides", "Display Options", "Anchor/Path Labels", bool),
p!("measurementLabels", "Smart Guides", "Display Options", "Measurement Labels", bool),
p!("spacingGuides", "Smart Guides", "Display Options", "Spacing Guides", bool),
p!("distanceGuides", "Smart Guides", "Display Options", "Invoke Distance Guides", bool),
p!("snappingTolerance", "Smart Guides", "", "Snapping Tolerance", num(0.0, 40.0, "pt")),
p!("snapTangent", "Smart Guides", "Geometric Guides", "Snap to Tangent", bool),
p!("snapPerpendicular", "Smart Guides", "Geometric Guides", "Snap to Perpendicular", bool),
+2
View File
@@ -970,6 +970,7 @@ pub struct Prefs {
pub anchor_path_labels: bool,
pub measurement_labels: bool,
pub spacing_guides: bool,
pub distance_guides: bool,
pub snapping_tolerance: f64,
pub snap_tangent: bool,
pub snap_perpendicular: bool,
@@ -1221,6 +1222,7 @@ impl Default for Prefs {
anchor_path_labels: true,
measurement_labels: true,
spacing_guides: true,
distance_guides: true,
snapping_tolerance: 4.0,
snap_tangent: true,
snap_perpendicular: true,
+24
View File
@@ -616,6 +616,30 @@ fn spacing_guides_space_a_dragged_square_like_its_row() {
assert_eq!(drag(&mut s), (161.0, 0), "off: where it was dragged");
}
/// Smart Guides › Invoke Distance Guides: with a square selected, Alt held over another square to
/// its right shows the gap between them in the document's General unit; with the preference or
/// View › Smart Guides off, nothing.
#[test]
fn invoke_distance_guides_measures_the_selection_to_the_object_under_alt() {
use vectorcraft_tools::{Mods, Overlay, PointerKind::Move};
let mut s = new_doc();
let a = square(&mut s, 100.0, 100.0);
square(&mut s, 250.0, 100.0);
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
let v = ViewInfo::default();
s.select_tool("selection", v).unwrap();
let shown = |s: &mut Session, v: ViewInfo| {
s.pointer(&PointerEvent::new(Move, 275.0, 125.0).with_mods(Mods { alt: true, ..Mods::default() }), v).unwrap();
s.overlays(v).into_iter().filter_map(|o| if let Overlay::Distance { text, .. } = o { Some(text) } else { None }).collect::<Vec<_>>()
};
assert_eq!(shown(&mut s, v), ["100.00 pt"], "the 100 pt gap; the tops and bottoms are level");
s.execute("document.setUnits", &json!({"units": "Millimeters"})).unwrap();
assert_eq!(shown(&mut s, v), ["35.28 mm"]);
assert!(shown(&mut s, ViewInfo { smart_guides: false, ..v }).is_empty(), "View › Smart Guides off");
set_pref(&mut s, "distanceGuides", json!(false));
assert!(shown(&mut s, v).is_empty(), "Invoke Distance Guides off");
}
/// Preferences › Smart Guides (#394): Color, Alignment Guides, Anchor/Path Labels, Measurement
/// Labels, Transform Tools and Snapping Tolerance change what the Selection tool shows while a
/// square is dragged into line with another, and how far the pull reaches; a hidden guide still
+1
View File
@@ -282,6 +282,7 @@ impl Session {
measurement_labels: self.prefs.measurement_labels,
transform_tools_guides: self.prefs.transform_tools_guides,
spacing_guides: self.prefs.spacing_guides,
distance_guides: self.prefs.distance_guides,
snapping_tolerance: self.prefs.snapping_tolerance,
construction_angles: if self.prefs.construction_guides {
vectorcraft_tools::guides::construction_angles(&self.prefs.construction_angles)