From cf297c75c6bf8ed3968b5766469ac7ddc54d42e6 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 12 Jan 2023 12:34:34 +0000 Subject: [PATCH] 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)); --- modules/juce_gui_basics/menus/juce_PopupMenu.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index 8dd135733a..f168cd8c5e 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -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(); } //==============================================================================