Tools: readouts measure in the document's ruler units

Tool readouts (the Page tool's size while dragging, smart-guide distances, the
resize readout) took their unit from the UI's own setting, which nothing changes
from picas, so a document set to inches read in picas. The tool context now takes
the active document's horizontal ruler unit, and the Page tool's W/H use the
horizontal and vertical units, as the Control and Properties fields do.

Test: tool_readouts_measure_in_the_documents_units (picas before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CgGsJkVe5GYG9qK6VFdECa
This commit is contained in:
Claude
2026-10-17 06:27:34 +00:00
parent fc36957fe0
commit 3eb7b5085b
2 changed files with 16 additions and 3 deletions
+2 -2
View File
@@ -434,8 +434,8 @@ impl Tool for PageTool {
p: d.cur,
text: format!(
"W: {}\nH: {}",
designcraft_geom::format_measure(pg.width, cx.unit),
designcraft_geom::format_measure(pg.height, cx.unit)
designcraft_geom::format_measure(pg.width, cx.doc.settings.horizontal_units),
designcraft_geom::format_measure(pg.height, cx.doc.settings.vertical_units)
),
});
}
+14 -1
View File
@@ -737,7 +737,9 @@ impl DesignApp {
ViewInfo {
zoom: self.view().map(|v| v.zoom).unwrap_or(1.0),
snap: self.ui.snap_view(),
unit: self.ui.units,
// Tool readouts (sizes, smart-guide distances) measure in the document's ruler units,
// as its Control and Properties fields do.
unit: self.session.active().map_or(self.ui.units, |st| st.doc.settings.horizontal_units),
stroke_in_front: self.ui.stroke_front,
}
}
@@ -1843,6 +1845,17 @@ mod tests {
assert!(!accurate.rich_black, "a saved choice is kept");
}
/// Tool readouts measured in picas whatever the document's units (the UI's unit is never set):
/// they follow the active document's ruler units.
#[test]
fn tool_readouts_measure_in_the_documents_units() {
let mut app = DesignApp::new(designcraft_engine::Session::new(), Services::default());
assert_eq!(app.view_info().unit, Unit::Picas, "no document: the UI's default");
app.run("file.new", json!({})).unwrap();
app.run("document.preferences", json!({"horizontalUnits": "inches", "verticalUnits": "millimeters"})).unwrap();
assert_eq!(app.view_info().unit, Unit::Inches);
}
/// An app with one document that has an unsaved edit.
fn app_with_unsaved_document() -> DesignApp {
let mut app = DesignApp::new(designcraft_engine::Session::new(), Services::default());