1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:57:35 +00:00

LibGUI, WindowServer: Greatly simplify menubar logic

Currently, any number of menubars can be plugged in and out of a window.
This is unnecessary complexity, since we only need one menubar on a
window. This commit removes most of the logic for dynamically attaching
and detaching menubars and makes one menubar always available. The
menubar is only considered existent if it has at least a single menu in
it (in other words, an empty menubar will not be shown).

This commit additionally fixes a bug wherein menus added after a menubar
has been attached would not have their rects properly setup, and would
therefore appear glitched out on the top left corner of the menubar.
This commit is contained in:
sin-ack 2021-07-29 10:14:12 +00:00 committed by Andreas Kling
parent 95ab61e3db
commit 611370e7dc
19 changed files with 150 additions and 255 deletions

View file

@ -1,15 +1,18 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/Badge.h>
#include <AK/IterationDecision.h>
#include <AK/NonnullRefPtrVector.h>
#include <LibCore/Object.h>
#include <LibGUI/Forward.h>
#include <LibGUI/Menu.h>
namespace GUI {
@ -17,22 +20,27 @@ class Menubar : public Core::Object {
C_OBJECT(Menubar);
public:
~Menubar();
~Menubar() { }
Menu& add_menu(String name);
Menu& add_menu(Badge<Window>, String name)
{
auto& menu = add<Menu>(move(name));
m_menus.append(menu);
return menu;
}
void notify_added_to_window(Badge<Window>);
void notify_removed_from_window(Badge<Window>);
int menubar_id() const { return m_menubar_id; }
void for_each_menu(Function<IterationDecision(Menu&)> callback)
{
for (auto& menu : m_menus) {
if (callback(menu) == IterationDecision::Break) {
return;
}
}
}
private:
Menubar();
Menubar() { }
int realize_menubar();
void unrealize_menubar();
int m_menubar_id { -1 };
NonnullRefPtrVector<Menu> m_menus;
};