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
61
src/cg/os.cg
61
src/cg/os.cg
|
|
@ -3,16 +3,21 @@
|
|||
osState = {
|
||||
palette = { visible = False },
|
||||
windows = [],
|
||||
blah = 53,
|
||||
wm = {
|
||||
focusedIndex = 0,
|
||||
scrollOffset = 0,
|
||||
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;
|
||||
|
||||
|
|
@ -41,14 +46,14 @@ focusWindow = index \ batch [
|
|||
osState.wm.scrollOffset := scrollToWindow index
|
||||
];
|
||||
|
||||
openWindow = title content width \
|
||||
openWindow = title appExpr width \
|
||||
id = osState.nextId;
|
||||
batch [
|
||||
osState.nextId := id + 1,
|
||||
osState.windows := osState.windows & [{
|
||||
id = id,
|
||||
title = title,
|
||||
content = content,
|
||||
appExpr = appExpr,
|
||||
width = width,
|
||||
fullWidth = False
|
||||
}],
|
||||
|
|
@ -78,10 +83,10 @@ toggleMaximizeFocusedWindow = _ \
|
|||
idx = osState.wm.focusedIndex;
|
||||
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)
|
||||
| (Some i) \ focusWindow i
|
||||
| None \ openWindow title content width;
|
||||
| None \ openWindow title appExpr width;
|
||||
|
||||
renderWindow = window isActive \
|
||||
titleBarHeight = 36;
|
||||
|
|
@ -130,12 +135,17 @@ renderWindow = window isActive \
|
|||
child = ui.clip {
|
||||
w = windowWidth window,
|
||||
h = viewport.height - titleBarHeight,
|
||||
child = window.content {
|
||||
w = windowWidth window,
|
||||
h = viewport.height - titleBarHeight,
|
||||
openApp = openOrFocus,
|
||||
close = _ \ closeWindowById window.id
|
||||
}
|
||||
child = eval! window.appExpr
|
||||
| (Value app) \ (hasField "view" app
|
||||
| True \ app.view {
|
||||
w = windowWidth window,
|
||||
h = viewport.height - titleBarHeight,
|
||||
openApp = openOrFocus,
|
||||
close = _ \ closeWindowById window.id
|
||||
}
|
||||
| False \ text (show app))
|
||||
| (Err msg) \ text msg
|
||||
| _ \ text "App not found"
|
||||
}
|
||||
}
|
||||
] };
|
||||
|
|
@ -187,23 +197,18 @@ search = q \
|
|||
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))
|
||||
| (Value v) \ (hasField "_tag" v
|
||||
| True \ batch [historyEvent, v]
|
||||
| False \ (hasField "view" v
|
||||
| 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)))))
|
||||
| (Defined name) \ openOrFocus name input dw
|
||||
| (Value v) \ (hasField "view" v
|
||||
| True \ openOrFocus input input (hasField "width" v
|
||||
| True \ v.width
|
||||
| False \ dw)
|
||||
| False \ (hasField "_tag" v
|
||||
| True \ batch [historyEvent, v]
|
||||
| False \ openOrFocus input input dw))
|
||||
| (Err msg) \ (_ = debug! "OS Error" msg;
|
||||
noOp);
|
||||
noOp)
|
||||
| _ \ noOp;
|
||||
batch [historyEvent, openEvent];
|
||||
|
||||
handleFocusLeftEvent = state \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue