Easy feature: drawPopupMenuBackground fails to pass pointer to associated PopupMenu

Which makes it tricky to have different backgrounds for different menus! Can a pointer thrown in?

edit: I realise I can’t have a pointer to the PopupMenu object itself as it may have been deleted, but a pointer to the specific window would be useful :). We’ve got some really sexy looking menus with semi-transparent blurred backgrounds working. But I have a horrible hack at the mo to identify which blurred background to draw.

1 Like

Would access to the PopupMenu::options or PopupMenu::Options::targetComponent help?

That was promised to come soon here:

I think I need access to the actual Component for the menu as well. But those would be a great start. Just a Component & on the background painting call would be fine :slight_smile:

1 Like

I’d second this, and add that it would be really helpful if a const reference to the PopupMenu::Options field (or the targetComponent*) was also available in LookAndFeel::preparePopupMenuWindow(Component& c). That method’s only implementation is a stub in juce::LookAndFeel_V2, so that wouldn’t affect much, but would make it possible to alter the layout, etc. in response to the context.

For example, I’ve been trying to make a popup menu that renders like a CallOutBox/BubbleComponent (slightly rounded corners and with an arrow back to target) and it has been a slog. I can do things like shift the window over via preparePopupMenu, but without access to the options, I don’t know where it is in relation to its target.

I’m realizing now that PopupMenu::Options probably couldn’t be passed to drawPopupMenuBackground at present because it’s also being used by BurgerMenuComponent.

It could have an overload added with PopupMenu::Options, though, with PopupMenu using that version, and BurgerMenuComponent using the current one. Calls to the method with Options in existing LAFs could simply delegate to the method without Options.

Any updates on this issue ? it seems the other thread was closed as unresolved.

It was “kind of” resolved: In the drawPopupMenuBackgroundWithOptions has all information needed.

But the fix only fixes future LookAndFeels (and there are no new ones). The existing remain broken in that respect for backward compatibility.

I created fixed versions of all juce::LookAndFeel_Vx in my PluginGuiMagic (source)

Feel free to have a look, it is a lot of copy/paste. Just the colour lookup is modified to use the new findPopupColour() like proposed before:

juce::Colour JuceLookAndFeel_V2::findPopupColour (int colourId, juce::Component* target)
{
    if (target)
        return target->findColour (colourId);

    return findColour (colourId);
}

Hope that helps

1 Like

Thanks, I appreciate it !

I looked at the code example you shared; for some reason when i try to invoke “getTargetComponent” in “drawPopupMenuBackgroundWithOptions” , i get a nullptr :frowning: I was thinking of grabbing the background color for the combobox that way, but was unable to…

void drawPopupMenuBackgroundWithOptions(juce::Graphics& g, int width, int height, const juce::PopupMenu::Options& opt) override
{
  const juce::Component* tgt = opt.getTargetComponent();
  if(tgt != nullptr)
  {
     std::cout << "FOUND POPUP TARGET" << std::endl;
  }
}

this code does not seem to work for me :confused:

the const was the problem… I am able to grab colors values from the parent combobox component :slight_smile: