From 881aad743d78a170b31f0b35d263986577c5c782 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Mon, 30 Jan 2023 16:06:13 +0100 Subject: [PATCH] added renderToContext to Canvas --- src/lib/ui/Canvas.hx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib/ui/Canvas.hx b/src/lib/ui/Canvas.hx index 4063bb4..67e5396 100644 --- a/src/lib/ui/Canvas.hx +++ b/src/lib/ui/Canvas.hx @@ -1,5 +1,6 @@ package lib.ui; +import kernel.ui.WindowContext; import lib.Pos; import lib.Rect; import kernel.ui.Pixel; @@ -67,6 +68,28 @@ abstract Canvas(Array>) to Array> from Array line in this) { + if (line == null || line.length == 0) { + continue; + } + + for (pixelIndex => pixel in line) { + if (pixel == null) { + continue; + } + + ctx.setCursorPos(pixelIndex, lineIndex); + ctx.setBackgroundColor(pixel.bg); + ctx.setTextColor(pixel.textColor); + ctx.write(pixel.char); + } + } + } } class CanvasKeyValueIterator {