From 0f2ad19bdb656908d1becdcacb978054d95501b4 Mon Sep 17 00:00:00 2001 From: semmelrinde <124386289+semmelrinde@users.noreply.github.com> Date: Thu, 29 Oct 2026 09:20:05 +0000 Subject: [PATCH] Navigation menus: a label too long for its row ends in an ellipsis (#8700) (#8745) The Display menu's "Perspective while orbiting, ortho on faces" ran past the menu's edge: a menu row painted its label at full length. It is now cut before the row's detail and check, and shown whole on hover, as a long name in a list is. Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/navigation_bar_tests.rs | 28 ++++++++++++++++++++ crates/ui-egui/src/ui_kit/navigation_menu.rs | 24 ++++++++++------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/navigation_bar_tests.rs b/crates/ui-egui/src/navigation_bar_tests.rs index 15743b224..b49c3a55c 100644 --- a/crates/ui-egui/src/navigation_bar_tests.rs +++ b/crates/ui-egui/src/navigation_bar_tests.rs @@ -513,6 +513,34 @@ fn navigation_board_popup_width_includes_its_border_and_padding() { } } +/// A label longer than its menu row (the Display menu's "Perspective while orbiting, ortho on +/// faces", #8700) is cut with an ellipsis before the row's check, not drawn past the menu's edge; +/// a short one is drawn whole. +#[test] +fn a_long_menu_row_label_ends_in_an_ellipsis_inside_its_row() { + use crate::ui_kit::*; + let ctx = crate::fonts::test_context(); + for (label, selected, cut) in [ + ("Perspective while orbiting, ortho on faces", false, true), + ("Perspective while orbiting, ortho on faces", true, true), + ("Show tool at cursor", true, false), + ] { + let mut row = Rect::NOTHING; + let output = crate::test_support::frame(&ctx, egui::RawInput::default(), |ui| { + navigation_menu(ui, NAV_POPUP_WIDTH, |ui| { + let mut item = NavigationMenuRow::new("row", label, "select"); + item.selected = selected; + row = item.show(ui).rect; + }); + }); + let text = crate::test_support::text_shapes(&output).find(|t| t.galley.text() == label).unwrap_or_else(|| panic!("{label} is drawn")); + assert_eq!(text.galley.elided, cut, "{label}"); + let end = row.right() - NAV_MENU_INSET - if selected { crate::theme::Tokens::get().space_14 } else { 0.0 }; + let drawn = text.pos.x + text.galley.size().x; + assert!(drawn <= end, "{label}: ends at {drawn}, past {end}"); + } +} + #[test] fn navigation_board_position_aliases_migrate_and_editor_alignment_follows_position() { use crate::navigation_bar_view::editor_layout; diff --git a/crates/ui-egui/src/ui_kit/navigation_menu.rs b/crates/ui-egui/src/ui_kit/navigation_menu.rs index bd72a2775..e4bfc322c 100644 --- a/crates/ui-egui/src/ui_kit/navigation_menu.rs +++ b/crates/ui-egui/src/ui_kit/navigation_menu.rs @@ -59,22 +59,26 @@ impl<'a> NavigationMenuRow<'a> { icons::paint_ink(ui.painter(), icon, self.icon, if self.selected { ink } else { t.form_dim }); } let font = if self.selected { crate::fonts::semibold(NAV_TEXT) } else { FontId::proportional(NAV_TEXT) }; - ui.painter().text( - pos2(rect.left() + NAV_MENU_INSET + NAV_MENU_ICON + NAV_ROW_GAP, rect.center().y), - Align2::LEFT_CENTER, - self.label, - font, - ink, - ); + // The label ends before the detail and the check or chevron: one that doesn't fit is cut + // with an ellipsis and shown whole on hover, as a long name in a list is (#8700). + let mut end = rect.right() - NAV_MENU_INSET - if self.selected || self.submenu { t.space_14 + t.space_4 } else { 0.0 }; if let Some(detail) = self.detail { - ui.painter().text( - pos2(rect.right() - NAV_MENU_INSET - if self.submenu { NAV_CHEVRON + t.space_4 } else { 0.0 }, rect.center().y), + let at = rect.right() - NAV_MENU_INSET - if self.submenu { NAV_CHEVRON + t.space_4 } else { 0.0 }; + let detail = ui.painter().text( + pos2(at, rect.center().y), Align2::RIGHT_CENTER, detail, FontId::proportional(if self.enabled { t.font_body } else { t.font_small }), if self.enabled { t.form_dim } else { t.nav_dim }, ); + end = end.min(detail.left() - t.space_8); } + let left = rect.left() + NAV_MENU_INSET + NAV_MENU_ICON + NAV_ROW_GAP; + let mut job = egui::text::LayoutJob::simple_singleline(self.label.to_owned(), font, ink); + job.wrap = egui::text::TextWrapping::truncate_at_width((end - left).max(0.0)); + let galley = ui.painter().layout_job(job); + let cut = galley.elided; + ui.painter().galley(pos2(left, rect.center().y - galley.size().y / 2.0), galley, ink); let tail = Rect::from_center_size(pos2(rect.right() - NAV_MENU_INSET - t.space_14 / 2.0, rect.center().y), vec2(t.space_14, t.space_14)); if self.selected { super::checks::paint_check_glyph(ui.painter(), tail, false, t.form_primary); @@ -84,7 +88,7 @@ impl<'a> NavigationMenuRow<'a> { icons::paint_ink(ui.painter(), arrow, "chevron", t.form_dim); } response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, self.enabled && ui.is_enabled(), self.selected, self.label)); - response + if cut { response.on_hover_text(self.label) } else { response } } }