Merge pull request #1196 from seanth/tool-units

(fix)Tools: readouts measure in the document's ruler units
This commit is contained in:
Brandon Thomas
2026-10-19 02:49:58 -04:00
committed by GitHub
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());