diff --git a/examples/Plugins/DSPModulePluginDemo.h b/examples/Plugins/DSPModulePluginDemo.h index 06e9738b6c..a5c5479b3a 100644 --- a/examples/Plugins/DSPModulePluginDemo.h +++ b/examples/Plugins/DSPModulePluginDemo.h @@ -1713,7 +1713,8 @@ private: if (e.mods.isRightButtonDown()) if (auto* c = editor.getHostContext()) if (auto menuInfo = c->getContextMenuForParameterIndex (¶m)) - menuInfo->getEquivalentPopupMenu().showMenuAsync ({}); + menuInfo->getEquivalentPopupMenu().showMenuAsync (PopupMenu::Options{}.withTargetComponent (this) + .withMousePosition()); } private: diff --git a/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp b/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp index 3f5bf87aeb..e380d0c623 100644 --- a/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp +++ b/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp @@ -450,16 +450,11 @@ public: if (e.mods.isRightButtonDown()) if (auto* context = editor.getHostContext()) if (auto menu = context->getContextMenuForParameterIndex (¶meter)) - menu->getEquivalentPopupMenu().showMenuAsync (getMenuOptions()); + menu->getEquivalentPopupMenu().showMenuAsync (PopupMenu::Options().withTargetComponent (this) + .withMousePosition()); } private: - PopupMenu::Options getMenuOptions() - { - return PopupMenu::Options().withTargetComponent (this) - .withTargetScreenArea ({ Desktop::getMousePosition(), Desktop::getMousePosition() }); - } - AudioProcessorEditor& editor; AudioProcessorParameter& parameter; Label parameterName, parameterLabel; diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index a059b57562..4efaf0eb24 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -1927,6 +1927,11 @@ PopupMenu::Options PopupMenu::Options::withTargetScreenArea (Rectangle area return with (*this, &Options::targetArea, area); } +PopupMenu::Options PopupMenu::Options::withMousePosition() const +{ + return withTargetScreenArea (Rectangle{}.withPosition (Desktop::getMousePosition())); +} + PopupMenu::Options PopupMenu::Options::withDeletionCheck (Component& comp) const { return with (with (*this, &Options::isWatchingForDeletion, true), diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.h b/modules/juce_gui_basics/menus/juce_PopupMenu.h index ff1b0a4674..5781531957 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.h +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.h @@ -480,15 +480,28 @@ public: /** Sets the region of the screen next to which the menu should be displayed. - To display the menu next to the mouse cursor, pass - Rectangle{}.withPosition (Desktop::getMousePosition()). + To display the menu next to the mouse cursor use withMousePosition(), + which is equivalent to passing the following to this function: + @code + Rectangle{}.withPosition (Desktop::getMousePosition()) + @endcode withTargetComponent() will also set the target screen area. If you need a target component and a target screen area, make sure to call withTargetScreenArea() after withTargetComponent(). + + @see withMousePosition */ Options withTargetScreenArea (Rectangle targetArea) const; + /** Sets the target screen area to match the current mouse position. + + Make sure to call this after withTargetComponent(). + + @see withTargetScreenArea + */ + Options withMousePosition() const; + /** If the passed component has been deleted when the popup menu exits, the selected item's action will not be called.