WindowServer: Add a bunch of horizontal padding to menu items.

All right, this looks a lot nicer. :^)
This commit is contained in:
Andreas Kling 2019-02-11 14:14:49 +01:00
parent 3c863e0ffa
commit 8d0bfa62fd
Notes: sideshowbarker 2024-07-19 15:47:11 +09:00
2 changed files with 11 additions and 8 deletions

View file

@ -34,14 +34,14 @@ int WSMenu::width() const
longest = max(longest, font().width(item->text()));
}
return max(longest, rect_in_menubar().width()) + padding() * 2;
return max(longest, rect_in_menubar().width()) + horizontal_padding();
}
int WSMenu::height() const
{
if (m_items.is_empty())
return 0;
return (m_items.last()->rect().bottom() - 1) + padding();
return (m_items.last()->rect().bottom() - 1) + vertical_padding();
}
void WSMenu::redraw()
@ -54,14 +54,14 @@ void WSMenu::redraw()
WSWindow& WSMenu::ensure_menu_window()
{
if (!m_menu_window) {
Point next_item_location(padding() / 2, padding() / 2);
Point next_item_location(1, vertical_padding() / 2);
for (auto& item : m_items) {
int height = 0;
if (item->type() == WSMenuItem::Text)
height = item_height();
else if (item->type() == WSMenuItem::Separator)
height = 7;
item->set_rect({ next_item_location, { width() - padding(), height } });
item->set_rect({ next_item_location, { width() - 2, height } });
next_item_location.move_by(0, height);
}
@ -90,10 +90,10 @@ void WSMenu::draw()
painter.fill_rect(item->rect(), Color(0, 0, 104));
text_color = Color::White;
}
painter.draw_text(item->rect(), item->text(), TextAlignment::CenterLeft, text_color);
painter.draw_text(item->rect().translated(left_padding(), 0), item->text(), TextAlignment::CenterLeft, text_color);
} else if (item->type() == WSMenuItem::Separator) {
Point p1(padding(), item->rect().center().y());
Point p2(width() - padding(), item->rect().center().y());
Point p1(1, item->rect().center().y());
Point p2(width() - 2, item->rect().center().y());
painter.draw_line(p1, p2, Color::MidGray);
}
}

View file

@ -48,7 +48,10 @@ public:
int height() const;
int item_height() const { return 16; }
int padding() const { return 4; }
int vertical_padding() const { return 4; }
int horizontal_padding() const { return left_padding() + right_padding(); }
int left_padding() const { return 14; }
int right_padding() const { return 14; }
void on_window_message(WSMessage&);
void draw();