diff options
author | wlodekm <[email protected]> | 2024-11-15 09:46:47 +0200 |
---|---|---|
committer | wlodekm <[email protected]> | 2024-11-15 09:46:47 +0200 |
commit | d28d8333ebe71e2937660b13d9afb1d516cf14f0 (patch) | |
tree | 6c941712ec80b785a940b37aec52b2cea7861835 /screenbuilder.ts | |
parent | d51dbb974d83125f4bfb017188de6a013b7f746c (diff) |
v1.0.2
Diffstat (limited to 'screenbuilder.ts')
-rw-r--r-- | screenbuilder.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/screenbuilder.ts b/screenbuilder.ts new file mode 100644 index 0000000..98af374 --- /dev/null +++ b/screenbuilder.ts @@ -0,0 +1,44 @@ +// deno-lint-ignore-file no-explicit-any ban-ts-comment +import { Screen } from "./screen.ts"; +import * as elements from "./elements.ts"; + +export enum ElemType { + TextElem, + InputElem, + ButtonElem, + HR, + BR +} + +const types = { + 0: elements.Text, + 1: elements.Input, + 2: elements.Button, + 3: elements.HR, + 4: elements.BR +} + +type BuilderElem = { + type: ElemType, + id: string, + data?: any[], +} + +type Data = { + elements: BuilderElem[], + focus?: string, + name: string + onload?: (screen: Screen) => any +} + +export function build(data: Data) { + const screen = new Screen(data.name); + for (const element of data.elements) { + if (!element.data) element.data = [] + //@ts-ignore + screen.addElement(element.id, new types[element.type](...element.data)) + } + if (data.focus) screen.focus(data.focus); + screen.ready() + if (data.onload) data.onload(screen) +} \ No newline at end of file |