Mouse toggling pixel cells

master
Dustin Swan 5 days ago
parent eccc14a714
commit 2e05df8035
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -1,6 +1,5 @@
pixelEditor = config \ pixelEditor = config \
c = config; c = config;
_ = debug! "pixEd config" c;
upArrow = state \ ( upArrow = state \ (
newRow = max 0 (state.selectedRow - 1); newRow = max 0 (state.selectedRow - 1);
@ -19,7 +18,6 @@ pixelEditor = config \
{ state = state.{ selectedCol = newCol }, emit = [] }); { state = state.{ selectedCol = newCol }, emit = [] });
toggleFocused = state \ ( toggleFocused = state \ (
_ = debug! "Toggling" state;
row = state.selectedRow; row = state.selectedRow;
col = state.selectedCol; col = state.selectedCol;
newMap = contains { x = col, y = row } state.map newMap = contains { x = col, y = row } state.map
@ -37,13 +35,13 @@ pixelEditor = config \
map = [], # loadMap from store map = [], # loadMap from store
pixelWidth = 5, pixelWidth = 5,
pixelHeight = 7, pixelHeight = 7,
zoomMultiplier = 5, cellSize = 30,
selectedRow = 0, selectedRow = 0,
selectedCol = 0 selectedCol = 0
}, },
update = state event \ event update = state event \ event
# | Toggle pixel \ (\ toggleFocused) | ClickCell { x = x, y = y } \ toggleFocused state.{ selectedRow = y, selectedCol = x }
| Key { key = " " } \ toggleFocused state | Key { key = " " } \ toggleFocused state
| Key { key = "Enter" } \ toggleFocused state | Key { key = "Enter" } \ toggleFocused state
@ -61,9 +59,6 @@ pixelEditor = config \
view = state emit \ view = state emit \
# onToggle = path \ emit (Toggle path); # onToggle = path \ emit (Toggle path);
cellWidth = state.pixelWidth * state.zoomMultiplier;
cellHeight = state.pixelHeight * state.zoomMultiplier;
grid = ui.column { grid = ui.column {
children = map (rIdx \ children = map (rIdx \
ui.row { ui.row {
@ -72,9 +67,12 @@ pixelEditor = config \
color = (on |True\ "#000" |False\ "rgba(255,255,255,0.2)"); color = (on |True\ "#000" |False\ "rgba(255,255,255,0.2)");
selected = and (rIdx == state.selectedRow) (cIdx == state.selectedCol); 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.pixelWidth)
} }
) (range 0 state.pixelHeight) ) (range 0 state.pixelHeight)

Loading…
Cancel
Save