diff --git a/canvas.ts b/canvas.ts index 24bbfab..968b08e 100644 --- a/canvas.ts +++ b/canvas.ts @@ -89,6 +89,7 @@ export class Doodler { // } for (const [i, l] of (this.layers || []).entries()) { l(this.ctx, i); + this.drawDeferred(); } this.drawUI(); } @@ -227,6 +228,18 @@ export class Doodler { ); } + private deferredDrawings: (() => void)[] = []; + + deferDrawing(cb: () => void) { + this.deferredDrawings.push(cb); + } + + drawDeferred() { + while (this.deferredDrawings.length) { + this.deferredDrawings.pop()?.(); + } + } + setStyle(style?: IStyle) { const ctx = this.ctx; ctx.fillStyle = style?.color || style?.fillColor || "black";