Show PopupMenu animated?

We’re adding some final polish to a plug-in and are trying to find a way to show PopupMenus animated.

Is there anyway to get a handle on a PopupMenu’s MenuWindow component? The only place where I can see it is possible is in the Lnf method “preparePopupMenuWindow”

Any help in figuring out how to show PopupMenus animated without it turning into a hack-a-thon would be much appreciated!

Something like this? (warning: untested)

/*******************************************************************************
 The block below describes the properties of this PIP. A PIP is a short snippet
 of code that can be read by the Projucer and used to generate a JUCE project.

 BEGIN_JUCE_PIP_METADATA

  name:             AnimatedPopupMenu

  dependencies:     juce_core, juce_data_structures, juce_events, juce_graphics, juce_gui_basics
  exporters:        xcode_mac

  moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1

  type:             Component
  mainClass:        MyComponent

 END_JUCE_PIP_METADATA

*******************************************************************************/

#pragma once


//==============================================================================
class MyComponent   : public Component
{
public:
    //==============================================================================
    MyComponent()
    {
        addAndMakeVisible (showPopupButton);
        
        showPopupButton.onClick = [this]
        {
            PopupMenu m;
            
            for (int i = 1; i <= 10; ++i)
                m.addItem (i, "Item " + String (i));
            
            m.setLookAndFeel (&lf);
            m.showMenu (PopupMenu::Options().withParentComponent (this));
        };
        
        setSize (600, 400);
    }

    ~MyComponent()
    {
    }

    //==============================================================================
    void paint (Graphics& g) override
    {
        g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
    }

    void resized() override
    {
        showPopupButton.centreWithSize (250, 35);
    }


private:
    //==============================================================================
    TextButton showPopupButton { "Show popup" };
    
    struct PopupLF : public LookAndFeel_V4
    {
        void preparePopupMenuWindow (Component& menu)
        {
            Desktop::getInstance().getAnimator().fadeIn (&menu, 1000);
        }
    };
    
    PopupLF lf;


    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyComponent)
};


1 Like

Works great Ed!

On Big Sur, the menu appears without a shadow. Is there some correct way to keep the shadow when animating?