mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:57:43 +00:00
LibGUI: Refactor context menus to be event-driven instead of declarative.
The declarative approach had way too many limitations. This patch adds a context menu event that can be hooked to prepare a custom context menu on demand just-in-time. :^)
This commit is contained in:
parent
e74b5bc054
commit
a747a10eab
5 changed files with 37 additions and 27 deletions
|
@ -35,16 +35,20 @@ VBForm::VBForm(const String& name, GWidget* parent)
|
|||
groupbox1->set_rect({ 300, 150, 161, 51 });
|
||||
m_widgets.append(move(groupbox1));
|
||||
|
||||
auto context_menu = make<GMenu>("Context menu");
|
||||
context_menu->add_action(GAction::create("Move to front", [this] (auto&) {
|
||||
m_context_menu = make<GMenu>("Context menu");
|
||||
m_context_menu->add_action(GAction::create("Move to front", [this] (auto&) {
|
||||
if (m_selected_widget)
|
||||
m_selected_widget->gwidget()->move_to_front();
|
||||
}));
|
||||
context_menu->add_action(GAction::create("Move to back", [this] (auto&) {
|
||||
m_context_menu->add_action(GAction::create("Move to back", [this] (auto&) {
|
||||
if (m_selected_widget)
|
||||
m_selected_widget->gwidget()->move_to_back();
|
||||
}));
|
||||
set_context_menu(move(context_menu), GWidget::ContextMenuMode::PassthroughMouseEvent);
|
||||
}
|
||||
|
||||
void VBForm::context_menu_event(GContextMenuEvent& event)
|
||||
{
|
||||
m_context_menu->popup(event.screen_position());
|
||||
}
|
||||
|
||||
void VBForm::insert_widget(VBWidgetType type)
|
||||
|
|
|
@ -31,6 +31,7 @@ protected:
|
|||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual void mousemove_event(GMouseEvent&) override;
|
||||
virtual void mouseup_event(GMouseEvent&) override;
|
||||
virtual void context_menu_event(GContextMenuEvent&) override;
|
||||
virtual void keydown_event(GKeyEvent&) override;
|
||||
|
||||
private:
|
||||
|
@ -47,4 +48,5 @@ private:
|
|||
Rect m_transform_widget_origin_rect;
|
||||
Point m_next_insertion_position;
|
||||
Direction m_resize_direction { Direction::None };
|
||||
OwnPtr<GMenu> m_context_menu;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue