PopupMenu x

Can we have direct access to the Array of Items in this, or failing that at least functions to allow removing or adding items anywhere without copying them to a new PopupMenu?

Frequently we have some reusable class that generates a menu and we then want to edit it for a specific purpose. Maybe adding a new item at the top or whatever, and it’s a real fucking pain in the arse with the way PopupMenu is written :slight_smile:

1 Like

I’m reluctant to expose any of the PopupMenu’s internals as that would then restrict what we can do with it in the future. I don’t want to come across as being difficult - keeping implementation details outside of the API is a core responsibility of an API developer.

Why not keep a vector of items and have a very simple function for turning that vector into a PopupMenu? That way you can reuse and modify the vector without much difficulty.

Perhaps a PopupMenu::insertItem(int index, ...) could work?

To work around it as things stand your classes could have lambda function addMenuItemsAtTop/addMenuItemsAtBottom that pass a PopupMenu reference and allow insertion of extra items (this is an approach I’ve used before). The only issue there is you’re kind of stuck either adding items to the top or bottom of the menu, but I’ve found that’s the usual use case, so it worked for me.

Yeah, just needs functions for inspecting and inserting stuff anywhere really.

However … your point about passing an array of Items’ around rather than the menu is a strong and sensible suggestion. Although if the items are a submenu it kind of gets complicated and we are back where we started …?