Browse Source

PopupMenu: Add withMousePosition helper function to Options

v6.1.6
reuk 3 years ago
parent
commit
ab966fb499
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
4 changed files with 24 additions and 10 deletions
  1. +2
    -1
      examples/Plugins/DSPModulePluginDemo.h
  2. +2
    -7
      modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp
  3. +5
    -0
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp
  4. +15
    -2
      modules/juce_gui_basics/menus/juce_PopupMenu.h

+ 2
- 1
examples/Plugins/DSPModulePluginDemo.h View File

@@ -1713,7 +1713,8 @@ private:
if (e.mods.isRightButtonDown())
if (auto* c = editor.getHostContext())
if (auto menuInfo = c->getContextMenuForParameterIndex (&param))
menuInfo->getEquivalentPopupMenu().showMenuAsync ({});
menuInfo->getEquivalentPopupMenu().showMenuAsync (PopupMenu::Options{}.withTargetComponent (this)
.withMousePosition());
}
private:


+ 2
- 7
modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp View File

@@ -450,16 +450,11 @@ public:
if (e.mods.isRightButtonDown())
if (auto* context = editor.getHostContext())
if (auto menu = context->getContextMenuForParameterIndex (&parameter))
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;


+ 5
- 0
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -1927,6 +1927,11 @@ PopupMenu::Options PopupMenu::Options::withTargetScreenArea (Rectangle<int> area
return with (*this, &Options::targetArea, area);
}
PopupMenu::Options PopupMenu::Options::withMousePosition() const
{
return withTargetScreenArea (Rectangle<int>{}.withPosition (Desktop::getMousePosition()));
}
PopupMenu::Options PopupMenu::Options::withDeletionCheck (Component& comp) const
{
return with (with (*this, &Options::isWatchingForDeletion, true),


+ 15
- 2
modules/juce_gui_basics/menus/juce_PopupMenu.h View File

@@ -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<int>{}.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<int>{}.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<int> 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.


Loading…
Cancel
Save