mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Measure: with Measurement Labels off the measured line still draws, only its readout goes (#3128)
This commit is contained in:
@@ -53,21 +53,20 @@ impl Tool for MeasureTool {
|
||||
}
|
||||
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
if !cx.measurement_labels {
|
||||
return vec![];
|
||||
}
|
||||
let Some((a, b)) = self.line else { return vec![] };
|
||||
if a == b {
|
||||
return vec![];
|
||||
}
|
||||
let (dist, ang, dx, dy) = measure(a, b);
|
||||
vec![
|
||||
Overlay::Line { a, b, color: CYAN, dashed: false },
|
||||
Overlay::Measure {
|
||||
let mut out = vec![Overlay::Line { a, b, color: CYAN, dashed: false }];
|
||||
// Measurement Labels decides the readout; the line the tool draws stays.
|
||||
if cx.measurement_labels {
|
||||
let (dist, ang, dx, dy) = measure(a, b);
|
||||
out.push(Overlay::Measure {
|
||||
p: b + Vec2::new(cx.tol(12.0), cx.tol(12.0)),
|
||||
text: format!("D: {}\nAngle: {ang:.1}°\n{}", cx.len(dist), cx.offset_label(dx, dy)),
|
||||
},
|
||||
]
|
||||
});
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn cursor(&self, _cx: &ToolContext, _p: Point, _m: Mods) -> Cursor {
|
||||
@@ -108,6 +107,8 @@ mod tests {
|
||||
let ov = t.overlays(&cx);
|
||||
assert!(matches!(&ov[1], Overlay::Measure { text, .. } if text.starts_with("D: 50.00 pt")));
|
||||
let quiet = ToolContext { measurement_labels: false, ..cx };
|
||||
assert!(t.overlays(&quiet).is_empty(), "Measurement Labels off hides the readout");
|
||||
let ov = t.overlays(&quiet);
|
||||
assert!(!ov.iter().any(|o| matches!(o, Overlay::Measure { .. })), "Measurement Labels off hides the readout");
|
||||
assert!(ov.iter().any(|o| matches!(o, Overlay::Line { .. })), "the measured line stays");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user