What's the right was to make a param widget?

I’ve tinkered with widget making, but never felt I was doing it right.

Today I had a familiar problem: I needed a multi-value toggle button, so I made one by deriving from SvgButton. That was fine.

Then I wanted it to be a ParamWidget so my button can control a param. I ended up deriving a new class from ParamWidget, embedding an instance of my button in it as a member variable, then make it work by a bunch of ugly code to delegate things between my param widget and the widget that it encapsulate.

The ugly result is here: https://github.com/squinkylabs/SquinkyVCV/blob/80589c6b5b91318e7a74949a6cdc134f7d5908a9/src/ctrl/ToggleButtonV1.h#L87

In the v0.6 day perhaps I could have used virtual inheritance to have mywidget drive from param widget and SVGSwitch?

Is there a “good” way to turn a UI widget into a param widget?

Just use SvgSwitch. I don’t see any functionality you’d need that it doesn’t have.

Oh, man, am I dumb. I didn’t notice that it’s already a ParamWidget! Will it also cycle through mutliple values? Well, doesn’t matter, definitely gotta revert some of that junk code from yesterday.


Here’s the documentation of its direct superclass. https://github.com/VCVRack/Rack/blob/v1/include/app/Switch.hpp#L10