mirror of
https://github.com/RGBCube/serenity
synced 2025-07-16 21:07:35 +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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue