"comfy/git@developer.sourcefind.cn:chenpangpang/ComfyUI.git" did not exist on "89507f8adff4aff4507b6f35a67717badaecd4ac"
Commit 7e51bbd0 authored by pythongosssss's avatar pythongosssss
Browse files

automatic calculation of image pos from widgets

parent fcf513e0
......@@ -263,6 +263,34 @@ export class ComfyApp {
*/
#addDrawBackgroundHandler(node) {
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) {
if (!this.flags.collapsed) {
const output = app.nodeOutputs[this.id + ""];
......@@ -283,9 +311,7 @@ export class ComfyApp {
).then((imgs) => {
if (this.images === output.images) {
this.imgs = imgs.filter(Boolean);
if (this.size[1] < 100) {
this.size[1] = 250;
}
this.setSizeForImage?.();
app.graph.setDirtyCanvas(true);
}
});
......@@ -310,12 +336,7 @@ export class ComfyApp {
this.imageIndex = imageIndex = 0;
}
let shiftY;
if (this.imageOffset != null) {
shiftY = this.imageOffset;
} else {
shiftY = this.computeSize()[1];
}
const shiftY = getImageTop(this);
let dw = this.size[0];
let dh = this.size[1];
......
......@@ -261,20 +261,13 @@ export const ComfyWidgets = {
let uploadWidget;
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();
img.onload = () => {
node.imgs = [img];
app.graph.setDirtyCanvas(true);
};
img.src = `/view?filename=${name}&type=input`;
if ((node.size[1] - node.imageOffset) < 100) {
node.size[1] = 250 + node.imageOffset;
}
node.setSizeForImage?.();
}
// Add our own callback to the combo widget to render an image when it changes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment