Merge pull request #2636 from Zaxaerith/fix/2454-left-align-font-name

fix(ui): left-align the font name box (#2454)
This commit is contained in:
FredApps authored and GitHub committed 2026-11-26 13:37:06 +01:00
commit fe30de8f7f
2 files changed
+26 -1

No files matched your search

+2 -1
View File
@@ -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();
+24
View File
@@ -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).