mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Measurement Scale: size the readout by its own text, up to the fields' width (#17414)
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.
This commit is contained in:
1 parent
7dde54de1b
commit
284b517af7
2 files changed
+10
-2
No files matched your search
@@ -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: `<px> pixel(s) = <length, 4 decimals> <units>`, 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 => {
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in new issue
Block a user