Measurement Scale: write the readout's decimal mark as the fields do, and require one title (#17414)

The readout took the system mark only when it is . or ,; it now reads the mark from the env the
fields above it are drawn in (the system's or the host's region). The title test now counts the
frame's heading and requires exactly one.
This commit is contained in:
qvest-ssels committed 2026-11-29 08:09:19 +01:00
1 parent 284b517af7
commit a4eded0176
2 files changed
+25 -7

No files matched your search

+4 -3
View File
@@ -7,7 +7,7 @@ use craft::ui::dialog::DialogId;
use craft::ui::display::{Elide, Text};
use craft::ui::layout_components::{Row, Stack};
use craft::ui::patterns::form_dialogs::{DialogFields, Param, ParamDialog, ParamKind, ParamResult};
use craft::ui::runtime::env::{Label, UnitKind};
use craft::ui::runtime::env::{Env, Label, UnitKind};
use photocraft_doc::Document;
use photocraft_engine::analysis_cmds;
use serde_json::{Value, json};
@@ -171,8 +171,9 @@ fn form(kind: Kind, fields: &mut DialogFields) -> ParamDialog<'_> {
custom(Param::new("units", tl!("Logical Units:"), ParamKind::text("pixels"))),
];
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('.'));
// One line: units too long for it are cut with "…", so the dialog keeps its width (#17414). The decimal
// mark is the one the fields above write: the system's (any mark, not only `.` or `,`) or the host's.
let text = scale_readout(f, Env::of(ui).format().separators().0);
// 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();
@@ -2,7 +2,10 @@
//! the values are typed, on one line: units too long for it are cut with "…" and the dialog keeps its width. The title
//! "Measurement Scale" shows once, in the dialog's frame.
use std::cell::Cell;
use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog};
use craft::ui::runtime::env::Env;
use egui::accesskit::Role;
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
@@ -15,6 +18,17 @@ type H = Harness<'static, Box<PhotocraftApp>>;
const COMMAND: &str = "image.analysis.setMeasurementScale";
thread_local! {
/// The decimal mark the dialog's fields write, from the env they are drawn in: the system region's unless the
/// host sets one.
static MARK: Cell<char> = const { Cell::new('.') };
}
/// `text` with `.` replaced by the fields' decimal mark.
fn localized(text: &str) -> String {
text.replace('.', &MARK.get().to_string())
}
fn fields(preset: &str, pixels: f64, length: f64, units: &str) -> DialogFields {
let mut f = DialogFields::new();
f.set("preset", preset);
@@ -43,6 +57,7 @@ fn open() -> H {
if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
return;
}
MARK.set(Env::of(ui).format().separators().0);
crate::dialogs::run(app, ui);
},
app,
@@ -81,13 +96,13 @@ fn dialog_width(h: &H) -> f32 {
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");
assert_eq!(default_text, localized("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_eq!(text, localized("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");
@@ -101,9 +116,11 @@ fn the_readout_follows_typing_and_long_units_stay_on_one_line_without_growing_th
#[test]
fn the_title_shows_once() {
let h = open();
// The frame draws its title as a heading; a second copy in the body would be a label.
let shown = h
.query_all_by_role(Role::Label)
.query_all_by_role(Role::Heading)
.chain(h.query_all_by_role(Role::Label))
.filter(|n| n.accesskit_node().value().or_else(|| n.accesskit_node().label()).as_deref() == Some("Measurement Scale"))
.count();
assert!(shown <= 1, "\"Measurement Scale\" is drawn {shown} times");
assert_eq!(shown, 1, "\"Measurement Scale\" is drawn {shown} times");
}