pixelEditor coming along
This commit is contained in:
parent
5d7d297050
commit
12a22cf55c
3 changed files with 49 additions and 15 deletions
|
|
@ -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)
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -130,7 +130,6 @@ os =
|
|||
|
||||
|
||||
windowComponent = config \ ui.stateful {
|
||||
a = debug! "window id" config.window,
|
||||
key = "window-" & (show config.window.id),
|
||||
focusable = True,
|
||||
init = {},
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ export const _rt = {
|
|||
_tag: (typeof obj === 'object' && obj !== null && field in obj) ? 'True' : 'False'
|
||||
}),
|
||||
storeSearch: (query: string) => {
|
||||
return Object.keys(store).filter(name => _rt.fuzzyMatch(query)(name)._tag === 'True');
|
||||
return Object.keys(store)
|
||||
.filter(name => _rt.fuzzyMatch(query)(name)._tag === 'True')
|
||||
.sort((a, b) => a.length - b.length);
|
||||
},
|
||||
getSource: (name: string) => {
|
||||
const ast = definitions.get(name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue