Os module is now generated by CG. modularizing palette
This commit is contained in:
parent
fa999b70fe
commit
f2c381cad7
2 changed files with 159 additions and 167 deletions
|
|
@ -1,3 +1,5 @@
|
|||
@palette
|
||||
|
||||
paletteState = {
|
||||
query = "",
|
||||
focusedIndex = 0,
|
||||
|
|
@ -5,6 +7,8 @@ paletteState = {
|
|||
opacity = 0.95
|
||||
};
|
||||
|
||||
paletteHistory = [];
|
||||
|
||||
palette = config \
|
||||
windowHeight = 400;
|
||||
windowWidth = 600;
|
||||
|
|
@ -172,3 +176,4 @@ palette = config \
|
|||
}
|
||||
}
|
||||
};
|
||||
@
|
||||
|
|
|
|||
223
src/cg/os.cg
223
src/cg/os.cg
|
|
@ -3,7 +3,7 @@
|
|||
osState = {
|
||||
palette = { visible = True },
|
||||
windows = [],
|
||||
blah = 3,
|
||||
blah = 53,
|
||||
wm = {
|
||||
focusedIndex = 0,
|
||||
scrollOffset = 0,
|
||||
|
|
@ -12,10 +12,10 @@ osState = {
|
|||
nextId = 0
|
||||
};
|
||||
|
||||
os =
|
||||
openPalette = _ \ osState.palette.visible := not (osState.palette.visible);
|
||||
os = openPalette = _ \ osState.palette.visible := not osState.palette.visible;
|
||||
|
||||
windowWidth = window \ window.fullWidth
|
||||
windowWidth = window \
|
||||
window.fullWidth
|
||||
| True \ viewport.width
|
||||
| False \ window.width;
|
||||
|
||||
|
|
@ -27,14 +27,13 @@ os =
|
|||
windowW = unwrapOr osState.wm.defaultWindowWidth (nth index widths);
|
||||
scrollOffset = osState.wm.scrollOffset;
|
||||
vw = viewport.width;
|
||||
(windowX < scrollOffset
|
||||
windowX < scrollOffset
|
||||
| True \ windowX
|
||||
| False \ (windowX + windowW > scrollOffset + vw
|
||||
| True \ windowX + windowW - vw
|
||||
| False \ scrollOffset));
|
||||
| False \ ((windowX + windowW) > (scrollOffset + vw)
|
||||
| True \ (windowX + windowW) - vw
|
||||
| False \ scrollOffset);
|
||||
|
||||
focusWindow = index \
|
||||
batch [
|
||||
focusWindow = index \ batch [
|
||||
osState.palette.visible := False,
|
||||
osState.wm.focusedIndex := index,
|
||||
osState.wm.scrollOffset := scrollToWindow index
|
||||
|
|
@ -57,16 +56,14 @@ os =
|
|||
|
||||
closeWindowByIndex = i \
|
||||
focused = osState.wm.focusedIndex;
|
||||
newFocused = (i < focused
|
||||
newFocused = i < focused
|
||||
| True \ focused - 1
|
||||
| False \ (i == focused
|
||||
| True \ max 0 (focused - 1)
|
||||
| False \ focused));
|
||||
|
||||
| False \ focused);
|
||||
batch [
|
||||
osState.windows := (take i osState.windows) & (drop (i + 1) osState.windows),
|
||||
focusWindow newFocused
|
||||
# osState.wm.focusedIndex := min newFocused (len osState.windows - 2)
|
||||
];
|
||||
|
||||
closeFocusedWindow = _ \ closeWindowByIndex osState.wm.focusedIndex;
|
||||
|
|
@ -81,71 +78,72 @@ os =
|
|||
|
||||
openOrFocus = title content width \
|
||||
index title (map (w \ w.title) osState.windows)
|
||||
| Some i \ focusWindow i
|
||||
| (Some i) \ focusWindow i
|
||||
| None \ openWindow title content width;
|
||||
|
||||
renderWindow = window isActive \
|
||||
titleBarHeight = 36;
|
||||
|
||||
ui.stack {
|
||||
children = [
|
||||
# background
|
||||
ui.rect { w = (windowWidth window), h = viewport.height, color = (isActive | True \ "#0a2a3a" | False \ "#061820")},
|
||||
|
||||
# title bar
|
||||
ui.stack { children = [
|
||||
ui.rect {
|
||||
w = windowWidth window,
|
||||
h = viewport.height,
|
||||
color = isActive
|
||||
| True \ "#0a2a3a"
|
||||
| False \ "#061820"
|
||||
},
|
||||
ui.positioned {
|
||||
x = 0, y = 0,
|
||||
child = ui.stack {
|
||||
children = [
|
||||
# background
|
||||
ui.rect { w = (windowWidth window), h = titleBarHeight, color = (isActive | True \ "#a15f80" | False \ "#0f3348") },
|
||||
ui.row {
|
||||
children = [
|
||||
# close button
|
||||
x = 0,
|
||||
y = 0,
|
||||
child = ui.stack { children = [
|
||||
ui.rect {
|
||||
w = windowWidth window,
|
||||
h = titleBarHeight,
|
||||
color = isActive
|
||||
| True \ "#a15f80"
|
||||
| False \ "#0f3348"
|
||||
},
|
||||
ui.row { children = [
|
||||
ui.clickable {
|
||||
onClick = _ \ closeWindowById window.id,
|
||||
child = ui.stack {
|
||||
children = [
|
||||
# button background
|
||||
ui.rect { w = titleBarHeight, h = titleBarHeight, color = "rgba(255,255,255,0.2)" },
|
||||
# button text
|
||||
ui.positioned {
|
||||
x = 12, y = 5, child = text "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
child = ui.stack { children = [
|
||||
ui.rect {
|
||||
w = titleBarHeight,
|
||||
h = titleBarHeight,
|
||||
color = "rgba(255,255,255,0.2)"
|
||||
},
|
||||
|
||||
# title
|
||||
ui.positioned { x = 8, y = 8, child = renderText { content = window.title, color = "white" } },
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
ui.positioned { x = 12, y = 5, child = text "x" }
|
||||
] }
|
||||
},
|
||||
|
||||
# content
|
||||
ui.positioned {
|
||||
x = 0, y = titleBarHeight,
|
||||
x = 8,
|
||||
y = 8,
|
||||
child = renderText { content = window.title, color = "white" }
|
||||
}
|
||||
] }
|
||||
] }
|
||||
},
|
||||
ui.positioned {
|
||||
x = 0,
|
||||
y = titleBarHeight,
|
||||
child = ui.clip {
|
||||
w = (windowWidth window),
|
||||
w = windowWidth window,
|
||||
h = viewport.height - titleBarHeight,
|
||||
child = window.content {
|
||||
w = (windowWidth window),
|
||||
w = windowWidth window,
|
||||
h = viewport.height - titleBarHeight,
|
||||
openApp = openOrFocus,
|
||||
close = _ \ closeWindowById window.id
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
] };
|
||||
|
||||
windowComponent = config \ ui.stateful {
|
||||
key = "window-" & (show config.window.id),
|
||||
focusable = True,
|
||||
init = { },
|
||||
update = state event \ event
|
||||
update = state event \
|
||||
event
|
||||
| Focused \ { state = state, emit = [focusWindow config.index] }
|
||||
| ChildFocused \ { state = state, emit = [focusWindow config.index] }
|
||||
| _ \ { state = state, emit = [] },
|
||||
|
|
@ -153,7 +151,7 @@ os =
|
|||
};
|
||||
|
||||
onScroll = delta \
|
||||
totalWidth = (sum (map windowWidth osState.windows)) + (max 0 (len osState.windows - 1));
|
||||
totalWidth = (sum (map windowWidth osState.windows)) + (max 0 ((len osState.windows) - 1));
|
||||
osState.wm.scrollOffset := max 0 (min (totalWidth - viewport.width) (osState.wm.scrollOffset + delta.deltaX));
|
||||
|
||||
renderWindows = _ \
|
||||
|
|
@ -168,8 +166,8 @@ os =
|
|||
onScroll = onScroll,
|
||||
child = ui.row {
|
||||
gap = 1,
|
||||
children = mapWithIndex (w i \ windowComponent { window = w, index = i, isActive = (i == focused) }) windows
|
||||
},
|
||||
children = mapWithIndex (w i \ windowComponent { window = w, index = i, isActive = i == focused }) windows
|
||||
}
|
||||
};
|
||||
|
||||
search = q \
|
||||
|
|
@ -185,25 +183,27 @@ os =
|
|||
];
|
||||
|
||||
onSelect = input \
|
||||
historyEvent = paletteHistory := take 50 [input, ...(filter (e \ e != input) paletteHistory)];
|
||||
dw = osState.wm.defaultWindowWidth;
|
||||
appWidth = app \ hasField "width" app | True \ app.width | false \ dw;
|
||||
openEvent = eval! input
|
||||
| Defined name \ (
|
||||
app = inspector { name = name };
|
||||
openOrFocus name app.view (appWidth app))
|
||||
historyEvent = paletteHistory := take 50 [input, ...filter (e \ e != input) paletteHistory];
|
||||
|
||||
| Value v \ (hasField "_tag" v
|
||||
dw = osState.wm.defaultWindowWidth;
|
||||
|
||||
appWidth = app \
|
||||
hasField "width" app
|
||||
| True \ app.width
|
||||
| false \ dw;
|
||||
openEvent = eval! input
|
||||
| (Defined name) \ (app = inspector { name = name };
|
||||
openOrFocus name app.view (appWidth app))
|
||||
| (Value v) \ (hasField "_tag" v
|
||||
| True \ batch [historyEvent, v]
|
||||
| False \ (hasField "view" v
|
||||
| True \ openOrFocus input v.view (appWidth v)
|
||||
| False \ (getSource input == ""
|
||||
| False \ ((getSource input) == ""
|
||||
| True \ openOrFocus input (_ \ renderText { content = show v, color = "white" }) dw
|
||||
| False \ (
|
||||
app = inspector { name = input };
|
||||
| False \ (app = inspector { name = input };
|
||||
openOrFocus input app.view (appWidth app)))))
|
||||
|
||||
| Err msg \ (_ = debug! "OS Error" msg; noOp);
|
||||
| (Err msg) \ (_ = debug! "OS Error" msg;
|
||||
noOp);
|
||||
batch [historyEvent, openEvent];
|
||||
|
||||
handleFocusLeftEvent = state \
|
||||
|
|
@ -211,85 +211,72 @@ os =
|
|||
{ state = state, emit = [focusWindow newIndex] };
|
||||
|
||||
handleFocusRightEvent = state \
|
||||
newIndex = min (len osState.windows - 1) (osState.wm.focusedIndex + 1);
|
||||
newIndex = min ((len osState.windows) - 1) (osState.wm.focusedIndex + 1);
|
||||
{ state = state, emit = [focusWindow newIndex] };
|
||||
|
||||
handleMoveLeftEvent = state \
|
||||
idx = osState.wm.focusedIndex;
|
||||
idx == 0
|
||||
| True \ { state = state, emit = [] }
|
||||
| False \ (
|
||||
newIdx = idx - 1;
|
||||
| False \ (newIdx = idx - 1;
|
||||
windows = osState.windows;
|
||||
newWindows = [
|
||||
...take newIdx windows,
|
||||
nth idx windows ~ unwrapOr {},
|
||||
nth newIdx windows ~ unwrapOr {},
|
||||
unwrapOr { } (nth idx windows),
|
||||
unwrapOr { } (nth newIdx windows),
|
||||
...drop (idx + 1) windows
|
||||
];
|
||||
{ state = state, emit = [osState.windows := newWindows, focusWindow newIdx] }
|
||||
);
|
||||
{
|
||||
state = state,
|
||||
emit = [osState.windows := newWindows, focusWindow newIdx]
|
||||
});
|
||||
|
||||
handleMoveRightEvent = state \
|
||||
idx = osState.wm.focusedIndex;
|
||||
idx == len osState.windows - 1
|
||||
idx == ((len osState.windows) - 1)
|
||||
| True \ { state = state, emit = [] }
|
||||
| False \ (
|
||||
newIdx = idx + 1;
|
||||
| False \ (newIdx = idx + 1;
|
||||
windows = osState.windows;
|
||||
newWindows = [
|
||||
...take idx windows,
|
||||
nth newIdx windows ~ unwrapOr {},
|
||||
nth idx windows ~ unwrapOr {},
|
||||
unwrapOr { } (nth newIdx windows),
|
||||
unwrapOr { } (nth idx windows),
|
||||
...drop (newIdx + 1) windows
|
||||
];
|
||||
{ state = state, emit = [osState.windows := newWindows, focusWindow newIdx] }
|
||||
);
|
||||
{
|
||||
state = state,
|
||||
emit = [osState.windows := newWindows, focusWindow newIdx]
|
||||
});
|
||||
|
||||
ui.stateful {
|
||||
key = "os",
|
||||
autoFocus = True,
|
||||
|
||||
init = { },
|
||||
|
||||
update = state event \ event
|
||||
| Key { key = "p", meta = True } \
|
||||
{ state = state, emit = [openPalette] }
|
||||
|
||||
| Key { key = "ArrowLeft", meta = True, shift = True } \ handleMoveLeftEvent state
|
||||
| Key { key = "h", meta = True, shift = True } \ handleMoveLeftEvent state
|
||||
|
||||
| Key { key = "ArrowRight", meta = True, shift = True } \ handleMoveRightEvent state
|
||||
| Key { key = "l", meta = True, shift = True } \ handleMoveRightEvent state
|
||||
|
||||
| Key { key = "ArrowLeft", meta = True } \ handleFocusLeftEvent state
|
||||
| Key { key = "h", meta = True } \ handleFocusLeftEvent state
|
||||
|
||||
| Key { key = "ArrowRight", meta = True } \ handleFocusRightEvent state
|
||||
| Key { key = "l", meta = True } \ handleFocusRightEvent state
|
||||
|
||||
| Key { key = "d", meta = True } \
|
||||
{ state = state, emit = [closeFocusedWindow 0] }
|
||||
| Key { key = "f", meta = True } \
|
||||
{ state = state, emit = [toggleMaximizeFocusedWindow 0] }
|
||||
update = state event \
|
||||
event
|
||||
| (Key {key = "p", meta = True}) \ { state = state, emit = [openPalette] }
|
||||
| (Key {key = "ArrowLeft", meta = True, shift = True}) \ handleMoveLeftEvent state
|
||||
| (Key {key = "h", meta = True, shift = True}) \ handleMoveLeftEvent state
|
||||
| (Key {key = "ArrowRight", meta = True, shift = True}) \ handleMoveRightEvent state
|
||||
| (Key {key = "l", meta = True, shift = True}) \ handleMoveRightEvent state
|
||||
| (Key {key = "ArrowLeft", meta = True}) \ handleFocusLeftEvent state
|
||||
| (Key {key = "h", meta = True}) \ handleFocusLeftEvent state
|
||||
| (Key {key = "ArrowRight", meta = True}) \ handleFocusRightEvent state
|
||||
| (Key {key = "l", meta = True}) \ handleFocusRightEvent state
|
||||
| (Key {key = "d", meta = True}) \ { state = state, emit = [closeFocusedWindow 0] }
|
||||
| (Key {key = "f", meta = True}) \ { state = state, emit = [toggleMaximizeFocusedWindow 0] }
|
||||
| _ \ { state = state, emit = [] },
|
||||
|
||||
view = state emit \
|
||||
ui.stack {
|
||||
children = [
|
||||
view = state emit \ ui.stack { children = [
|
||||
ui.rect { w = viewport.width, h = viewport.height, color = "#012" },
|
||||
|
||||
renderWindows 0,
|
||||
|
||||
# keep palette at the end so it's on top
|
||||
osState.palette.visible
|
||||
| True \ palette {
|
||||
search = search,
|
||||
onSelect = onSelect,
|
||||
viewport = viewport,
|
||||
}
|
||||
| False \ empty,
|
||||
]
|
||||
viewport = viewport
|
||||
}
|
||||
| False \ empty
|
||||
] }
|
||||
};
|
||||
|
||||
@
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue