WindowServer: Add Menu::is_open() to improve readability

"menu.is_open()" instead of "MenuManager::the().is_open(menu)"
This commit is contained in:
Andreas Kling 2021-05-17 22:01:05 +02:00
parent dfb2178519
commit 5d0c3bd564
Notes: sideshowbarker 2024-07-18 17:54:07 +09:00
4 changed files with 11 additions and 3 deletions

View File

@ -658,4 +658,9 @@ void Menu::set_hovered_index(int index, bool make_input)
}
}
bool Menu::is_open() const
{
return MenuManager::the().is_open(*this);
}
}

View File

@ -34,6 +34,8 @@ public:
const ClientConnection* client() const { return m_client; }
int menu_id() const { return m_menu_id; }
bool is_open() const;
u32 alt_shortcut_character() const { return m_alt_shortcut_character; }
bool is_empty() const { return m_items.is_empty(); }

View File

@ -291,7 +291,7 @@ void MenuManager::set_hovered_menu(Menu* menu)
void MenuManager::open_menu(Menu& menu, bool as_current_menu)
{
if (is_open(menu)) {
if (menu.is_open()) {
if (as_current_menu || current_menu() != &menu) {
// This menu is already open. If requested, or if the current
// window doesn't match this one, then set it to this

View File

@ -293,9 +293,10 @@ void WindowFrame::paint_menubar(Gfx::Painter& painter)
m_window.menubar()->for_each_menu([&](Menu& menu) {
auto text_rect = menu.rect_in_window_menubar();
Color text_color = palette.window_text();
if (MenuManager::the().is_open(menu))
auto is_open = menu.is_open();
if (is_open)
text_rect.translate_by(1, 1);
bool paint_as_pressed = MenuManager::the().is_open(menu);
bool paint_as_pressed = is_open;
bool paint_as_hovered = !paint_as_pressed && &menu == MenuManager::the().hovered_menu();
if (paint_as_pressed || paint_as_hovered) {
Gfx::StylePainter::paint_button(painter, menu.rect_in_window_menubar(), palette, Gfx::ButtonStyle::Coolbar, paint_as_pressed, paint_as_hovered);