fix(ui): left-align font name in Home ribbon (#2454)

Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
Zaxaerith
2026-10-26 18:45:52 +08:00
co-authored by Codex
parent f6b0cec67e
commit de8f36ee33
2 changed files with 26 additions and 1 deletions
+2 -1
View File
@@ -1294,7 +1294,8 @@ fn autosum_menu(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).