mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 23:12:35 +08:00
Add Enum display_names;
This commit is contained in:
parent
bc76b3829f
commit
70c8d53c28
@ -9898,6 +9898,24 @@ LGraphNode.prototype.executeAction = function(action)
|
|||||||
if(values && values.constructor !== Array)
|
if(values && values.constructor !== Array)
|
||||||
v = values[ w.value ];
|
v = values[ w.value ];
|
||||||
}
|
}
|
||||||
|
if (w.options.display_names) {
|
||||||
|
var old_v = v;
|
||||||
|
var display_names = w.options.display_names;
|
||||||
|
if (display_names.constructor === Function)
|
||||||
|
display_names = display_names();
|
||||||
|
if (display_names && display_names.constructor === Array) {
|
||||||
|
// search from array
|
||||||
|
var values = w.options.values;
|
||||||
|
if (values.constructor === Function)
|
||||||
|
values = values();
|
||||||
|
var index = values.indexOf(w.value);
|
||||||
|
v = display_names[index];
|
||||||
|
} else if (display_names && display_names.hasOwnProperty(w.value)) {
|
||||||
|
// search from map
|
||||||
|
v = display_names[w.value];
|
||||||
|
}
|
||||||
|
v = v || old_v;
|
||||||
|
}
|
||||||
ctx.fillText(
|
ctx.fillText(
|
||||||
v,
|
v,
|
||||||
widget_width - margin * 2 - 20,
|
widget_width - margin * 2 - 20,
|
||||||
@ -10071,7 +10089,8 @@ LGraphNode.prototype.executeAction = function(action)
|
|||||||
scale: Math.max(1, this.ds.scale),
|
scale: Math.max(1, this.ds.scale),
|
||||||
event: event,
|
event: event,
|
||||||
className: "dark",
|
className: "dark",
|
||||||
callback: inner_clicked.bind(w)
|
callback: inner_clicked.bind(w),
|
||||||
|
widget: w
|
||||||
},
|
},
|
||||||
ref_window);
|
ref_window);
|
||||||
function inner_clicked(v, option, event) {
|
function inner_clicked(v, option, event) {
|
||||||
@ -13721,6 +13740,13 @@ LGraphNode.prototype.executeAction = function(action)
|
|||||||
if (name != null && name.constructor !== String) {
|
if (name != null && name.constructor !== String) {
|
||||||
name = name.content === undefined ? String(name) : name.content;
|
name = name.content === undefined ? String(name) : name.content;
|
||||||
}
|
}
|
||||||
|
if(options.widget?.options?.display_names){
|
||||||
|
var display_names = options.widget.options.display_names;
|
||||||
|
if(display_names.constructor === Array)
|
||||||
|
name = display_names[i];
|
||||||
|
else if(display_names.hasOwnProperty(name))
|
||||||
|
name = display_names[name];
|
||||||
|
}
|
||||||
var value = values[i];
|
var value = values[i];
|
||||||
this.addItem(name, value, options);
|
this.addItem(name, value, options);
|
||||||
num++;
|
num++;
|
||||||
|
|||||||
@ -308,10 +308,14 @@ export const ComfyWidgets = {
|
|||||||
COMBO(node, inputName, inputData) {
|
COMBO(node, inputName, inputData) {
|
||||||
const type = inputData[0];
|
const type = inputData[0];
|
||||||
let defaultValue = type[0];
|
let defaultValue = type[0];
|
||||||
|
let display_names = JSON.parse(JSON.stringify(type));
|
||||||
if (inputData[1] && inputData[1].default) {
|
if (inputData[1] && inputData[1].default) {
|
||||||
defaultValue = inputData[1].default;
|
defaultValue = inputData[1].default;
|
||||||
}
|
}
|
||||||
return { widget: node.addWidget("combo", inputName, defaultValue, () => {}, { values: type }) };
|
if (inputData[1] && inputData[1].display_names) {
|
||||||
|
display_names = inputData[1].display_names;
|
||||||
|
}
|
||||||
|
return { widget: node.addWidget("combo", inputName, defaultValue, () => {}, { values: type, display_names: display_names }) };
|
||||||
},
|
},
|
||||||
IMAGEUPLOAD(node, inputName, inputData, app) {
|
IMAGEUPLOAD(node, inputName, inputData, app) {
|
||||||
const imageWidget = node.widgets.find((w) => w.name === "image");
|
const imageWidget = node.widgets.find((w) => w.name === "image");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user