mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
G1: honor Show Measurement Labels on pie, corners, width, and tiling readouts
Tools that showed distance or angle overlays during drags now respect the Units preference, consistent with shape and selection tools. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Cursor
parent
d507a73d09
commit
fd53416de3
@@ -374,7 +374,10 @@ impl CornerDrag {
|
||||
if !self.began {
|
||||
return vec![];
|
||||
}
|
||||
let mut out = vec![Overlay::Measure { p: self.at, text: format!("Radius: {}", cx.len(self.radius)) }];
|
||||
let mut out = vec![];
|
||||
if cx.measurement_labels {
|
||||
out.push(Overlay::Measure { p: self.at, text: format!("Radius: {}", cx.len(self.radius)) });
|
||||
}
|
||||
if self.at_limit {
|
||||
out.push(Overlay::Path { path: self.corners_at_limit(), color: crate::builder::HIGHLIGHT_RED, width: 2.0, dashed: false });
|
||||
}
|
||||
@@ -465,6 +468,8 @@ mod tests {
|
||||
assert!((radius(&a[1]) - 15.0).abs() < 1e-9);
|
||||
assert!(matches!(&a[1], Action::Preview(_, v) if v["id"] == id.0));
|
||||
assert!(t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Measure { text, .. } if text == "Radius: 15.00 pt")));
|
||||
let quiet = ToolContext { measurement_labels: false, ..crate::testutil::cx(&d, &s, &p) };
|
||||
assert!(!t.overlays(&quiet).iter().any(|o| matches!(o, Overlay::Measure { .. })));
|
||||
// Past the middle the corner is fully round; back outside it is square.
|
||||
assert_eq!(radius(&t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 100.0, 100.0))[0]), 50.0);
|
||||
assert_eq!(radius(&t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 260.0, 260.0))[0]), 0.0);
|
||||
|
||||
@@ -399,7 +399,9 @@ impl Tool for DimensionTool {
|
||||
for p in [a, b] {
|
||||
out.push(Overlay::Anchor { p, color, filled: true, size: 6.0 });
|
||||
}
|
||||
if let Ok(text) = self.style.label(a.distance(b), false) {
|
||||
if cx.measurement_labels
|
||||
&& let Ok(text) = self.style.label(a.distance(b), false)
|
||||
{
|
||||
out.push(Overlay::Measure { p: self.at + Vec2::new(12.0, 12.0), text });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1262,7 +1262,9 @@ impl Tool for PerspectiveSelectionTool {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((p, t)) = &self.measure {
|
||||
if cx.measurement_labels
|
||||
&& let Some((p, t)) = &self.measure
|
||||
{
|
||||
out.push(Overlay::Measure { p: *p, text: t.clone() });
|
||||
}
|
||||
out
|
||||
|
||||
@@ -435,7 +435,9 @@ impl Tool for WidthTool {
|
||||
let q = d.spot.p;
|
||||
out.push(Overlay::Line { a: q + d.spot.n * d.left, b: q - d.spot.n * d.right, color: BLUE, dashed: false });
|
||||
out.push(Overlay::Path { path: diamond(q, r), color: BLUE, width: 2.0, dashed: false });
|
||||
out.push(Overlay::Measure { p: q + d.spot.n * (d.left + r * 3.0), text: format!("W: {}", cx.stroke_unit.readout(d.left + d.right)) });
|
||||
if cx.measurement_labels {
|
||||
out.push(Overlay::Measure { p: q + d.spot.n * (d.left + r * 3.0), text: format!("W: {}", cx.stroke_unit.readout(d.left + d.right)) });
|
||||
}
|
||||
} else if let Some(h) = &self.hover {
|
||||
out.push(Overlay::Line { a: h.p + h.n * h.left, b: h.p - h.n * h.right, color: BLUE, dashed: true });
|
||||
out.push(Overlay::Path { path: diamond(h.p, r), color: BLUE, width: 1.0, dashed: false });
|
||||
|
||||
@@ -187,8 +187,8 @@ impl PieDrag {
|
||||
}
|
||||
|
||||
/// The angle readout next to the pointer.
|
||||
pub fn overlays(&self) -> Vec<Overlay> {
|
||||
if !self.began {
|
||||
pub fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
if !self.began || !cx.measurement_labels {
|
||||
return vec![];
|
||||
}
|
||||
vec![Overlay::Measure { p: self.at, text: format!("{:.1}°", self.angle) }]
|
||||
@@ -275,6 +275,8 @@ mod tests {
|
||||
assert!(v.get("pieStart").is_none(), "{v}");
|
||||
assert!(t.transforming());
|
||||
assert!(t.overlays(&c).iter().any(|o| matches!(o, Overlay::Measure { text, .. } if text == "90.0°")));
|
||||
let quiet = ToolContext { measurement_labels: false, ..cx(&d, &s, &p) };
|
||||
assert!(!t.overlays(&quiet).iter().any(|o| matches!(o, Overlay::Measure { .. })));
|
||||
// Below the center and to the left: 225°, on the ellipse's own angles (not the page's).
|
||||
let a = t.pointer(&c, &ev(PointerKind::Drag, Point::new(100.0, 200.0)));
|
||||
assert!(matches!(&a[0], Action::Preview(_, v) if (v["pieEnd"].as_f64().unwrap() - 225.0).abs() < 1e-9), "{a:?}");
|
||||
|
||||
@@ -79,7 +79,7 @@ impl Tool for PrintTilingTool {
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
match self.drag {
|
||||
// How far the corner is from the artboard's.
|
||||
Some((_, Some(r))) if self.began => {
|
||||
Some((_, Some(r))) if self.began && cx.measurement_labels => {
|
||||
vec![Overlay::Measure { p: self.last, text: cx.offset_label(self.last.x - r.x0, self.last.y - r.y0) }]
|
||||
}
|
||||
_ => vec![],
|
||||
@@ -122,6 +122,8 @@ mod tests {
|
||||
let a = t.pointer(&c, &ev(PointerKind::Drag, 2.0, 497.0));
|
||||
assert_eq!(a, vec![Action::Preview("print.tiling.set".into(), json!({"origin": [0.0, 500.0], "artboard": 0}))]);
|
||||
assert!(matches!(t.overlays(&c).as_slice(), [Overlay::Measure { .. }]));
|
||||
let quiet = ToolContext { measurement_labels: false, ..cx(&d, &s, &pd) };
|
||||
assert!(t.overlays(&quiet).is_empty());
|
||||
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, 2.0, 497.0)), vec![Action::Commit]);
|
||||
assert!(!t.busy());
|
||||
// A click alone changes nothing; a double click resets.
|
||||
|
||||
@@ -714,7 +714,7 @@ impl Tool for SelectionTool {
|
||||
match &self.state {
|
||||
State::Marquee { start, cur, .. } => o.push(Overlay::Marquee(Rect::from_points(*start, *cur))),
|
||||
State::Corner(c) => o.extend(c.overlays(cx)),
|
||||
State::Pie(d) => o.extend(d.overlays()),
|
||||
State::Pie(d) => o.extend(d.overlays(cx)),
|
||||
State::Loaded { press: Some((start, cur)), .. } => o.push(Overlay::Marquee(Rect::from_points(*start, *cur))),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user