LibGUI: Add hook when a context menu is requested on a button

This commit is contained in:
FalseHonesty 2020-05-18 21:25:28 -04:00 committed by Andreas Kling
parent 040c75a3cc
commit 28f74df2e6
Notes: sideshowbarker 2024-07-19 06:15:12 +09:00
2 changed files with 10 additions and 0 deletions

View file

@ -101,6 +101,14 @@ void Button::click(unsigned modifiers)
m_action->activate(this);
}
void Button::context_menu_event(ContextMenuEvent& context_menu_event)
{
if (!is_enabled())
return;
if (on_context_menu_request)
on_context_menu_request(context_menu_event);
}
void Button::set_action(Action& action)
{
m_action = action.make_weak_ptr();

View file

@ -48,11 +48,13 @@ public:
Gfx::TextAlignment text_alignment() const { return m_text_alignment; }
Function<void(unsigned modifiers)> on_click;
Function<void(const ContextMenuEvent&)> on_context_menu_request;
void set_button_style(Gfx::ButtonStyle style) { m_button_style = style; }
Gfx::ButtonStyle button_style() const { return m_button_style; }
virtual void click(unsigned modifiers = 0) override;
virtual void context_menu_event(ContextMenuEvent&) override;
void set_action(Action&);