summaryrefslogtreecommitdiff
path: root/web/src/components/grid/drawGrid.ts
diff options
context:
space:
mode:
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,
+ );
+ });
+ });
+}