HomeContext new ui system

This commit is contained in:
Djeeberjr 2023-02-05 02:56:18 +01:00
parent a4e4e103bd
commit b0be0ba8b4

View File

@ -1,6 +1,8 @@
package lib;
import lib.ui.rendere.List;
import lib.ui.elements.UIElement;
import lib.ui.elements.TextElement;
import lib.ui.elements.RootElement;
import kernel.KernelEvents;
import bin.Terminal;
import kernel.ui.WindowManager;
@ -11,40 +13,24 @@ import kernel.ui.WindowContext;
Listens to global hotkey "POS1"/"HOME" to switch back to this context.
**/
class HomeContext {
private static final MAX_CONTEXT:Int = 10;
private static inline final MAX_CONTEXT:Int = 10;
private var ctx:WindowContext = null;
private final workspaces:Map<Int, WindowContext> = [];
private var currentWorkspace:Int = -1;
private var listRenderer: List;
private var renderer:RootElement;
public function new() {
}
public function new() {}
public function run() {
// Create main terminal context
ctx = WindowManager.instance.createNewContext();
WindowManager.instance.focusContextToOutput(ctx, "main");
// Setup renderer and event handlers for main terminal
listRenderer = new List((i)->{
if (workspaces[i] != null) {
focusContext(i);
}else {
var newContext = WindowManager.instance.createNewContext();
renderer = new RootElement();
// Create new terminal
var term = new Terminal();
term.invoke(newContext);
addContextToWorkspace(newContext,i);
focusContext(i);
}
});
ctx.delegateEvents(listRenderer);
ctx.delegateEvents(renderer);
render();
// Register global key bindings to react to main terminal
@ -90,12 +76,34 @@ class HomeContext {
currentWorkspace = -1;
}
private function handleSelectContext(contextId:Int) {
if (workspaces[contextId] != null) {
focusContext(contextId);
} else {
var newContext = WindowManager.instance.createNewContext();
// Create new terminal
var term = new Terminal();
term.invoke(newContext);
addContextToWorkspace(newContext, contextId);
focusContext(contextId);
}
}
private function render() {
ctx.clear();
ctx.setCursorPos(0,0);
var list = [for (i in 0...MAX_CONTEXT) workspaces.exists(i) ? 'Switch to context ${i}' : 'Create new Terminal on context ${i}'];
var list = [
for (i in 0...MAX_CONTEXT) workspaces.exists(i) ? 'Switch to context ${i}' : 'Create new Terminal on context ${i}'
];
listRenderer.render(list).renderToContext(ctx);
var children:Array<UIElement> = [
for (i => line in list) new TextElement(line, {onClick: this.handleSelectContext.bind(i)})
];
renderer.setChildren(children);
renderer.render().renderToContext(ctx);
}
}