mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-11 02:15:17 +00:00
automatic calculation of image pos from widgets
This commit is contained in:
parent
fcf513e0b6
commit
7e51bbd07f
@ -263,6 +263,34 @@ export class ComfyApp {
|
|||||||
*/
|
*/
|
||||||
#addDrawBackgroundHandler(node) {
|
#addDrawBackgroundHandler(node) {
|
||||||
const app = this;
|
const app = this;
|
||||||
|
|
||||||
|
function getImageTop(node) {
|
||||||
|
let shiftY;
|
||||||
|
if (node.imageOffset != null) {
|
||||||
|
shiftY = node.imageOffset;
|
||||||
|
} else {
|
||||||
|
if (node.widgets?.length) {
|
||||||
|
const w = node.widgets[node.widgets.length - 1];
|
||||||
|
shiftY = w.last_y;
|
||||||
|
if (w.computeSize) {
|
||||||
|
shiftY += w.computeSize()[1] + 4;
|
||||||
|
} else {
|
||||||
|
shiftY += LiteGraph.NODE_WIDGET_HEIGHT + 4;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shiftY = node.computeSize()[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shiftY;
|
||||||
|
}
|
||||||
|
|
||||||
|
node.prototype.setSizeForImage = function () {
|
||||||
|
const minHeight = getImageTop(this) + 220;
|
||||||
|
if (this.size[1] < minHeight) {
|
||||||
|
this.setSize([this.size[0], minHeight]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
node.prototype.onDrawBackground = function (ctx) {
|
node.prototype.onDrawBackground = function (ctx) {
|
||||||
if (!this.flags.collapsed) {
|
if (!this.flags.collapsed) {
|
||||||
const output = app.nodeOutputs[this.id + ""];
|
const output = app.nodeOutputs[this.id + ""];
|
||||||
@ -283,9 +311,7 @@ export class ComfyApp {
|
|||||||
).then((imgs) => {
|
).then((imgs) => {
|
||||||
if (this.images === output.images) {
|
if (this.images === output.images) {
|
||||||
this.imgs = imgs.filter(Boolean);
|
this.imgs = imgs.filter(Boolean);
|
||||||
if (this.size[1] < 100) {
|
this.setSizeForImage?.();
|
||||||
this.size[1] = 250;
|
|
||||||
}
|
|
||||||
app.graph.setDirtyCanvas(true);
|
app.graph.setDirtyCanvas(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -310,12 +336,7 @@ export class ComfyApp {
|
|||||||
this.imageIndex = imageIndex = 0;
|
this.imageIndex = imageIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let shiftY;
|
const shiftY = getImageTop(this);
|
||||||
if (this.imageOffset != null) {
|
|
||||||
shiftY = this.imageOffset;
|
|
||||||
} else {
|
|
||||||
shiftY = this.computeSize()[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
let dw = this.size[0];
|
let dw = this.size[0];
|
||||||
let dh = this.size[1];
|
let dh = this.size[1];
|
||||||
|
@ -261,20 +261,13 @@ export const ComfyWidgets = {
|
|||||||
let uploadWidget;
|
let uploadWidget;
|
||||||
|
|
||||||
function showImage(name) {
|
function showImage(name) {
|
||||||
// Position the image somewhere sensible
|
|
||||||
if (!node.imageOffset) {
|
|
||||||
node.imageOffset = uploadWidget.last_y ? uploadWidget.last_y + 25 : 75;
|
|
||||||
}
|
|
||||||
|
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
node.imgs = [img];
|
node.imgs = [img];
|
||||||
app.graph.setDirtyCanvas(true);
|
app.graph.setDirtyCanvas(true);
|
||||||
};
|
};
|
||||||
img.src = `/view?filename=${name}&type=input`;
|
img.src = `/view?filename=${name}&type=input`;
|
||||||
if ((node.size[1] - node.imageOffset) < 100) {
|
node.setSizeForImage?.();
|
||||||
node.size[1] = 250 + node.imageOffset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add our own callback to the combo widget to render an image when it changes
|
// Add our own callback to the combo widget to render an image when it changes
|
||||||
|
Loading…
Reference in New Issue
Block a user