mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:18:12 +00:00
WindowServer+LibGfx: Show menus in windows! :^)
This patch begins the transition away from the global menu towards per-window menus instead. The global menu looks neat, but has always felt clunky, and there are a number of usability problems with it, especially in programs with multiple windows. You can now call GUI::Window::set_menubar() to add a menubar to your window. It will be specific to that one window only.
This commit is contained in:
parent
1daaa4f38d
commit
e76771bfad
21 changed files with 335 additions and 44 deletions
|
@ -942,4 +942,36 @@ bool Window::hit_test(const Gfx::IntPoint& point, bool include_frame) const
|
|||
return color.alpha() >= threshold;
|
||||
}
|
||||
|
||||
void Window::set_menubar(MenuBar* menubar)
|
||||
{
|
||||
if (m_menubar == menubar)
|
||||
return;
|
||||
m_menubar = menubar;
|
||||
if (m_menubar) {
|
||||
auto& wm = WindowManager::the();
|
||||
Gfx::IntPoint next_menu_location { MenuManager::menubar_menu_margin() / 2, 0 };
|
||||
auto menubar_rect = Gfx::WindowTheme::current().menu_bar_rect(Gfx::WindowTheme::WindowType::Normal, rect(), wm.palette(), 1);
|
||||
m_menubar->for_each_menu([&](Menu& menu) {
|
||||
int text_width = wm.font().width(menu.name());
|
||||
menu.set_rect_in_window_menubar({ next_menu_location.x() - MenuManager::menubar_menu_margin() / 2, 0, text_width + MenuManager::menubar_menu_margin(), menubar_rect.height() });
|
||||
|
||||
Gfx::IntRect text_rect { next_menu_location.translated(0, 1), { text_width, menubar_rect.height() - 3 } };
|
||||
|
||||
menu.set_text_rect_in_window_menubar(text_rect);
|
||||
next_menu_location.move_by(menu.rect_in_window_menubar().width(), 0);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
Compositor::the().invalidate_occlusions();
|
||||
frame().invalidate();
|
||||
}
|
||||
|
||||
void Window::invalidate_menubar()
|
||||
{
|
||||
if (!menubar())
|
||||
return;
|
||||
// FIXME: This invalidates way more than the menubar!
|
||||
frame().invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue