mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibGUI: More work on client-side menus.
This commit is contained in:
parent
c75ecaae32
commit
757429fb55
Notes:
sideshowbarker
2024-07-19 15:47:02 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/757429fb558
6 changed files with 55 additions and 3 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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>());
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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>)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue