LibGUI: More work on client-side menus.

This commit is contained in:
Andreas Kling 2019-02-11 15:37:12 +01:00
parent c75ecaae32
commit 757429fb55
Notes: sideshowbarker 2024-07-19 15:47:02 +09:00
6 changed files with 55 additions and 3 deletions

View file

@ -13,6 +13,7 @@
#include <LibGUI/GApplication.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GMenuBar.h>
static void make_shell(int ptm_fd)
{
@ -72,5 +73,17 @@ int main(int argc, char** argv)
window->move_to(300, 300);
window->show();
auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("Terminal");
app_menu->add_item(1, "Quit");
menubar->add_menu(move(app_menu));
auto help_menu = make<GMenu>("?");
help_menu->add_item(2, "About");
menubar->add_menu(move(app_menu));
app.set_menubar(move(menubar));
return app.exec();
}

View file

@ -33,6 +33,10 @@ void GApplication::exit(int exit_code)
void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar)
{
if (m_menubar)
m_menubar->notify_removed_from_application(Badge<GApplication>());
m_menubar = move(menubar);
if (m_menubar)
m_menubar->notify_added_to_application(Badge<GApplication>());
}

View file

@ -1,6 +1,7 @@
#include <LibGUI/GMenu.h>
GMenu::GMenu()
GMenu::GMenu(const String& name)
: m_name(name)
{
}
@ -8,4 +9,12 @@ GMenu::~GMenu()
{
}
void GMenu::add_item(unsigned identifier, const String& text)
{
m_items.append({ identifier, text });
}
void GMenu::add_separator()
{
m_items.append(GMenuItem(GMenuItem::Separator));
}

View file

@ -5,9 +5,13 @@
class GMenu {
public:
GMenu();
explicit GMenu(const String& name);
~GMenu();
void add_item(unsigned identifier, const String& text);
void add_separator();
private:
String m_name;
Vector<GMenuItem> m_items;
};

View file

@ -7,3 +7,16 @@ GMenuBar::GMenuBar()
GMenuBar::~GMenuBar()
{
}
void GMenuBar::add_menu(OwnPtr<GMenu>&& menu)
{
m_menus.append(move(menu));
}
void GMenuBar::notify_added_to_application(Badge<GApplication>)
{
}
void GMenuBar::notify_removed_from_application(Badge<GApplication>)
{
}

View file

@ -1,13 +1,22 @@
#pragma once
#include <LibGUI/GMenu.h>
#include <AK/Badge.h>
#include <AK/OwnPtr.h>
#include <AK/Vector.h>
class GApplication;
class GMenuBar {
public:
GMenuBar();
~GMenuBar();
void add_menu(OwnPtr<GMenu>&&);
void notify_added_to_application(Badge<GApplication>);
void notify_removed_from_application(Badge<GApplication>);
private:
Vector<GMenu> m_menus;
Vector<OwnPtr<GMenu>> m_menus;
};