summaryrefslogtreecommitdiff
path: root/web/src/components/grid/drawGrid.ts
diff options
context:
space:
mode:
authorJosh Kingsley <josh@joshkingsley.me>2025-10-25 22:05:04 +0300
committerJosh Kingsley <josh@joshkingsley.me>2025-10-25 22:10:04 +0300
commit1b8d05bf83d7bd9ab425852f519ea81bdc379444 (patch)
treea2555ce10f3c607c6809d020ba4d31fa3c05c7fb /web/src/components/grid/drawGrid.ts
parent5404a95c15e176d25728bf1a319ddb9828b23625 (diff)
feat(web): render and draw grid
Diffstat (limited to 'web/src/components/grid/drawGrid.ts')
-rw-r--r--web/src/components/grid/drawGrid.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/web/src/components/grid/drawGrid.ts b/web/src/components/grid/drawGrid.ts
new file mode 100644
index 0000000..6284693
--- /dev/null
+++ b/web/src/components/grid/drawGrid.ts
@@ -0,0 +1,30 @@
+import { RenderedGrid } from "./renderGrid";
+import colors from "open-color";
+
+export default function drawGrid(
+ ctx: CanvasRenderingContext2D,
+ grid: RenderedGrid,
+) {
+ ctx.clearRect(0, 0, grid.rect.width, grid.rect.height);
+
+ ctx.fillStyle = colors.gray[8];
+ ctx.fillRect(0, 0, grid.rect.width, grid.rect.height);
+
+ ctx.strokeStyle = colors.gray[7];
+
+ grid.renderedRows.forEach((row, renderedRowIndex) => {
+ const isLastRow = renderedRowIndex === grid.renderedRows.length - 1;
+
+ row.renderedCells.forEach((cell, cellIndex) => {
+ const { topLeft, width, height } = cell.rect;
+ const isLastCell = cellIndex === row.renderedCells.length - 1;
+
+ ctx.strokeRect(
+ topLeft.x + 0.5,
+ topLeft.y + 0.5,
+ isLastCell ? width - 1 : width,
+ isLastRow ? height - 1 : height,
+ );
+ });
+ });
+}