diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index d85c08138..c32e8665b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -3372,6 +3372,20 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { let (ok_label, close_label) = action_labels(&d.kind); // What the footer's OK takes, for the check in the view's corner too (#6709). let ok_enabled = valid && !ok_label.is_empty() && app.applying.is_none(); + // #10620: the card widens to fit its widest label in the current language. The body + // publishes the extra it needs under this key each pass; the card applies it next pass, + // so the label column grows and the control column keeps its design width. Manager cards + // keep their approved fixed width. + let manager = matches!( + d.kind, + Kind::Material { .. } + | Kind::Appearance(_) + | Kind::Motion(crate::dialogs_motion::Mo::Configurations { .. }) + | Kind::Sheet(crate::dialogs_sheet::Sm::Rules { .. }) + | Kind::Plastic(crate::dialogs_plastic::Pl::Rules { .. }) + ); + let grow_key = egui::Id::new(("sc_dialog_label_grow", raw_title)); + let label_grow = ctx.data(|data| data.get_temp::(grow_key)).unwrap_or(0.0).min((vp.width() - t.space_24 - card_width(&d)).max(0.0)); let panel = crate::ui_kit::Panel::new(&heading, egui::Id::new(("sc_dialog", title(&d.kind))), anchor, drag_bounds, side, frame) .actions(ok_label, close_label); let panel = if let Some(column) = column { @@ -3379,8 +3393,10 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { } else if wide && side == crate::frame::Side::Left { let available = app.viewport.palette_rect.map_or(vp.width(), |r| (r.left() - vp.left() - t.space_8).max(0.0)); panel.width(card_width(&d).min(available)) - } else { + } else if manager { panel.width(card_width(&d)) + } else { + panel.width(card_width(&d) + label_grow).grow_label(grow_key) }; let reset_scroll = d.reset_scroll; let panel = @@ -3414,14 +3430,6 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { let heading = crate::ui_kit::FeatureOptions { icon, title: label, drag_key, moved, docked, apply_label: repeatable.then_some("Apply") }; let applying = app.applying.is_some(); let mut collapsed = d.collapsed; - let manager = matches!( - d.kind, - Kind::Material { .. } - | Kind::Appearance(_) - | Kind::Motion(crate::dialogs_motion::Mo::Configurations { .. }) - | Kind::Sheet(crate::dialogs_sheet::Sm::Rules { .. }) - | Kind::Plastic(crate::dialogs_plastic::Pl::Rules { .. }) - ); // A study/configuration owns Enter for its cells, including when folded. let cell_enter = matches!(&d.kind, Kind::Motion(k) if k.wide()) || matches!(&d.kind, Kind::Material { editor, .. } if editor.editing()); if cell_enter && collapsed { diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs index 6e0d5d746..4cd548cc5 100644 --- a/crates/ui-egui/src/dialogs_all_tests.rs +++ b/crates/ui-egui/src/dialogs_all_tests.rs @@ -578,6 +578,38 @@ fn new_cards_settle_before_the_first_click_in_both_layouts() { } } +#[test] +fn the_loft_dialog_widens_its_label_column_for_the_current_language() { + // #10620: German "Anpassung an Leitkurve" (Rail Fit) clipped to "Anpassung an Leit…" in + // the fixed-width Loft card. The label column now measures the dialog's labels in the + // active language and the card widens by the same amount, so the label fits and the + // control column keeps its design width. English, whose labels fit the design, is unchanged. + let t = Tokens::get(); + let shoot = |language: &str| { + let mut h = fixture(); + h.call("ui.resize", json!({"width": 1400, "height": 950})); + h.app.preferences.language = language.into(); + h.app.dialog = Some(representative(&h, "solid.loft")); + h.frames(4); + (h, scenario::rect_of("dialog:card").unwrap(), scenario::rect_of("dialog:label:Rail Fit").unwrap()) + }; + let (h, card, label) = shoot("de"); + let (_, english_card, english_label) = shoot("en"); + assert!(card.width() > english_card.width(), "the German card widened: {card:?} vs {english_card:?}"); + assert!(label.width() > t.form_label_width * 1.6, "past the ordinary cap: {label:?}"); + assert!(english_label.width() <= t.form_label_width * 1.6, "English keeps the design's label column: {english_label:?}"); + // The drawn galley holds the whole translation: no ellipsis. + let drawn = h + .shapes + .iter() + .find_map(|shape| match &shape.shape { + egui::Shape::Text(text) if text.galley.job.text.contains("Anpassung") => Some(text.galley.job.text.to_string()), + _ => None, + }) + .expect("the Rail Fit row drew its German label"); + assert!(drawn.contains("Leitkurve") && !drawn.contains('…'), "the label is not ellipsized: {drawn:?}"); +} + #[test] fn remaining_dialogs_keep_kit_chrome_and_cancel_restores_preview() { for command in [ diff --git a/crates/ui-egui/src/ui_kit/layout.rs b/crates/ui-egui/src/ui_kit/layout.rs index d299fc7ed..a76da8b19 100644 --- a/crates/ui-egui/src/ui_kit/layout.rs +++ b/crates/ui-egui/src/ui_kit/layout.rs @@ -7,6 +7,15 @@ pub(super) const FORM: &str = "sc_dense_form"; pub(super) const LABEL: &str = "sc_form_label"; pub(super) const FIXED_LABEL: &str = "sc_fixed_label_width"; +pub(super) const GROW_LABEL: &str = "sc_grow_label_column"; + +/// A form whose card widens so its widest label fits (#10620). Each pass the form publishes, +/// under `key`, the width its label column needs beyond the design's 1.6x cap; the card's +/// owner reads that before opening the card, so the card settles one frame later. +/// Tokens: `form_label_width, font_label, dialog_label, space_4`. +pub(super) fn scope_grow(ui: &mut Ui, key: egui::Id, add: impl FnOnce(&mut Ui) -> R) -> R { + scope_inner(ui, Some(key), add) +} /// A deliberate label grid for multi-column settings, inherited by the existing shared rows. pub(crate) fn settings_form(ui: &mut Ui, label_width: f32, add: impl FnOnce(&mut Ui) -> R) -> R { @@ -17,7 +26,15 @@ pub(crate) fn settings_form(ui: &mut Ui, label_width: f32, add: impl FnOnce(& /// Mark a form without global state: children inherit this tag through their UI stack. /// Inherited form styling and label-column identity. Tokens: `space_4/8, form_gap_y, control_height, font_label, accent, selected_bg, dialog_rule, control_fill/border/radius, text`. pub(crate) fn scope(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R { - ui.scope_builder(egui::UiBuilder::new().ui_stack_info(egui::UiStackInfo::default().with_tag(FORM)), |ui| { + scope_inner(ui, None, add) +} + +fn scope_inner(ui: &mut Ui, grow: Option, add: impl FnOnce(&mut Ui) -> R) -> R { + let mut info = egui::UiStackInfo::default().with_tag(FORM); + if let Some(key) = grow { + info = info.with_tag_value(GROW_LABEL, key); + } + ui.scope_builder(egui::UiBuilder::new().ui_stack_info(info), |ui| { let t = Tokens::get(); ui.spacing_mut().item_spacing = vec2(t.space_4, t.form_gap_y); ui.spacing_mut().interact_size.y = row_height(); diff --git a/crates/ui-egui/src/ui_kit/metrics.rs b/crates/ui-egui/src/ui_kit/metrics.rs index 775523829..6990ea468 100644 --- a/crates/ui-egui/src/ui_kit/metrics.rs +++ b/crates/ui-egui/src/ui_kit/metrics.rs @@ -107,7 +107,21 @@ pub(super) fn label_column(ui: &Ui, text: &str, row_width: f32) -> f32 { } None => natural, }; - (widest + t.space_4).clamp(base, base * LABEL_COLUMN_MAX).min(row_width * 0.5) + let needed = widest + t.space_4; + if let Some(&key) = ui.stack().iter().find_map(|node| node.tags().get_downcast::(super::layout::GROW_LABEL)) { + // A growing card (#10620): labels up to the ordinary 1.6x cap keep the design's card + // width; a longer label grows the column past the cap, and the extra the card must + // gain is published under `key` so the card widens by the same amount and the + // control column keeps its design width. + let extra = (needed - base * LABEL_COLUMN_MAX).max(0.0); + let previous = ui.ctx().data(|d| d.get_temp::(key)).unwrap_or(0.0); + if (extra - previous).abs() > 0.5 { + ui.ctx().request_discard("dialog label column width"); + } + ui.ctx().data_mut(|d| d.insert_temp(key, extra)); + return needed.max(base).min(row_width * 0.7); + } + needed.clamp(base, base * LABEL_COLUMN_MAX).min(row_width * 0.5) } #[cfg(test)] diff --git a/crates/ui-egui/src/ui_kit/metrics_tests.rs b/crates/ui-egui/src/ui_kit/metrics_tests.rs index 963642f9e..2ee9025a2 100644 --- a/crates/ui-egui/src/ui_kit/metrics_tests.rs +++ b/crates/ui-egui/src/ui_kit/metrics_tests.rs @@ -1,3 +1,4 @@ +use crate::theme::Tokens; use crate::ui_kit::metrics::dimension; use crate::ui_kit::test_support::*; use crate::ui_kit::*; @@ -22,6 +23,36 @@ fn non_finite_and_tiny_row_widths_are_sanitized() { } } +#[test] +fn a_growing_form_widens_past_the_cap_and_publishes_the_card_extra() { + // #10620: inside `grow_form` the label column takes the width the widest label needs, + // past the 1.6x cap an ordinary form clamps to, and the card's owner is told by how much + // the card must widen so the control column keeps its room. + let ctx = egui::Context::default(); + crate::fonts::setup_fonts(&ctx); + let t = Tokens::get(); + let key = egui::Id::new("grow-test"); + let long = "Anpassung an Leitkurve"; + let mut label = None; + for _ in 0..3 { + let mut output = ctx.run_ui(egui::RawInput::default(), |ui| { + ui.set_width(300.0); + scope_grow(ui, key, |ui| { + let mut value = String::new(); + row(ui, long, |ui| field(ui, &mut value)); + }); + }); + output.textures_delta.clear(); + label = scenario::rect_of(&format!("dialog:label:{long}")); + } + let label = label.unwrap(); + let measured = ctx.fonts_mut(|f| f.layout_no_wrap(long.to_owned(), egui::FontId::proportional(t.font_label), t.dialog_label)).size().x; + assert!(label.width() > t.form_label_width * 1.6, "past the ordinary cap: {label:?}"); + assert!(label.width() >= measured, "the label fits its column: {label:?} vs {measured}"); + let extra = ctx.data(|d| d.get_temp::(key)).unwrap(); + assert!((extra - (label.width() - t.form_label_width * 1.6)).abs() < 0.01, "the card grows only past the cap: {extra}"); +} + #[test] fn file_tiles_are_fixed_height_bounded_and_disabled_actions_stay_inert() { let ctx = crate::fonts::test_context(); diff --git a/crates/ui-egui/src/ui_kit/panel.rs b/crates/ui-egui/src/ui_kit/panel.rs index a686c4122..d9bd34b29 100644 --- a/crates/ui-egui/src/ui_kit/panel.rs +++ b/crates/ui-egui/src/ui_kit/panel.rs @@ -282,6 +282,7 @@ pub(crate) struct Panel<'a> { cancel: &'a str, reset_scroll: bool, joined: Option, + grow_key: Option, } pub(crate) struct WorkspaceOptions<'a> { @@ -600,6 +601,7 @@ impl<'a> Panel<'a> { cancel: "Cancel", reset_scroll: false, joined: None, + grow_key: None, } } @@ -621,6 +623,13 @@ impl<'a> Panel<'a> { self } + /// The feature card's form measures its labels and publishes the width it needs under + /// this key, so the card can widen for the current language (#10620). + pub(crate) fn grow_label(mut self, key: egui::Id) -> Self { + self.grow_key = Some(key); + self + } + /// The footer's primary and closing actions when they are not OK and Cancel. An empty `ok` /// leaves the primary action out (a card that only closes, e.g. Measure). pub(crate) fn actions(mut self, ok: &'a str, cancel: &'a str) -> Self { @@ -759,7 +768,7 @@ impl<'a> Panel<'a> { mut collapsed: Option<&mut bool>, body: impl FnOnce(&mut Ui) -> ComputeStatus, ) -> (bool, super::Action) { - super::scope(ui, |ui| { + let card = |ui: &mut Ui| { let t = Tokens::get(); let min = ui.cursor().min; let band = egui::Rect::from_min_size(min, vec2(ui.available_width(), super::header_height())); @@ -845,7 +854,11 @@ impl<'a> Panel<'a> { ); super::Container::finish_content(ui, self.positioned_frame(ui.ctx())); (close, action) - }) + }; + match self.grow_key { + Some(key) => super::scope_grow(ui, key, card), + None => super::scope(ui, card), + } } /// Palette composition retains its compact padding and whole-card scrolling on short views.