Skip to content

Commit

Permalink
feat(hiccup-canvas): add support for __clear ctrl attrib
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 3, 2023
1 parent 404eacb commit 2f3de82
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/hiccup-canvas/src/internal/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ export const __mergeState = (
res.edits!.push(id);
setAttrib(ctx, state, id, k, v);
}
} else if (id === "__background") {
} else if (id === "__background" || id === "__clear") {
ctx.save();
ctx.resetTransform();
ctx.fillStyle = resolveGradientOrColor(state, attribs[id]);
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
if (id === "__clear") {
attribs[id] &&
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
} else {
ctx.fillStyle = resolveGradientOrColor(state, attribs[id]);
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}
ctx.restore();
}
}
Expand Down

0 comments on commit 2f3de82

Please sign in to comment.