mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-12 22:22:55 +00:00
WindowServer: Give menu items an identifier field and add a simple callback.
Eventually these identifiers will be sent to the userspace client who created the menu. None of that is hooked up yet though.
This commit is contained in:
parent
78fc7a9ef2
commit
145aa27b8f
Notes:
sideshowbarker
2024-07-19 15:47:37 +09:00
Author: https://github.com/awesomekling
Commit: 145aa27b8f
5 changed files with 41 additions and 9 deletions
|
@ -107,7 +107,23 @@ void WSMenu::on_window_message(WSMessage& message)
|
||||||
return;
|
return;
|
||||||
m_hovered_item = item;
|
m_hovered_item = item;
|
||||||
redraw();
|
redraw();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.type() == WSMessage::MouseUp) {
|
||||||
|
if (!m_hovered_item)
|
||||||
|
return;
|
||||||
|
did_activate(*m_hovered_item);
|
||||||
|
m_hovered_item = nullptr;
|
||||||
|
redraw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSMenu::did_activate(WSMenuItem& item)
|
||||||
|
{
|
||||||
|
if (on_item_activation)
|
||||||
|
on_item_activation(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
WSMenuItem* WSMenu::item_at(const Point& position)
|
WSMenuItem* WSMenu::item_at(const Point& position)
|
||||||
|
|
|
@ -57,7 +57,11 @@ public:
|
||||||
WSMenuItem* item_at(const Point&);
|
WSMenuItem* item_at(const Point&);
|
||||||
void redraw();
|
void redraw();
|
||||||
|
|
||||||
|
Function<void(WSMenuItem&)> on_item_activation;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void did_activate(WSMenuItem&);
|
||||||
|
|
||||||
String m_name;
|
String m_name;
|
||||||
Rect m_rect_in_menubar;
|
Rect m_rect_in_menubar;
|
||||||
Rect m_text_rect_in_menubar;
|
Rect m_text_rect_in_menubar;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "WSMenuItem.h"
|
#include "WSMenuItem.h"
|
||||||
|
|
||||||
WSMenuItem::WSMenuItem(const String& text)
|
WSMenuItem::WSMenuItem(unsigned identifier, const String& text)
|
||||||
: m_type(Text)
|
: m_type(Text)
|
||||||
|
, m_identifier(identifier)
|
||||||
, m_text(text)
|
, m_text(text)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
|
#include <AK/Function.h>
|
||||||
#include <SharedGraphics/Rect.h>
|
#include <SharedGraphics/Rect.h>
|
||||||
|
|
||||||
class WSMenuItem {
|
class WSMenuItem {
|
||||||
|
@ -11,7 +12,7 @@ public:
|
||||||
Separator,
|
Separator,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit WSMenuItem(const String& text);
|
explicit WSMenuItem(unsigned identifier, const String& text);
|
||||||
explicit WSMenuItem(Type);
|
explicit WSMenuItem(Type);
|
||||||
~WSMenuItem();
|
~WSMenuItem();
|
||||||
|
|
||||||
|
@ -23,9 +24,12 @@ public:
|
||||||
void set_rect(const Rect& rect) { m_rect = rect; }
|
void set_rect(const Rect& rect) { m_rect = rect; }
|
||||||
Rect rect() const { return m_rect; }
|
Rect rect() const { return m_rect; }
|
||||||
|
|
||||||
|
unsigned identifier() const { return m_identifier; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type m_type { None };
|
Type m_type { None };
|
||||||
bool m_enabled { true };
|
bool m_enabled { true };
|
||||||
|
unsigned m_identifier { 0 };
|
||||||
String m_text;
|
String m_text;
|
||||||
Rect m_rect;
|
Rect m_rect;
|
||||||
};
|
};
|
||||||
|
|
|
@ -185,19 +185,26 @@ WSWindowManager::WSWindowManager()
|
||||||
|
|
||||||
{
|
{
|
||||||
auto menu = make<WSMenu>("Serenity");
|
auto menu = make<WSMenu>("Serenity");
|
||||||
menu->add_item(make<WSMenuItem>("Launch Terminal"));
|
menu->add_item(make<WSMenuItem>(0, "Launch Terminal"));
|
||||||
menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
||||||
menu->add_item(make<WSMenuItem>("Hello again"));
|
menu->add_item(make<WSMenuItem>(1, "Hello again"));
|
||||||
menu->add_item(make<WSMenuItem>("To all my friends"));
|
menu->add_item(make<WSMenuItem>(2, "To all my friends"));
|
||||||
menu->add_item(make<WSMenuItem>("Together we can play some rock&roll"));
|
menu->add_item(make<WSMenuItem>(3, "Together we can play some rock&roll"));
|
||||||
menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
||||||
menu->add_item(make<WSMenuItem>("About..."));
|
menu->add_item(make<WSMenuItem>(4, "About..."));
|
||||||
|
menu->on_item_activation = [] (WSMenuItem& item) {
|
||||||
|
kprintf("WSMenu 1 item activated: '%s'\n", item.text().characters());
|
||||||
|
};
|
||||||
menubar->add_menu(move(menu));
|
menubar->add_menu(move(menu));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto menu = make<WSMenu>("Application");
|
auto menu = make<WSMenu>("Application");
|
||||||
menu->add_item(make<WSMenuItem>("Bar!"));
|
menu->add_item(make<WSMenuItem>(5, "Foo."));
|
||||||
menu->add_item(make<WSMenuItem>("Foo!"));
|
menu->add_item(make<WSMenuItem>(6, "Bar?"));
|
||||||
|
menu->add_item(make<WSMenuItem>(7, "Baz!"));
|
||||||
|
menu->on_item_activation = [] (WSMenuItem& item) {
|
||||||
|
kprintf("WSMenu 2 item activated: '%s'\n", item.text().characters());
|
||||||
|
};
|
||||||
menubar->add_menu(move(menu));
|
menubar->add_menu(move(menu));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue