diff --git a/crates/ui-egui/src/ribbon/home.rs b/crates/ui-egui/src/ribbon/home.rs index 7dd55f7067..3bf7bb3576 100644 --- a/crates/ui-egui/src/ribbon/home.rs +++ b/crates/ui-egui/src/ribbon/home.rs @@ -575,7 +575,8 @@ pub(super) fn home(app: &mut SheetApp, ui: &mut Ui) { fn font_combo(app: &mut SheetApp, ui: &mut Ui, st: &Style) { let name = st.font.name.clone(); - let resp = ui.add_sized([150.0, 24.0], egui::Button::new(egui::RichText::new(&name).font(theme::ui_font(12.5)))); + // The trailing grow atom left-aligns the existing label inside the button. + let resp = ui.add_sized([150.0, 24.0], egui::Button::new(egui::RichText::new(&name).font(theme::ui_font(12.5))).right_text(())); control_keytip(app, ui, &resp, "home.fontName"); let forced = invoke(app, "home.fontName"); let items: Vec<(&str, String)> = FONTS.iter().map(|f| (*f, f.to_string())).collect(); diff --git a/crates/ui-egui/tests/keytips.rs b/crates/ui-egui/tests/keytips.rs index cf765e0317..6835c0d8dc 100644 --- a/crates/ui-egui/tests/keytips.rs +++ b/crates/ui-egui/tests/keytips.rs @@ -522,6 +522,30 @@ fn pending_sequences_go_live_when_the_command_lands() { assert_eq!(h.state().keytips.prefix(), None); } +#[test] +fn font_name_box_left_aligns_short_and_long_names() -> Result<(), String> { + for name in ["Arial", "Calibri", "Times New Roman"] { + let mut session = blank(); + session.execute("home.fontName", json!({"name": name})).map_err(|e| e.to_string())?; + let h = harness(session); + // Querying the original name also checks that the button keeps its accessible label. + let rect = h.get_by_role_and_label(egui::accesskit::Role::Button, name).rect(); + assert!((rect.width() - 150.0).abs() < 0.1 && (rect.height() - 24.0).abs() < 0.1, "{name}: {rect:?}"); + let text_x = h + .output() + .shapes + .iter() + .find_map(|shape| match &shape.shape { + egui::Shape::Text(text) if text.galley.text() == name && rect.contains(text.pos) => Some(text.pos.x), + _ => None, + }) + .ok_or("font name was not painted inside its button")?; + let inset = text_x - rect.left(); + assert!((0.0..=10.0).contains(&inset), "{name}: expected a small left inset, got {inset}"); + } + Ok(()) +} + #[test] fn control_keytips_open_dropdowns_and_run_handlers() { // HFF routes to the font control: its dropdown opens (popup items queryable).