|
|
|
|
@ -1,6 +1,28 @@
|
|
|
|
|
pixelEditor = config \
|
|
|
|
|
downArrow = state \
|
|
|
|
|
{ state = state, emit = [] };
|
|
|
|
|
upArrow = state \ (
|
|
|
|
|
newRow = max 0 (state.selectedRow - 1);
|
|
|
|
|
{ state = state.{ selectedRow = newRow }, emit = [] });
|
|
|
|
|
|
|
|
|
|
downArrow = state \ (
|
|
|
|
|
newRow = min (state.pixelHeight - 1) (state.selectedRow + 1);
|
|
|
|
|
{ state = state.{ selectedRow = newRow }, emit = [] });
|
|
|
|
|
|
|
|
|
|
leftArrow = state \ (
|
|
|
|
|
newCol = max 0 (state.selectedCol - 1);
|
|
|
|
|
{ state = state.{ selectedCol = newCol }, emit = [] });
|
|
|
|
|
|
|
|
|
|
rightArrow = state \ (
|
|
|
|
|
newCol = min (state.pixelWidth - 1) (state.selectedCol + 1);
|
|
|
|
|
{ state = state.{ selectedCol = newCol }, emit = [] });
|
|
|
|
|
|
|
|
|
|
toggleFocused = state \ (
|
|
|
|
|
_ = debug! "Toggling" state;
|
|
|
|
|
row = state.selectedRow;
|
|
|
|
|
col = state.selectedCol;
|
|
|
|
|
newMap = contains { x = col, y = row } state.map
|
|
|
|
|
| True \ filter (e \ e != { x = col, y = row }) state.map
|
|
|
|
|
| False \ [...state.map, { x = col, y = row }];
|
|
|
|
|
{ state = state.{ map = newMap }, emit = [] });
|
|
|
|
|
|
|
|
|
|
ui.stateful {
|
|
|
|
|
focusable = True,
|
|
|
|
|
@ -9,17 +31,18 @@ pixelEditor = config \
|
|
|
|
|
key = "pixelEditor-" & config.path,
|
|
|
|
|
|
|
|
|
|
init = {
|
|
|
|
|
expanded = [], # loadMap from store
|
|
|
|
|
map = [], # loadMap from store
|
|
|
|
|
pixelWidth = 5,
|
|
|
|
|
pixelHeight = 7,
|
|
|
|
|
zoomMultiplier = 10,
|
|
|
|
|
selectedCords = { x = 0, y = 0 },
|
|
|
|
|
editing = None
|
|
|
|
|
zoomMultiplier = 5,
|
|
|
|
|
selectedRow = 0,
|
|
|
|
|
selectedCol = 0
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update = state event \ event
|
|
|
|
|
# | Toggle pixel \ (\ toggleFocused)
|
|
|
|
|
| Key { key = "Space" } \ (\ toggleFocused)
|
|
|
|
|
| Key { key = " " } \ toggleFocused state
|
|
|
|
|
| Key { key = "Enter" } \ toggleFocused state
|
|
|
|
|
|
|
|
|
|
| Key { key = "ArrowDown" } \ downArrow state
|
|
|
|
|
| Key { key = "j" } \ downArrow state
|
|
|
|
|
@ -35,12 +58,22 @@ pixelEditor = config \
|
|
|
|
|
view = state emit \
|
|
|
|
|
# onToggle = path \ emit (Toggle path);
|
|
|
|
|
|
|
|
|
|
cellWidth = state.pixelWidth * zoomMultiplier;
|
|
|
|
|
cellHeight = state.pixelHeight * zoomMultiplier;
|
|
|
|
|
rows = range 0 pixelHeight;
|
|
|
|
|
columns = range 0 pixelWidth;
|
|
|
|
|
cellWidth = state.pixelWidth * state.zoomMultiplier;
|
|
|
|
|
cellHeight = state.pixelHeight * state.zoomMultiplier;
|
|
|
|
|
|
|
|
|
|
center {
|
|
|
|
|
child = mapWidthIndex (rect) rows
|
|
|
|
|
ui.column {
|
|
|
|
|
children = map (rIdx \
|
|
|
|
|
ui.row {
|
|
|
|
|
children = map (cIdx \
|
|
|
|
|
on = contains { x = cIdx, y = rIdx } state.map;
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
ui.rect { w = cellWidth, h = cellHeight, color = color, strokeWidth = 1, strokeColor = strokeColor }
|
|
|
|
|
) (range 0 state.pixelWidth)
|
|
|
|
|
}
|
|
|
|
|
) (range 0 state.pixelHeight)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|