mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 03:37:35 +00:00
WindowServer: Make WSMenu wide enough that shortcuts are always rightmost.
This commit is contained in:
parent
0ae475ff5b
commit
c8aae534d7
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 WSMenu::width() const
|
||||||
{
|
{
|
||||||
int longest = 0;
|
int widest_text = 0;
|
||||||
|
int widest_shortcut = 0;
|
||||||
for (auto& item : m_items) {
|
for (auto& item : m_items) {
|
||||||
if (item->type() == WSMenuItem::Text) {
|
if (item->type() != WSMenuItem::Text)
|
||||||
int item_width = font().width(item->text());
|
continue;
|
||||||
if (!item->shortcut_text().is_empty())
|
int text_width = font().width(item->text());
|
||||||
item_width += padding_between_text_and_shortcut() + font().width(item->shortcut_text());
|
if (!item->shortcut_text().is_empty()) {
|
||||||
if (item->is_checkable())
|
int shortcut_width = font().width(item->shortcut_text());
|
||||||
item_width += s_checked_bitmap_width + s_checked_bitmap_padding;
|
widest_shortcut = max(shortcut_width, widest_shortcut);
|
||||||
|
|
||||||
longest = max(longest, item_width);
|
|
||||||
}
|
}
|
||||||
|
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
|
int WSMenu::height() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue