From 3eb7b5085b18f6080db38dcd6e04833df6d29584 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 17 Oct 2026 06:27:34 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01CgGsJkVe5GYG9qK6VFdECa --- crates/tools/src/nav.rs | 4 ++-- crates/ui-egui/src/lib.rs | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/tools/src/nav.rs b/crates/tools/src/nav.rs index f371f267..f77c5d0b 100644 --- a/crates/tools/src/nav.rs +++ b/crates/tools/src/nav.rs @@ -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) ), }); } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index fcb764c5..70685206 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -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());