1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

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));
This commit is contained in:
reuk 2023-01-12 12:34:34 +00:00
parent 4b222427f9
commit cf297c75c6
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

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();
}
//==============================================================================