fixing pretty printer. adding updateAt. getting maximize windows going. fixing scrolling. new windows start focused

master
Dustin Swan 2 weeks ago
parent db00b914fc
commit 8c20a29b54
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -191,7 +191,14 @@ export function prettyPrint(ast: AST, indent = 0): string {
case 'apply':
const func = prettyPrint(ast.func, 0);
const args = ast.args.map(a => prettyPrint(a, 0)).join(' ');
const args = ast.args.map(a => {
const printed = prettyPrint(a, 0);
if (a.kind === 'lambda' || a.kind === 'match' || a.kind === 'let' || a.kind === 'rebind') {
return `(${printed})`;
}
return printed;
}).join(' ');
return `(${func} ${args})`
case 'let':

@ -32,6 +32,11 @@ filter = f list \ list
| True \ [x, ...filter f xs]
| False \ filter f xs);
# updateAt
updateAt = i f list \ mapWithIndex (x j \
(i == j | True \ f x | False \ x)
) list;
# fold : (b \ a \ b) \ b \ List a \ b
fold = f acc list \ list
| [] \ acc

@ -5,17 +5,29 @@ osState = {
windows = [],
wm = {
focusedIndex = 0,
scrollOffset = 0
scrollOffset = 0,
defaultWindowWidth = 800
},
nextId = 0
};
windowWidth = window \ window.fullWidth
| True \ viewport.width
| False \ window.width;
openWindow = title content \
id = osState.nextId;
batch [
osState.nextId := id + 1,
osState.windows := osState.windows & [{ id = id, title = title, content = content, width = 400 }],
osState.palette.visible := False
osState.windows := osState.windows & [{
id = id,
title = title,
content = content,
width = osState.wm.defaultWindowWidth,
fullWidth = False
}],
osState.palette.visible := False,
focusWindow id
];
closeWindowByIndex = i \
@ -28,7 +40,8 @@ closeWindowByIndex = i \
batch [
osState.windows := (take i osState.windows) & (drop (i + 1) osState.windows),
osState.wm.focusedIndex := min newFocused (len osState.windows - 2)
focusWindow newFocused
# osState.wm.focusedIndex := min newFocused (len osState.windows - 2)
];
closeFocusedWindow = _ \ closeWindowByIndex osState.wm.focusedIndex;
@ -37,12 +50,16 @@ closeWindowById = id \
i = index id (map (w \ w.id) osState.windows);
closeWindowByIndex (unwrapOr 0 i);
toggleMaximizeFocusedWindow = _ \
idx = osState.wm.focusedIndex;
osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows;
scrollToWindow = index \
windows = osState.windows;
widths = map (w \ w.width) windows;
widths = map windowWidth windows;
gap = 1;
windowX = (sum (take index widths)) + (index * gap);
windowW = unwrapOr 400 (nth index widths);
windowW = unwrapOr osState.wm.defaultWindowWidth (nth index widths);
scrollOffset = osState.wm.scrollOffset;
vw = viewport.width;
(windowX < scrollOffset
@ -66,10 +83,11 @@ onSelect = input \
renderWindow = window isActive \
titleBarHeight = 30;
ui.stack {
children = [
# background
ui.rect { w = window.width, h = viewport.height, color = (isActive | True \ "#0a2a3a" | False \ "#061820")},
ui.rect { w = (windowWidth window), h = viewport.height, color = (isActive | True \ "#0a2a3a" | False \ "#061820")},
# title bar
ui.positioned {
@ -77,7 +95,7 @@ renderWindow = window isActive \
child = ui.stack {
children = [
# background
ui.rect { w = window.width, h = titleBarHeight, color = (isActive | True \ "#a15f80" | False \ "#0f3348") },
ui.rect { w = (windowWidth window), h = titleBarHeight, color = (isActive | True \ "#a15f80" | False \ "#0f3348") },
ui.row {
children = [
# close button
@ -107,7 +125,7 @@ renderWindow = window isActive \
ui.positioned {
x = 0, y = titleBarHeight,
child = ui.clip {
w = window.width,
w = (windowWidth window),
h = viewport.height - titleBarHeight,
child = window.content
}
@ -161,6 +179,8 @@ os = ui.stateful {
)
| 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 \

Loading…
Cancel
Save