From 2e05df8035d6d44f41084e22a7926812cf5e7f5c Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Sat, 21 Feb 2026 22:51:47 -0700 Subject: [PATCH] Mouse toggling pixel cells --- src/cg/06-pixelEditor.cg | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cg/06-pixelEditor.cg b/src/cg/06-pixelEditor.cg index 8d14550..220a433 100644 --- a/src/cg/06-pixelEditor.cg +++ b/src/cg/06-pixelEditor.cg @@ -1,6 +1,5 @@ pixelEditor = config \ c = config; - _ = debug! "pixEd config" c; upArrow = state \ ( newRow = max 0 (state.selectedRow - 1); @@ -19,7 +18,6 @@ pixelEditor = config \ { state = state.{ selectedCol = newCol }, emit = [] }); toggleFocused = state \ ( - _ = debug! "Toggling" state; row = state.selectedRow; col = state.selectedCol; newMap = contains { x = col, y = row } state.map @@ -37,13 +35,13 @@ pixelEditor = config \ map = [], # loadMap from store pixelWidth = 5, pixelHeight = 7, - zoomMultiplier = 5, + cellSize = 30, selectedRow = 0, selectedCol = 0 }, update = state event \ event - # | Toggle pixel \ (\ toggleFocused) + | ClickCell { x = x, y = y } \ toggleFocused state.{ selectedRow = y, selectedCol = x } | Key { key = " " } \ toggleFocused state | Key { key = "Enter" } \ toggleFocused state @@ -61,9 +59,6 @@ pixelEditor = config \ view = state emit \ # onToggle = path \ emit (Toggle path); - cellWidth = state.pixelWidth * state.zoomMultiplier; - cellHeight = state.pixelHeight * state.zoomMultiplier; - grid = ui.column { children = map (rIdx \ ui.row { @@ -72,9 +67,12 @@ pixelEditor = config \ color = (on |True\ "#000" |False\ "rgba(255,255,255,0.2)"); selected = and (rIdx == state.selectedRow) (cIdx == state.selectedCol); - strokeColor = (selected | True \ "#f00" | False \ "transparent"); + strokeColor = (selected | True \ "#f00" | False \ "rgba(0,0,0,0.2)"); - ui.rect { w = cellWidth, h = cellHeight, color = color, strokeWidth = 1, strokeColor = strokeColor } + ui.clickable { + onClick = \ _ = debug! "here" [rIdx, cIdx]; 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) } ) (range 0 state.pixelHeight)