Skip to content

Commit

Permalink
PopupMenuHelper: Pass mouse down position through to popup menu callb…
Browse files Browse the repository at this point in the history
…ack (#447)

* PopupMenuHelper: Pass mouse down position through to popup menu callback

* Fix test compilation error
  • Loading branch information
jatinchowdhury18 authored Jul 29, 2023
1 parent 0c847d5 commit 3d6ea48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ PopupMenuHelper::PopupMenuHelper() : PopupMenuHelper (LongPressActionHelper::Par

PopupMenuHelper::PopupMenuHelper (const LongPressActionHelper::Parameters& params) : longPress (params)
{
longPress.longPressCallback = [this] (juce::Point<int>)
{ showPopupMenu(); };
longPress.longPressCallback = [this] (juce::Point<int> mouseDownPosition)
{ showPopupMenu (mouseDownPosition); };
}

PopupMenuHelper::~PopupMenuHelper()
Expand All @@ -29,7 +29,7 @@ void PopupMenuHelper::setAssociatedComponent (juce::Component* comp)
component->addMouseListener (this, false);
}

void PopupMenuHelper::showPopupMenu()
void PopupMenuHelper::showPopupMenu (juce::Point<int> position)
{
juce::PopupMenu menu;
juce::PopupMenu::Options options;
Expand All @@ -39,14 +39,14 @@ void PopupMenuHelper::showPopupMenu()

options = options.withTargetScreenArea (juce::Rectangle<int> {}.withPosition (juce::Desktop::getMousePosition()));

popupMenuCallback (menu, options);
popupMenuCallback (menu, options, position);
menu.showMenuAsync (options);
}

void PopupMenuHelper::mouseDown (const juce::MouseEvent& e)
{
if (e.mods.isPopupMenu())
showPopupMenu();
showPopupMenu (e.getMouseDownPosition());
}

} // namespace chowdsp
4 changes: 2 additions & 2 deletions modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class PopupMenuHelper : private juce::MouseListener
~PopupMenuHelper() override;

/** You can assign a lambda to this callback object to fill in the popup menu about to be shown */
std::function<void (juce::PopupMenu&, juce::PopupMenu::Options&)> popupMenuCallback = [] (juce::PopupMenu&, juce::PopupMenu::Options&) {}; // NOSONAR
std::function<void (juce::PopupMenu&, juce::PopupMenu::Options&, juce::Point<int>)> popupMenuCallback = [] (juce::PopupMenu&, juce::PopupMenu::Options&, juce::Point<int>) {}; // NOSONAR

/** Sets a component to listen for mouse actions on, or nullptr to not listen for mouse actions */
void setAssociatedComponent (juce::Component* comp);

/** Use this method to manually trigger the popup menu */
void showPopupMenu();
void showPopupMenu (juce::Point<int> position);

/** Returns true if long-press actions should trigger popup menus for any input source */
[[nodiscard]] bool isLongPressEnabled() const { return longPress.isLongPressActionEnabled(); }
Expand Down
2 changes: 1 addition & 1 deletion tests/gui_tests/chowdsp_gui_test/PopupMenuHelperTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void checkPopupMenu (bool expectedHit, Callback&& callback)

juce::Component comp;
chowdsp::PopupMenuHelper popupMenu;
popupMenu.popupMenuCallback = [&] (juce::PopupMenu&, juce::PopupMenu::Options&)
popupMenu.popupMenuCallback = [&] (juce::PopupMenu&, juce::PopupMenu::Options&, juce::Point<int>)
{ hasPopupMenuShown = true; };
popupMenu.setAssociatedComponent (&comp);

Expand Down

0 comments on commit 3d6ea48

Please sign in to comment.