diff --git a/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs b/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs index 5d2dab2b22..3d4d3a4309 100644 --- a/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs +++ b/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs @@ -183,6 +183,19 @@ fn width_and_height_refuse_a_value_their_rows_cannot_hold() { }); } +/// A size of 0 is the command's 8 x 10 in the units shown, so switching the units shows that size, not 0. +#[test] +fn switching_units_converts_a_zero_size_as_the_command_reads_it() { + crate::i18n::with_language(crate::i18n::Lang::EN, || { + let (mut h, id) = opened(); + pick_unit(&mut h, id, "inches"); + set(&mut h, id, "width", json!(0.0)); + pick_unit(&mut h, id, "cm"); + assert!((num(&h, id, "width") - 20.32).abs() < 1e-6, "width: {}", num(&h, id, "width")); + assert!((num(&h, id, "height") - 25.4).abs() < 1e-6, "height: {}", num(&h, id, "height")); + }); +} + /// Picks `unit` in the Units list, as the list's pick does. fn pick_unit(h: &mut H, id: DialogId, unit: &str) { set(h, id, "units", json!(unit)); diff --git a/crates/ui-egui/src/dialogs/contact_sheet_ui.rs b/crates/ui-egui/src/dialogs/contact_sheet_ui.rs index 716a2f9b29..849af9ebf3 100644 --- a/crates/ui-egui/src/dialogs/contact_sheet_ui.rs +++ b/crates/ui-egui/src/dialogs/contact_sheet_ui.rs @@ -80,7 +80,9 @@ pub(crate) fn follow_units(fields: &mut DialogFields) { let ppi = fields.number("resolution").unwrap_or(300.0); let (from, to) = (unit_of(&shown), unit_of(&units)); for (key, default) in [("width", 8.0), ("height", 10.0)] { - let v = to.from_px(from.to_px(fields.number(key).unwrap_or(default), ppi, 0.0, 72.0), ppi, 0.0, 72.0); + // The command reads no size or 0 as 8 x 10 in the units it is given, so that is the size to convert. + let shown = fields.number(key).filter(|v| v.is_finite() && *v > 0.0).unwrap_or(default); + let v = to.from_px(from.to_px(shown, ppi, 0.0, 72.0), ppi, 0.0, 72.0); // Kept unrounded (the field shows two decimals): a small pixel size at a high resolution would round to // 0 in, which the command reads as no size. Pixels are whole. fields.set(key, if to == Unit::Pixels { v.round() } else { v });