From 3d6ea48cd777f77c6716d5049ed4087e29ec220c Mon Sep 17 00:00:00 2001 From: jatinchowdhury18 Date: Sat, 29 Jul 2023 15:35:37 -0700 Subject: [PATCH] PopupMenuHelper: Pass mouse down position through to popup menu callback (#447) * PopupMenuHelper: Pass mouse down position through to popup menu callback * Fix test compilation error --- .../chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.cpp | 10 +++++----- .../gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.h | 4 ++-- .../gui_tests/chowdsp_gui_test/PopupMenuHelperTest.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.cpp b/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.cpp index 80e630eed..e7ae006f5 100644 --- a/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.cpp +++ b/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.cpp @@ -8,8 +8,8 @@ PopupMenuHelper::PopupMenuHelper() : PopupMenuHelper (LongPressActionHelper::Par PopupMenuHelper::PopupMenuHelper (const LongPressActionHelper::Parameters& params) : longPress (params) { - longPress.longPressCallback = [this] (juce::Point) - { showPopupMenu(); }; + longPress.longPressCallback = [this] (juce::Point mouseDownPosition) + { showPopupMenu (mouseDownPosition); }; } PopupMenuHelper::~PopupMenuHelper() @@ -29,7 +29,7 @@ void PopupMenuHelper::setAssociatedComponent (juce::Component* comp) component->addMouseListener (this, false); } -void PopupMenuHelper::showPopupMenu() +void PopupMenuHelper::showPopupMenu (juce::Point position) { juce::PopupMenu menu; juce::PopupMenu::Options options; @@ -39,14 +39,14 @@ void PopupMenuHelper::showPopupMenu() options = options.withTargetScreenArea (juce::Rectangle {}.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 diff --git a/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.h b/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.h index 338f30644..5d57b185a 100644 --- a/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.h +++ b/modules/gui/chowdsp_gui/Helpers/chowdsp_PopupMenuHelper.h @@ -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 popupMenuCallback = [] (juce::PopupMenu&, juce::PopupMenu::Options&) {}; // NOSONAR + std::function)> popupMenuCallback = [] (juce::PopupMenu&, juce::PopupMenu::Options&, juce::Point) {}; // 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 position); /** Returns true if long-press actions should trigger popup menus for any input source */ [[nodiscard]] bool isLongPressEnabled() const { return longPress.isLongPressActionEnabled(); } diff --git a/tests/gui_tests/chowdsp_gui_test/PopupMenuHelperTest.cpp b/tests/gui_tests/chowdsp_gui_test/PopupMenuHelperTest.cpp index 55927dd69..095650108 100644 --- a/tests/gui_tests/chowdsp_gui_test/PopupMenuHelperTest.cpp +++ b/tests/gui_tests/chowdsp_gui_test/PopupMenuHelperTest.cpp @@ -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) { hasPopupMenuShown = true; }; popupMenu.setAssociatedComponent (&comp);