Taking functions out of state so i can persist it
This commit is contained in:
parent
f7c3dff80f
commit
ae7ee9418b
1 changed files with 33 additions and 28 deletions
49
src/cg/os.cg
49
src/cg/os.cg
|
|
@ -3,16 +3,21 @@
|
||||||
osState = {
|
osState = {
|
||||||
palette = { visible = False },
|
palette = { visible = False },
|
||||||
windows = [],
|
windows = [],
|
||||||
blah = 53,
|
|
||||||
wm = {
|
wm = {
|
||||||
focusedIndex = 0,
|
focusedIndex = 0,
|
||||||
scrollOffset = 0,
|
scrollOffset = 0,
|
||||||
defaultWindowWidth = 800
|
defaultWindowWidth = 800
|
||||||
},
|
},
|
||||||
nextId = 6
|
nextId = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
paletteHistory = ["textEditor \"palette\"", "gt", "textEditor \"os\""];
|
paletteHistory = [
|
||||||
|
"textEditor \"osState\"",
|
||||||
|
"osState",
|
||||||
|
"textEditor \"palette\"",
|
||||||
|
"join",
|
||||||
|
"textEditor \"os\""
|
||||||
|
];
|
||||||
|
|
||||||
os = openPalette = _ \ osState.palette.visible := not osState.palette.visible;
|
os = openPalette = _ \ osState.palette.visible := not osState.palette.visible;
|
||||||
|
|
||||||
|
|
@ -41,14 +46,14 @@ focusWindow = index \ batch [
|
||||||
osState.wm.scrollOffset := scrollToWindow index
|
osState.wm.scrollOffset := scrollToWindow index
|
||||||
];
|
];
|
||||||
|
|
||||||
openWindow = title content width \
|
openWindow = title appExpr width \
|
||||||
id = osState.nextId;
|
id = osState.nextId;
|
||||||
batch [
|
batch [
|
||||||
osState.nextId := id + 1,
|
osState.nextId := id + 1,
|
||||||
osState.windows := osState.windows & [{
|
osState.windows := osState.windows & [{
|
||||||
id = id,
|
id = id,
|
||||||
title = title,
|
title = title,
|
||||||
content = content,
|
appExpr = appExpr,
|
||||||
width = width,
|
width = width,
|
||||||
fullWidth = False
|
fullWidth = False
|
||||||
}],
|
}],
|
||||||
|
|
@ -78,10 +83,10 @@ toggleMaximizeFocusedWindow = _ \
|
||||||
idx = osState.wm.focusedIndex;
|
idx = osState.wm.focusedIndex;
|
||||||
osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows;
|
osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows;
|
||||||
|
|
||||||
openOrFocus = title content width \
|
openOrFocus = title appExpr width \
|
||||||
index title (map (w \ w.title) osState.windows)
|
index title (map (w \ w.title) osState.windows)
|
||||||
| (Some i) \ focusWindow i
|
| (Some i) \ focusWindow i
|
||||||
| None \ openWindow title content width;
|
| None \ openWindow title appExpr width;
|
||||||
|
|
||||||
renderWindow = window isActive \
|
renderWindow = window isActive \
|
||||||
titleBarHeight = 36;
|
titleBarHeight = 36;
|
||||||
|
|
@ -130,12 +135,17 @@ renderWindow = window isActive \
|
||||||
child = ui.clip {
|
child = ui.clip {
|
||||||
w = windowWidth window,
|
w = windowWidth window,
|
||||||
h = viewport.height - titleBarHeight,
|
h = viewport.height - titleBarHeight,
|
||||||
child = window.content {
|
child = eval! window.appExpr
|
||||||
|
| (Value app) \ (hasField "view" app
|
||||||
|
| True \ app.view {
|
||||||
w = windowWidth window,
|
w = windowWidth window,
|
||||||
h = viewport.height - titleBarHeight,
|
h = viewport.height - titleBarHeight,
|
||||||
openApp = openOrFocus,
|
openApp = openOrFocus,
|
||||||
close = _ \ closeWindowById window.id
|
close = _ \ closeWindowById window.id
|
||||||
}
|
}
|
||||||
|
| False \ text (show app))
|
||||||
|
| (Err msg) \ text msg
|
||||||
|
| _ \ text "App not found"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
] };
|
] };
|
||||||
|
|
@ -187,23 +197,18 @@ search = q \
|
||||||
onSelect = input \
|
onSelect = input \
|
||||||
historyEvent = paletteHistory := take 50 [input, ...filter (e \ e != input) paletteHistory];
|
historyEvent = paletteHistory := take 50 [input, ...filter (e \ e != input) paletteHistory];
|
||||||
dw = osState.wm.defaultWindowWidth;
|
dw = osState.wm.defaultWindowWidth;
|
||||||
appWidth = app \
|
|
||||||
hasField "width" app
|
|
||||||
| True \ app.width
|
|
||||||
| false \ dw;
|
|
||||||
openEvent = eval! input
|
openEvent = eval! input
|
||||||
| (Defined name) \ (app = inspector { name = name };
|
| (Defined name) \ openOrFocus name input dw
|
||||||
openOrFocus name app.view (appWidth app))
|
| (Value v) \ (hasField "view" v
|
||||||
| (Value v) \ (hasField "_tag" v
|
| True \ openOrFocus input input (hasField "width" v
|
||||||
|
| True \ v.width
|
||||||
|
| False \ dw)
|
||||||
|
| False \ (hasField "_tag" v
|
||||||
| True \ batch [historyEvent, v]
|
| True \ batch [historyEvent, v]
|
||||||
| False \ (hasField "view" v
|
| False \ openOrFocus input input dw))
|
||||||
| True \ openOrFocus input v.view (appWidth v)
|
|
||||||
| False \ ((getSource input) == ""
|
|
||||||
| True \ openOrFocus input (_ \ renderText { content = show v, color = "white" }) dw
|
|
||||||
| False \ (app = inspector { name = input };
|
|
||||||
openOrFocus input app.view (appWidth app)))))
|
|
||||||
| (Err msg) \ (_ = debug! "OS Error" msg;
|
| (Err msg) \ (_ = debug! "OS Error" msg;
|
||||||
noOp);
|
noOp)
|
||||||
|
| _ \ noOp;
|
||||||
batch [historyEvent, openEvent];
|
batch [historyEvent, openEvent];
|
||||||
|
|
||||||
handleFocusLeftEvent = state \
|
handleFocusLeftEvent = state \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue