How to crop NanoVG draw outside the widget sizes?

Hi,

if I create my own Widget sized 200x100 and I try to draw any stuff using NanoVG (i.e. a circle at nvgCircle(vg, this->box.size.x, this->box.size.y, 10);, it draws outside the size of the widget.

Is there a way to crop it? i.e. draw only within the area of the widget?

Thanks

nvgScissor is what you need.

1 Like

ModuleWidget already scissors, so this is probably a bug with NanoVG. Or, you’re overriding ModuleWidget::draw(), which misses the scissor context. I wouldn’t do that. Instead, add child widgets.
Almost always, post screenshot(s) when talking about graphics.

Nice, it works perfectly :wink: Thanks

Don’t follow you here.

Yes, of course I’m overriding draw: well, I’m drawing :smile:
Here’s the code:

struct PlotDisplay : TransparentWidget {
	// ...

	PlotDisplay() {
		
	}

	void draw(NVGcontext *ctx) override {
		// nanoVG draw stuff
	}
};

I could add a child instead, as you said, but in any case at some point I need to override the draw method.

Or maybe, I don’t get what you are suggesting.