[noob] light with svg

I’m looking for an example on how to create custom widget : I want to be able to create something similar to a light, but using a custom svn image.
I.E : to be able to draw or not an image on top of the module.
what is the most simple way?

(I found answer for custom switch, but I don’t need the user interaction part)


1 Like

Take a look at the SvgButton source code for reference: https://github.com/VCVRack/Rack/blob/v1/include/app/SvgButton.hpp

Maybe there is an easier way, but what I would do is make a new custom widget inheriting from TransparentWidget which basically copies SvgButton without the click functionality. I think this is what the widget should look like, but WARNING: I didn’t actually run this code so there are probably errors.

struct ChCustomWidget : TransparentWidget {
	ChModule *module;
	widget::FramebufferWidget *fb;
	widget::SvgWidget *sw;

	ChCustomWidget() {

	void addFrame(std::shared_ptr<Svg> svg) {
		// If this is our first frame, automatically set SVG and size
		if (!sw->svg) {
			box.size = sw->box.size;
			fb->box.size = sw->box.size;

	void draw(const DrawArgs &args) override {
		if (module) {
			fb->dirty = true;
		else {



Your Module (of type ChModule in my example) must have a member svgIndex which tells the widget which svg to show. Instantiate the ChCustomWidget in your ModuleWidget constructor like this:

ChCustomWidget *chWidget = new ChCustomWidget();
			chWidget->module = module;
			chWidget->box.pos = Vec(20, 20);