SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Keep long Select Other labels inside the popup (#4209) (#4225)
Colin Faulkingham1bbc5ab0f78e
diff --git a/crates/ui-egui/src/select_other.rs b/crates/ui-egui/src/select_other.rsindex 070418267e..6dd7cd9802 100644--- a/crates/ui-egui/src/select_other.rs+++ b/crates/ui-egui/src/select_other.rs@@ -547,13 +547,19 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {row.icon,f32::from(t.icon.a()) / 255.0,);- ui.painter().text(- pos2(r.left() + 32.0, r.center().y),- Align2::LEFT_CENTER,- &row.label,- FontId::proportional(crate::theme::Tokens::get().font_button),- t.text,- );+ // Names can be wider than the list. Keep one line inside the row and+ // expose the full name on hover, as the browser tree does.+ let text_rect = Rect::from_min_max(pos2(r.left() + 32.0, r.top()), pos2(r.right() - 8.0, r.bottom()));+ let mut job =+ egui::text::LayoutJob::simple(row.label.clone(), FontId::proportional(t.font_button), t.text, text_rect.width());+ job.wrap.max_rows = 1;+ job.wrap.break_anywhere = true;+ job.wrap.overflow_character = Some('\u{2026}');+ let galley = ui.painter().layout_job(job);+ let elided = galley.elided;+ let at = pos2(text_rect.left(), r.center().y - galley.size().y / 2.0);+ ui.painter().with_clip_rect(ui.clip_rect().intersect(text_rect)).galley(at, galley, t.text);+ let resp = if elided { resp.on_hover_text(&row.label) } else { resp };if resp.clicked() {picked = Some(i);}diff --git a/crates/ui-egui/src/select_other_tests.rs b/crates/ui-egui/src/select_other_tests.rsindex 23b2e8cf02..69366eb256 100644--- a/crates/ui-egui/src/select_other_tests.rs+++ b/crates/ui-egui/src/select_other_tests.rs@@ -135,6 +135,44 @@ fn overlapping_bodies_list_both_and_the_hidden_one_can_be_picked() {assert_eq!(h.app.session.selection, [Sel::Body { name: "Inner".into() }]);}+#[test]+fn long_names_stay_inside_the_popup_and_remain_available_on_hover() {+ let mut h = Harness::new();+ h.app.ui.show_origin = false;+ h.call("ui.resize", json!({"width":1000,"height":700}));+ let name = "Long assembly component ".repeat(12);+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":name})).unwrap();+ h.call("ui.view", json!({"view":"top"}));+ h.call("ui.view", json!({"view":"fit"}));+ h.step(&json!({"hold": {"world": [5, 5, 10]}})).unwrap();+ let label = format!("Body · {name}");+ let row = labels(&h).iter().position(|r| r == &label).unwrap();+ let mut output = h.ctx.run_ui(egui::RawInput { screen_rect: Some(h.ctx.content_rect()), focused: true, ..Default::default() }, |ui| {+ h.app.logic(ui.ctx());+ h.app.ui(ui);+ });+ output.textures_delta.clear();+ let text = output+ .shapes+ .iter()+ .find_map(|s| match &s.shape {+ egui::Shape::Text(t) if t.galley.job.text == label => Some(t),+ _ => None,+ })+ .expect("the body label is painted");+ let popup = h.ctx.memory(|m| m.area_rect(egui::Id::new("sc_select_other"))).unwrap();+ let text_rect = egui::Rect::from_min_size(text.pos, text.galley.size());+ assert!(popup.contains_rect(text_rect), "{text_rect:?} spills outside {popup:?}");+ assert!(h.ctx.content_rect().contains_rect(popup));+ assert!(text.galley.elided, "long names end in an ellipsis");++ h.step(&json!({"move": {"handle": format!("select_other:{row}")}})).unwrap();+ h.frames(90);+ assert!(h.widget(&label).is_some(), "the tooltip exposes the full label");+ h.step(&json!({"click": {"handle": format!("select_other:{row}")}})).unwrap();+ assert_eq!(h.app.session.selection, [Sel::Body { name }], "the shortened label still selects the original body");+}+#[test]fn a_dialog_selection_input_takes_its_pick_from_the_list() {let mut h = Harness::new();