From d58c39a1acf1198bf880d70985c78a8fea5041ca Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Sun, 22 Feb 2026 15:53:06 -0700 Subject: [PATCH] Loading glyphs --- src/cg/06-pixelEditor.cg | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/cg/06-pixelEditor.cg b/src/cg/06-pixelEditor.cg index 1e7ed9e..b125895 100644 --- a/src/cg/06-pixelEditor.cg +++ b/src/cg/06-pixelEditor.cg @@ -35,20 +35,31 @@ pixelEditor = config \ newState = state.{ map = newMap }; { state = newState, emit = saveGlyph newState }); + existing = eval! (c.path); + size \ ui.stateful { focusable = True, autoFocus = True, - key = "pixelEditor-" & config.path, + key = "pixelEditor-" & c.path, - init = { - map = [], # loadMap from store - pixelWidth = 5, - pixelHeight = 7, - cellSize = 30, - selectedRow = 0, - selectedCol = 0 - }, + init = existing + | Value v \ { + map = v.map, + pixelWidth = 5, + pixelHeight = 7, + cellSize = 30, + selectedRow = 0, + selectedCol = 0 + } + | _ \ { + map = [], + pixelWidth = 5, + pixelHeight = 7, + cellSize = 30, + selectedRow = 0, + selectedCol = 0 + }, update = state event \ event | ClickCell { x = x, y = y } \ toggleFocused state.{ selectedRow = y, selectedCol = x } @@ -87,7 +98,7 @@ pixelEditor = config \ strokeColor = (selected | True \ "#f00" | False \ "rgba(0,0,0,0.2)"); ui.clickable { - onClick = \ _ = debug! "here" [rIdx, cIdx]; emit (ClickCell { x = cIdx, y = rIdx }), + onClick = \ emit (ClickCell { x = cIdx, y = rIdx }), child = ui.rect { w = state.cellSize, h = state.cellSize, color = color, strokeWidth = 1, strokeColor = strokeColor } } ) (range 0 state.pixelWidth)