WindowServer: Make WSMenu wide enough that shortcuts are always rightmost.
This commit is contained in:
parent
0ae475ff5b
commit
c8aae534d7
Notes:
sideshowbarker
2024-07-19 14:32:28 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c8aae534d7f
1 changed files with 17 additions and 10 deletions
|
@ -46,20 +46,27 @@ static const int s_checked_bitmap_padding = 6;
|
|||
|
||||
int WSMenu::width() const
|
||||
{
|
||||
int longest = 0;
|
||||
int widest_text = 0;
|
||||
int widest_shortcut = 0;
|
||||
for (auto& item : m_items) {
|
||||
if (item->type() == WSMenuItem::Text) {
|
||||
int item_width = font().width(item->text());
|
||||
if (!item->shortcut_text().is_empty())
|
||||
item_width += padding_between_text_and_shortcut() + font().width(item->shortcut_text());
|
||||
if (item->is_checkable())
|
||||
item_width += s_checked_bitmap_width + s_checked_bitmap_padding;
|
||||
|
||||
longest = max(longest, item_width);
|
||||
if (item->type() != WSMenuItem::Text)
|
||||
continue;
|
||||
int text_width = font().width(item->text());
|
||||
if (!item->shortcut_text().is_empty()) {
|
||||
int shortcut_width = font().width(item->shortcut_text());
|
||||
widest_shortcut = max(shortcut_width, widest_shortcut);
|
||||
}
|
||||
if (item->is_checkable())
|
||||
text_width += s_checked_bitmap_width + s_checked_bitmap_padding;
|
||||
|
||||
widest_text = max(widest_text, text_width);
|
||||
}
|
||||
|
||||
return max(longest, rect_in_menubar().width()) + horizontal_padding() + frame_thickness() * 2;
|
||||
int widest_item = widest_text;
|
||||
if (widest_shortcut)
|
||||
widest_item += padding_between_text_and_shortcut() + widest_shortcut;
|
||||
|
||||
return max(widest_item, rect_in_menubar().width()) + horizontal_padding() + frame_thickness() * 2;
|
||||
}
|
||||
|
||||
int WSMenu::height() const
|
||||
|
|
Loading…
Add table
Reference in a new issue