浏览代码

WindowServer: Strip Alt-shortcut marker ('&') when measuring menu texts

We were including these markers when computing the sizes of menus,
causing them to get a little too much padding.
Andreas Kling 4 年之前
父节点
当前提交
767bd8cc88
共有 2 个文件被更改,包括 2 次插入2 次删除
  1. 1 1
      Userland/Services/WindowServer/Menu.cpp
  2. 1 1
      Userland/Services/WindowServer/Window.cpp

+ 1 - 1
Userland/Services/WindowServer/Menu.cpp

@@ -115,7 +115,7 @@ int Menu::content_width() const
         if (item.type() != MenuItem::Text)
         if (item.type() != MenuItem::Text)
             continue;
             continue;
         auto& use_font = item.is_default() ? Gfx::FontDatabase::default_bold_font() : font();
         auto& use_font = item.is_default() ? Gfx::FontDatabase::default_bold_font() : font();
-        int text_width = use_font.width(item.text());
+        int text_width = use_font.width(Gfx::parse_ampersand_string(item.text()));
         if (!item.shortcut_text().is_empty()) {
         if (!item.shortcut_text().is_empty()) {
             int shortcut_width = use_font.width(item.shortcut_text());
             int shortcut_width = use_font.width(item.shortcut_text());
             widest_shortcut = max(shortcut_width, widest_shortcut);
             widest_shortcut = max(shortcut_width, widest_shortcut);

+ 1 - 1
Userland/Services/WindowServer/Window.cpp

@@ -990,7 +990,7 @@ void Window::set_menubar(MenuBar* menubar)
         Gfx::IntPoint next_menu_location { 0, 0 };
         Gfx::IntPoint next_menu_location { 0, 0 };
         auto menubar_rect = Gfx::WindowTheme::current().menubar_rect(Gfx::WindowTheme::WindowType::Normal, rect(), wm.palette(), 1);
         auto menubar_rect = Gfx::WindowTheme::current().menubar_rect(Gfx::WindowTheme::WindowType::Normal, rect(), wm.palette(), 1);
         m_menubar->for_each_menu([&](Menu& menu) {
         m_menubar->for_each_menu([&](Menu& menu) {
-            int text_width = wm.font().width(menu.name());
+            int text_width = wm.font().width(Gfx::parse_ampersand_string(menu.name()));
             menu.set_rect_in_window_menubar({ next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() });
             menu.set_rect_in_window_menubar({ next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() });
             next_menu_location.move_by(menu.rect_in_window_menubar().width(), 0);
             next_menu_location.move_by(menu.rect_in_window_menubar().width(), 0);
             return IterationDecision::Continue;
             return IterationDecision::Continue;