ts-ui-test/src/ui/view-manager.ts

36 lines
971 B
TypeScript
Raw Normal View History

2023-05-02 16:44:10 +00:00
import { UIWindow } from "./window";
export class ViewManager {
private currentWindow: UIWindow;
private windows: UIWindow[];
private viewElement: HTMLDivElement;
public constructor() {
this.windows = [];
this.viewElement = document.createElement("div");
}
public add(window: UIWindow) {
this.windows.push(window);
window.onConnect();
this.viewElement.appendChild(window.show());
}
public remove(window: UIWindow) {
this.windows.splice(this.windows.indexOf(window), 1);
window.onDisconnect();
this.viewElement.removeChild(window.show());
}
public switchTo(window: UIWindow) {
if (this.currentWindow !== undefined) {
this.currentWindow.onDisconnect();
}
this.currentWindow = window;
this.currentWindow.onConnect();
}
public render() {
return this.viewElement;
}
}