SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Parameters: show full names in the table and formula popup (#8533) (#8551)
SilentWolf75c6c91e6f4387
diff --git a/crates/ui-egui/src/expression_complete.rs b/crates/ui-egui/src/expression_complete.rsindex a427dfc7ef..7be658b0d9 100644--- a/crates/ui-egui/src/expression_complete.rs+++ b/crates/ui-egui/src/expression_complete.rs@@ -329,6 +329,55 @@ mod tests {}}+ /// #8533: a long parameter name widens the completion popup past a narrow editor.+ #[test]+ fn long_parameter_names_widen_the_completion_popup() {+ let short = Editor::new("wi");+ assert!(showing(&short.ctx, short.id));+ let short_w = crate::scenario::rect_of("dialog:suggestions").map(|r| r.width()).unwrap_or(0.0);++ let ctx = crate::fonts::test_context();+ let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default());+ let long = "Driver_MountHole_to_Cover_Shared_Base_Layout_Angle";+ app.run("parameters.add", json!({"name": long, "expression": "8 deg"})).unwrap();+ params_dialog::publish(&mut app, &ctx);+ let id = egui::Id::new("long_name_completion");+ ctx.memory_mut(|m| m.request_focus(id));+ let mut text = "Driver".to_string();+ let mut output = ctx.run_ui(+ egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 400.0))), ..Default::default() },+ |ui| {+ begin_frame(ui.ctx());+ params_dialog::publish(&mut app, ui.ctx());+ egui::CentralPanel::default().show(ui, |ui| {+ let response = ui.add(egui::TextEdit::singleline(&mut text).id(id).desired_width(120.0));+ let mut state = egui::TextEdit::load_state(ui.ctx(), id).unwrap_or_default();+ state.cursor.set_char_range(Some(egui::text::CCursorRange::one(egui::text::CCursor::new(text.chars().count()))));+ state.store(ui.ctx(), id);+ let _ = complete(ui, &response, &mut text);+ });+ },+ );+ output.textures_delta.clear();+ // A second frame so the popup sees the caret after "Driver".+ let mut output = ctx.run_ui(+ egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 400.0))), ..Default::default() },+ |ui| {+ begin_frame(ui.ctx());+ params_dialog::publish(&mut app, ui.ctx());+ egui::CentralPanel::default().show(ui, |ui| {+ let response = ui.add(egui::TextEdit::singleline(&mut text).id(id).desired_width(120.0));+ let _ = complete(ui, &response, &mut text);+ });+ },+ );+ output.textures_delta.clear();+ assert!(suggestions(&ctx, "Driver").iter().any(|s| s.text == long));+ let long_w = crate::scenario::rect_of("dialog:suggestions").map(|r| r.width()).unwrap_or(0.0);+ assert!(long_w > short_w + 40.0, "long name popup {long_w} should outgrow short {short_w}");+ assert!(long_w > 200.0, "popup should not stay locked to a narrow editor ({long_w})");+ }+#[test]fn arrows_cycle_without_moving_caret_enter_accepts_selected_without_leaking() {let mut e = Editor::new("2 * wi");diff --git a/crates/ui-egui/src/params_dialog.rs b/crates/ui-egui/src/params_dialog.rsindex e0fb32a4ab..4677a7be9c 100644--- a/crates/ui-egui/src/params_dialog.rs+++ b/crates/ui-egui/src/params_dialog.rs@@ -395,15 +395,22 @@ fn new_check(app: &mut SolveApp, d: &mut ParamsDialog, unit: &str) -> Result<Strfn table(app: &mut SolveApp, ui: &mut egui::Ui, d: &mut ParamsDialog, rows: &[&Row], salt: &str) {let units: Vec<_> = UNITS.iter().map(|unit| unit_label(unit)).collect();+ // Name keeps a larger share and a content floor so long identifiers stay readable (#8533).+ // Full window/column resize is #5097; hover still shows the whole name when clipped.+ let name_floor = rows+ .iter()+ .map(|r| ui_kit::ContentWidth::name(ui, &r.name))+ .fold(crate::theme::Tokens::get().form_label_width, f32::max)+ .min(crate::theme::Tokens::get().form_card_width);let columns = [Column::new("", 0.0).min_content_width(crate::theme::Tokens::get().space_24 * 3.0),- Column::new("Name", 1.1).flex(),+ Column::new("Name", 2.0).flex().min_content_width(name_floor),Column::new("Unit", 0.65).min_content_width(ui_kit::ContentWidth::dropdown(ui, &units).max(crate::theme::Tokens::get().space_24 * 3.0 + crate::theme::Tokens::get().space_6),),Column::new("Expression", 1.5).flex(),Column::new("Value", 1.1).flex(),- Column::new("Comment", 1.2).flex(),+ Column::new("Comment", 1.0).flex(),Column::new("Actions", 0.0).icon_only().min_content_width(ui_kit::table_row_height()),];ui_kit::table(ui, salt, &columns, crate::i18n::tr("manage.empty"), |ui, table| {@@ -454,8 +461,9 @@ fn table(app: &mut SolveApp, ui: &mut egui::Ui, d: &mut ParamsDialog, rows: &[&R}}_ => {- let response =- ui_kit::text(ui, &r.name, ui_kit::Text::NameCell(false)).on_hover_text(crate::i18n::tr_label("Double-click to rename"));+ let rename = crate::i18n::tr_label("Double-click to rename");+ // Always tip the full name: the Name cell clips long identifiers (#8533).+ let response = ui_kit::text(ui, &r.name, ui_kit::Text::NameCell(false)).on_hover_text(format!("{}\n{rename}", r.name));crate::scenario::publish_handle(&format!("param:name:{}", r.name), response.rect.center());if response.double_clicked() {d.renaming = Some((r.name.clone(), r.name.clone()));diff --git a/crates/ui-egui/src/ui_kit/choice.rs b/crates/ui-egui/src/ui_kit/choice.rsindex fc6911edbf..5cd2d94c97 100644--- a/crates/ui-egui/src/ui_kit/choice.rs+++ b/crates/ui-egui/src/ui_kit/choice.rs@@ -621,6 +621,19 @@ pub(crate) fn popup_list(let t = crate::theme::Tokens::get();let mut chosen = None;let mut rows = Vec::with_capacity(options.len());+ // Wide enough for the longest suggestion; still capped so a hostile name cannot fill the screen (#8533).+ let mono = egui::FontId::monospace(t.font_body);+ let kind_font = egui::FontId::proportional(t.font_small);+ let content_w = options+ .iter()+ .map(|option| {+ let text_w = ctx.fonts_mut(|fonts| fonts.layout_no_wrap(option.text.to_owned(), mono.clone(), option.color)).size().x;+ let kind = crate::i18n::tr_label(option.kind);+ let kind_w = ctx.fonts_mut(|fonts| fonts.layout_no_wrap(kind.to_owned(), kind_font.clone(), t.form_dim)).size().x;+ text_w + kind_w + t.space_8 * 3.0+ })+ .fold(0.0_f32, f32::max);+ let width = anchor.width().max(t.form_card_width - t.space_16 * 2.0 - t.space_2).max(content_w).min(t.form_card_width * 2.5);let popup = Container::new(ctx, Surface::Popup).area(id);let area = popup.order(egui::Order::Tooltip).fixed_pos(anchor.left_bottom() + egui::vec2(0.0, t.space_2)).show(ctx, |ui| {Container::popup_frame(ui.style())@@ -630,7 +643,7 @@ pub(crate) fn popup_list(.inner_margin(t.space_4).show(ui, |ui| {super::scope(ui, |ui| {- ui.set_width(anchor.width().max(t.form_card_width - t.space_16 * 2.0 - t.space_2));+ ui.set_width(width);for (index, option) in options.iter().enumerate() {let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), t.control_height), egui::Sense::CLICK);rows.push(rect);@@ -645,23 +658,12 @@ pub(crate) fn popup_list(inner.min,egui::pos2((inner.right() - kind_width - t.space_8).max(inner.left()), inner.bottom()),);- super::text::paint_text(- ui,- text_rect,- option.text,- egui::FontId::monospace(t.font_body),- if picked { t.form_primary } else { option.color },- false,- );- ui.painter().text(- inner.right_center(),- egui::Align2::RIGHT_CENTER,- kind,- egui::FontId::proportional(t.font_small),- t.form_dim,- );+ super::text::paint_text(ui, text_rect, option.text, mono.clone(), if picked { t.form_primary } else { option.color }, false);+ ui.painter().text(inner.right_center(), egui::Align2::RIGHT_CENTER, kind, kind_font.clone(), t.form_dim);response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, ui.is_enabled(), picked, option.text));- let response = response.on_hover_text(option.detail);+ // Tip the full name first: long identifiers still clip inside a capped popup.+ let tip = if option.detail.is_empty() { option.text.to_owned() } else { format!("{}\n{}", option.text, option.detail) };+ let response = response.on_hover_text(tip);crate::scenario::publish_handle(&format!("dialog:suggestion:{index}"), response.rect.center());if response.clicked() {chosen = Some(index);