diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2024-11-11 23:27:59 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2024-11-11 23:27:59 -0500 |
commit | da0556feab1e34e2de5b515c4d075603ef832b24 (patch) | |
tree | 6bb4ff4b649953b57f78247f2719dddb1863dc85 /scripts | |
parent | eae67d80d41a6eaa0ac688c33ace802ecfa238c4 (diff) |
Google fonts + thermostat widget
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/gui-common/widgets.js | 38 | ||||
-rw-r--r-- | scripts/main.js | 4 |
2 files changed, 37 insertions, 5 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 diff --git a/scripts/main.js b/scripts/main.js index b86a956..ce0dfe4 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,3 +1,3 @@ -import { widget } from './gui-common/widgets.js'; +import * as w from './gui-common/widgets.js'; -widget();
\ No newline at end of file +let a = w.Widget(); |