How exactly do I get this to show up in a menu when not using PopupMenu::addCustomItem( );

I’m having no luck with the following:

class ColorTeaser : public juce::PopupMenu::CustomComponent
    ColorTeaser(const juce::Colour& c) : color(c) { }
    ~ColorTeaser() {}
 void paint(Graphics& g) override
    DBG( "ColorTeaser::paint()" ); //this never gets called
    g.drawRect(0, 0, getWidth(), getHeight(), 3);
    //this also never gets called
    void getIdealSize(int &idealWidth, int &idealHeight) override { idealWidth = 20; idealHeight = 20; } 
    juce::Colour color;
juce::PopupMenu::Item noteOnColor;
    noteOnColor.commandManager = commandManager;
    noteOnColor.customComponent = new ColorTeaser(pianoRoll.getKeyboard().findColour(MatkatMusic::ExtendedMidiKeyboardComponent::ColourIds::keyDownOverlayColourId));
    noteOnColor.itemID = (int) commands->commandNoteOnColor;
    noteOnColor.text = commandManager->getCommandForID (commands->commandNoteOnColor)->shortName;

The menu item shows up and functions correctly, but that ColorTeaser component just won’t appear in the menu!! It’s driving me bonkers!!

Ok, it turns out that if you’re using setMacMainMenu(), you can’t have custom items in your menus. That should definitely be in the documentation for PopupMenu::addCustomItem(), etc…


OK a fix to the documentation will appear on develop.


We actually got the custom components working in the MacMainMenu. It was quite a bit of a task though and had to change quite a bit of the MacMainMenu code. We would appreciate it if JUCE would support it because it’s perfectly possible.


i suppose if you shared your solution, they’d add it…


Who owns the CustomComponent if it’s assigned via:
item.customComponent = new MyCustomComponent();
There’s nothing in the documentation that says who owns it. I’m not familiar with ReferenceCountedObjectPtr<CustomComponent> enough to know if the PopupMenu::Item owns it upon that assignment.

Figured it out
Some documentation for PopupMenu::Item would be nice that explains that if you use a CustomComponent, the item.text will not be displayed for that item.