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

Loading…
Cancel
Save