From da0556feab1e34e2de5b515c4d075603ef832b24 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 11 Nov 2024 23:27:59 -0500 Subject: Google fonts + thermostat widget --- scripts/gui-common/widgets.js | 38 +++++++++++++++++++++++++++++++++++--- scripts/main.js | 4 ++-- 2 files changed, 37 insertions(+), 5 deletions(-) (limited to 'scripts') 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 + * @template {any} T + */ + +/** + * @typedef {"button" | "toggle" | "slider" | "checkbox"} WidgetType + */ + +/** + * @template {any} T + * @param {WidgetType} type + * @returns {Widget} + */ +function Widget (type = "button") { + /** @type {Widget} */ + 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(); -- cgit v1.2.3