PopupMenu - Add CustomComponent with Submenu Request


Hi Jules,

I’ve no idea how nobody has not come across this before, but you can’t add a PopupMenu::CustomComponent with a submenu, therefore having to add it as a regular Component… Adding the option for a submenu with a CustomComponent lets JUCE users advantage of the item highlighting. Here be code to do just that:


    void addCustomItem (int itemResultID, CustomComponent* customComponent,
                        const PopupMenu* optionalSubMenu = nullptr);


void PopupMenu::addCustomItem (const int itemResultID, CustomComponent* const customComponent,
                               const PopupMenu* optionalSubMenu)
    jassert (itemResultID != 0);    // 0 is used as a return value to indicate that the user
                                    // didn't pick anything, so you shouldn't use it as the id
                                    // for an item..

    items.add (new Item (itemResultID, String::empty, true, false, Image::null,
                         Colours::black, false, customComponent, optionalSubMenu, nullptr));


Good point, thanks! Will add that.