Browse Source

Support numeric settings, tooltip, extra attrs

pull/361/head
pythongosssss 2 years ago
parent
commit
5aefd6cdf3
  1. 42
      web/scripts/ui.js

42
web/scripts/ui.js

@ -198,7 +198,7 @@ class ComfySettingsDialog extends ComfyDialog {
localStorage[settingId] = JSON.stringify(value);
}
addSetting({ id, name, type, defaultValue, onChange }) {
addSetting({ id, name, type, defaultValue, onChange, attrs = {}, tooltip = "", }) {
if (!id) {
throw new Error("Settings must have an ID");
}
@ -225,13 +225,14 @@ class ComfySettingsDialog extends ComfyDialog {
value = v;
};
if (typeof type === "function") {
return type(name, setter, value);
}
let element;
if (typeof type === "function") {
element = type(name, setter, value, attrs);
} else {
switch (type) {
case "boolean":
return $el("div", [
element = $el("div", [
$el("label", { textContent: name || id }, [
$el("input", {
type: "checkbox",
@ -239,28 +240,57 @@ class ComfySettingsDialog extends ComfyDialog {
oninput: (e) => {
setter(e.target.checked);
},
...attrs
}),
]),
]);
break;
case "number":
element = $el("div", [
$el("label", { textContent: name || id }, [
$el("input", {
type,
value,
oninput: (e) => {
setter(e.target.value);
},
...attrs
}),
]),
]);
break;
default:
console.warn("Unsupported setting type, defaulting to text");
return $el("div", [
element = $el("div", [
$el("label", { textContent: name || id }, [
$el("input", {
value,
oninput: (e) => {
setter(e.target.value);
},
...attrs
}),
]),
]);
break;
}
}
if(tooltip) {
element.title = tooltip;
}
return element;
},
});
}
show() {
super.show();
Object.assign(this.textElement.style, {
display: "flex",
flexDirection: "column",
gap: "10px"
});
this.textElement.replaceChildren(...this.settings.map((s) => s.render()));
}
}

Loading…
Cancel
Save