Creating a context menu for a TransparentWidget?

Hello! I’ve created custom Transparent Widgets for some elements on my module:

What I would like to do is provide some context menu features, like so:

I tried converting the TransparentWidgets to ParamWidgets and using appendContextMenu…

  void appendContextMenu(Menu *menu) override
  {
    GrooveBox *module = dynamic_cast<GrooveBox *>(this->module);
    assert(module);

    menu->addChild(new MenuSeparator);

    Etc....

… but that didn’t seem to work. Right clicking displayed the module’s right-click context menu.

Any suggestions? If at all possible, I’d like to avoid having to roll my own context menu from scratch. PS: Those aren’t the exact actions, but I’m using them as a visual example.

Thanks!

the difference between transparent widget and widget is that transparent widget ignores events. This is probably your first problem.

But the second problem is that Widget and TransparentWidget don’t have context menu plumbing built in. So you need to do a smidge of extra code for a custom menu.

That code is pretty easy. basically override onButton to look for a release with the right button. In that conditional, (1) consume the event then (2) just create and populate a rack::Menu

that’s all that the ParamWidget wrapper is doing.

Thanks for the response. It looks like you got me on the path to success! I’ll post my solution once I’m done. :grinning:

Cool

If you want to see it in the surge codebase

is where we call our virtual onShowMenu method to make a menu on a button and here’s one of the implementations which pops up, in this case, our FX presets

1 Like