PopupMenu and dropshadow when not on desktop

Quick question, perhaps there’s an obvious answer that I’ve missed…

If a PopupMenu is added to the desktop, we get a nice dropshadow underneath it.
However if we add the PopupMenu to a parent component (with PopupMenu::Options()) there is no such drop shadow.

I’ve been trying to add a DropShadower to the component(s) generated by PopupMenu but run in to all sorts of issues with managing the lifetime of the DropShadower. The fact that these components are not accessible isn’t helping either.

Is there an easy way to add the dropshadow to a PopupMenu if it’s not on the desktop? Or perhaps PopupMenu can be modified such that a DropShadower is added to its menu components whenever the flag for a drop shadow is set from the LookAndFeel?


There might be other ways, but you could do that in your look and feel.

You would have to set the backgroundColourId of your popup to be transparent (otherwise its window will be set as opaque) :
setColour (PopupMenu::backgroundColourId, Colours::transparentWhite);

then you could draw a drop shadow in your popup background like that for example (untested):

void drawPopupMenuBackground (Graphics& g, int width, int height) override
    juce::Rectangle<int> area (width, height);
    DropShadow shadow;
    shadow.radius = 10;
    area = area.reduced (2 * shadow.radius);
    shadow.drawForRectangle (g, area);

    g.setColour (Colours::white); // the actual background colour you want
    g.fillRect (area);

Thanks! I see how that could work. However with that approach the shadow needs to fit within the clipping region of the Graphics context, and hence the menu itself needs to be reduced in size (which has implications for all other LookAndFeel methods for the PopupMenu).

Perhaps there is another way to add the drop shadow outside the clipping region, like a DropShadower does by adding a new component that ‘follows’ its owner?

Bump, I’m also curious if there is an easy way to add the drop shadow outside of the clipping region. Anyone know?

I managed to do this by changing a custom LookAndFeel. Basically reducing the size of the popup menu to make space around it to draw custom drop shadows as suggested by lalala. It works fine, with the drawback that this carved out space for the drop shadow causes sub menus to disconnect from their main menu.

It would still be good if there would be a better solution for this in JUCE (e.g. allowing to set a custom drop shadow for popup menus when adding the menu to another component). In particular for IOS, where you can’t put any popup menu on the desktop and they’ll have to live somewhere inside one of the other components…

Yeah, I’ve tried the custom LookAndFeel, but like you mention the submenus seemingly float off of the side of the parent menu, which isn’t an acceptable solution for us.

I’m with you that the best solution would be something built into JUCE (perhaps a DropShadower class could be attached to each MenuWiindow that is created). JUCE team, any thoughts?

Yeah, it seems like a sensible suggestion, but the caveat is that it’ll be both rather time consuming to get right and low priority work in comparison to a lot of other things on our wish list.

If you can make a feature request out of it and gather enough community support that would be a way to increase it’s importance.