From 284b517af72e7fc259cba9716e482f3fb09cd569 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:47:46 +0100 Subject: [PATCH] Measurement Scale: size the readout by its own text, up to the fields' width (#17414) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fixed sample cut even a short readout ("200 pixel(s) = 25,000…"). The readout now asks for the width of its first 46 characters, so one that fits shows whole and only long units are cut. --- crates/ui-egui/src/tools/analysis/dialogs.rs | 9 +++++++-- crates/ui-egui/src/tools/analysis/scale_readout_tests.rs | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/tools/analysis/dialogs.rs b/crates/ui-egui/src/tools/analysis/dialogs.rs index 0b9e629385..071734ad5c 100644 --- a/crates/ui-egui/src/tools/analysis/dialogs.rs +++ b/crates/ui-egui/src/tools/analysis/dialogs.rs @@ -134,6 +134,9 @@ pub(crate) fn run(app: &mut PhotocraftApp, _ctx: &egui::Context, result: ParamRe } } +/// The most characters of the scale readout that set its width: about the width of the dialog's fields. +const READOUT_CHARS: usize = 46; + /// The Measurement Scale readout: ` pixel(s) = `, with `decimal` as the decimal mark, /// as the reference shows it while the values are typed (#17414). The Default preset reads 1 pixel(s) = 1 pixels. pub(crate) fn scale_readout(f: &DialogFields, decimal: char) -> String { @@ -170,8 +173,10 @@ fn form(kind: Kind, fields: &mut DialogFields) -> ParamDialog<'_> { ParamDialog::command(key, tl!("Measurement Scale"), rows).below(|ui, f| { // One line: units too long for it are cut with "…", so the dialog keeps its width (#17414). let text = scale_readout(f, crate::i18n::decimal_separator().unwrap_or('.')); - // The sample gives the readout a fixed ideal width, so long units never widen the dialog. - Text::new(Label::from(text)).elide(Elide::End).sample(Label::from("1 pixel(s) = 1.0000 pixels")).show(ui); + // The readout asks for the width of its text up to READOUT_CHARS characters, so a short one shows whole + // and long units are cut with "…" instead of widening the dialog. + let sample: String = text.chars().take(READOUT_CHARS).collect(); + Text::new(Label::from(text)).elide(Elide::End).sample(Label::from(sample)).show(ui); }) } Kind::DataPoints => { diff --git a/crates/ui-egui/src/tools/analysis/scale_readout_tests.rs b/crates/ui-egui/src/tools/analysis/scale_readout_tests.rs index d901e9d1e7..8712d491d5 100644 --- a/crates/ui-egui/src/tools/analysis/scale_readout_tests.rs +++ b/crates/ui-egui/src/tools/analysis/scale_readout_tests.rs @@ -80,12 +80,15 @@ fn dialog_width(h: &H) -> f32 { #[test] fn the_readout_follows_typing_and_long_units_stay_on_one_line_without_growing_the_dialog() { let mut h = open(); + let (default_text, default_rect) = readout(&h); + assert_eq!(default_text, "1 pixel(s) = 1.0000 pixels"); set(&mut h, "preset", json!("custom")); set(&mut h, "pixelLength", json!(200.0)); set(&mut h, "logicalLength", json!(25.0)); set(&mut h, "units", json!("Mikrometer")); let (text, short) = readout(&h); assert_eq!(text, "200 pixel(s) = 25.0000 Mikrometer", "live while typing"); + assert!(short.width() > default_rect.width() + 20.0, "a readout that fits shows whole: {default_rect:?} vs {short:?}"); let width = dialog_width(&h); assert!(width > 0.0, "the dialog has a frame");