Browse Source

PopupMenu: Fix issue where PopupMenu would sometimes use the default rather than the parent look and feel

Previously, for the following snippet, the menu's LnF was incorrectly
being forced to the default LnF. The correct behaviour is to display the
menu using LnF v4. The menu doesn't have an explicit LnF set, so it
should use the LnF of its parent component.

    LookAndFeel::setDefaultLookAndFeel (&lookAndFeel_V1);
    setLookAndFeel (&lookAndFeel_V4);
    PopupMenu().showMenuAsync (PopupMenu::Options{}.withParentComponent (this));
v7.0.9
reuk 2 years ago
parent
commit
cf297c75c6
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 9 additions and 6 deletions
  1. +9
    -6
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp

+ 9
- 6
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -333,7 +333,7 @@ struct MenuWindow : public Component
float parentScaleFactor = 1.0f)
: Component ("menu"),
parent (parentWindow),
options (opts.withParentComponent (findLookAndFeel (menu, parentWindow)->getParentComponentForMenuOptions (opts))),
options (opts.withParentComponent (findNonNullLookAndFeel (menu, parentWindow).getParentComponentForMenuOptions (opts))),
managerOfChosenCommand (manager),
componentAttachedTo (options.getTargetComponent()),
dismissOnMouseUp (shouldDismissOnMouseUp),
@@ -1296,13 +1296,16 @@ struct MenuWindow : public Component
LookAndFeel* findLookAndFeel (const PopupMenu& menu, MenuWindow* parentWindow) const
{
if (parentWindow != nullptr)
return &(parentWindow->getLookAndFeel());
return parentWindow != nullptr ? &(parentWindow->getLookAndFeel())
: menu.lookAndFeel.get();
}
if (auto* lnf = menu.lookAndFeel.get())
return lnf;
LookAndFeel& findNonNullLookAndFeel (const PopupMenu& menu, MenuWindow* parentWindow) const
{
if (auto* result = findLookAndFeel (menu, parentWindow))
return *result;
return &getLookAndFeel();
return getLookAndFeel();
}
//==============================================================================


Loading…
Cancel
Save