PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
fix(ui): the size field stays within its room in the row in every language (#5634)
RiceDee89efc79ecde4
diff --git a/crates/ui-egui/src/panels/format_text_ui.rs b/crates/ui-egui/src/panels/format_text_ui.rsindex 38ccb96b1..669c9b5e9 100644--- a/crates/ui-egui/src/panels/format_text_ui.rs+++ b/crates/ui-egui/src/panels/format_text_ui.rs@@ -109,9 +109,10 @@ const LABEL_ICON: f32 = 22.0;const PRESET_LIST: f32 = 22.0;/// The room a number field keeps for its value ("-5.0 pt"), beside the arrow in its box.const NUMBER_MIN: f32 = 52.0;-/// The size field, which reserves room for "Mixed" so it doesn't resize while typing.-/// shortcut: measured for English "Mixed"; a longer translation widens the size row past the-/// narrowest pane. Upgrade by having the panel report its measured row width to the pane.+/// The size field's room in the row: English "Mixed", its margins and the 2 pt of its box. The+/// field reserves room for "Mixed" so it doesn't resize while typing, but no more than this.+/// shortcut: a longer translation of "Mixed" scrolls in the field. Upgrade by having the panel+/// report its measured row width to the pane, if that reads badly.const SIZE_FIELD: f32 = 62.0;/// The least width the panel's widest rows need, which sets how narrow the Tools pane may be/// dragged. Size and alignment: the size field and its arrow (in their box), the swatch, the@@ -558,7 +559,9 @@ fn font_size_input(ui: &mut egui::Ui, size: &mut f64, mixed: bool) -> bool {// Reserve the localized mixed label, field margins and caret without resizing while typing.let font = egui::TextStyle::Body.resolve(ui.style());let mixed_width = ui.painter().layout_no_wrap(tl!("Mixed").into(), font.clone(), ui.visuals().text_color()).size().x;- let width = (mixed_width + margin.sum().x + 2.0).ceil().max(40.0);+ // Within the row's allowance, so a long translation ("Valeurs différentes") scrolls in the+ // field rather than pushing the row past the pane.+ let width = (mixed_width + margin.sum().x + 2.0).ceil().clamp(40.0, SIZE_FIELD - 2.0);let field = egui::TextEdit::singleline(&mut text).id(id).font(font)diff --git a/crates/ui-egui/tests/it/content.rs b/crates/ui-egui/tests/it/content.rsindex 80d08d199..dc287eb48 100644--- a/crates/ui-egui/tests/it/content.rs+++ b/crates/ui-egui/tests/it/content.rs@@ -757,9 +757,9 @@ fn format_text_fits_the_tools_pane_at_its_narrowest() {}}-/// The lists in Format text fit the narrowest Tools pane in every interface language: "Auto" in-/// the line spacing list is the one word in them that is translated, and in German, Ukrainian or-/// Lao it is twice as long. The font list spans the pane, so nothing may end past it.+/// The lists and the size row in Format text fit the narrowest Tools pane in every interface+/// language: "Auto" in the line spacing list and "Mixed" in the size field are translated, and in+/// Czech or French they are much longer. The font list spans the pane, so nothing may end past it.#[test]fn format_text_lists_fit_the_narrowest_tools_pane_in_every_language() {use egui::accesskit::Role;@@ -780,6 +780,9 @@ fn format_text_lists_fit_the_narrowest_tools_pane_in_every_language() {for r in &lists {assert!(r.right() <= font.right() + 0.5, "{}: {r:?} reaches past the font list ({font:?})", lang.code());}+ // The size row too: its field reserves room for a translated "Mixed".+ let align = h.get_by_label(pdfcraft_ui_egui::i18n::t("Alignment")).rect();+ assert!(align.right() <= font.right() + 0.5, "{}: Alignment {align:?} reaches past the font list ({font:?})", lang.code());}}