diff options
Diffstat (limited to 'scripts/gui-common/widgets.js')
-rw-r--r-- | scripts/gui-common/widgets.js | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/scripts/gui-common/widgets.js b/scripts/gui-common/widgets.js index 28efe7f..e365f56 100644 --- a/scripts/gui-common/widgets.js +++ b/scripts/gui-common/widgets.js @@ -1,5 +1,37 @@ -function widget() { - console.log("widgets!"); +/** + * @typedef {{ + * el: HTMLElement; + * value: T; + * set: (value: T) => void; + * get: () => T}} Widget<T> + * @template {any} T + */ + +/** + * @typedef {"button" | "toggle" | "slider" | "checkbox"} WidgetType + */ + +/** + * @template {any} T + * @param {WidgetType} type + * @returns {Widget<T>} + */ +function Widget (type = "button") { + /** @type {Widget<Number>} */ + let out = { + el: document.createElement("div"), + value: 0, + set: (e) => {value = e}, + get: () => this.value, + }; + + out.el.classList = ["widget", type]; + if (type == "checkbox" || type == "toggle") + { + out.el.classList.add("button"); + } + + return out; } -export { widget };
\ No newline at end of file +export { Widget };
\ No newline at end of file |