From da0556feab1e34e2de5b515c4d075603ef832b24 Mon Sep 17 00:00:00 2001
From: Kyle Gunger <kgunger12@gmail.com>
Date: Mon, 11 Nov 2024 23:27:59 -0500
Subject: Google fonts + thermostat widget

---
 scripts/gui-common/widgets.js | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

(limited to 'scripts/gui-common/widgets.js')

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
-- 
cgit v1.2.3