Pass Custom Component to addSubMenu


#1

Hi,

I’m trying to create a PopupMenu with sub-menus that uses custom components as the PopupMenu Items. I’ve been using addCustomItem() and this works perfectly unless I call addSubMenu(). The sub-menu that appears contains my custom components, but the item in the main menu that triggers the sub-menu is the default juce::PopupMenu::Item. Is there a way to make the item that triggers the sub-menu a custom component as well?

Perhaps another addSubMenu() function could be added to juce::PopupMenu that allows you to pass in a custom component just like addCustomItem() does.


#2

Maybe… not sure whether the menu class internals make that practical or not. Haven’t time to look at it myself, but feel free to dig around and suggest a change if it could be done with a minor tweak.


#3

Thanks for your reply!

I was able to implement it by adding this overloaded function for addSubMenu() to juce_PopupMenu:

void PopupMenu::addSubMenu (Component* customComponent, int idealWidth, int idealHeight, const bool triggerMenuItemAutomaticallyWhenClicked, const PopupMenu& subMenu, int itemResultID) { items.add (new Item (itemResultID, String::empty, true, false, Image::null, Colours::black, false, new NormalComponentWrapper (customComponent, idealWidth, idealHeight, triggerMenuItemAutomaticallyWhenClicked), &subMenu, nullptr)); }

Any chance you could add this?


#4

Thanks - I’ve done it slightly differently, using addCustomItem() instead, but it should do what you need now.


#5

Thanks for putting that in - I really appreciate it!