From 5610657a5644137794354d68c3c0cca48293239d Mon Sep 17 00:00:00 2001 From: Austin Mroz Date: Fri, 25 Oct 2024 03:01:47 -0500 Subject: [PATCH] Update autosizing js Allow for autosizing to be configured by setting a hidden field instead of dummy widget. If autosizing isn't specified for a node, instead set the initial width to the greater of the title length, or the original base node width used by ComfyUI --- web/js/autosize.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/web/js/autosize.js b/web/js/autosize.js index dcf4559..905c442 100644 --- a/web/js/autosize.js +++ b/web/js/autosize.js @@ -1,6 +1,34 @@ import { app } from '../../../scripts/app.js' + +function addResizeHook(node, padding, useOldMin=false) { + let origOnCreated = node.onNodeCreated + node.onNodeCreated = function() { + let r = origOnCreated?.apply(this, arguments) + let size = this.computeSize(); + size[0] += padding || 0; + if (useOldMin) { + //equal to LiteGraph.NODE_WIDTH*1.5*1.5 + size[0] = Math.max(size[0], 315) + } + this.setSize(size); + return r + } +} + app.registerExtension({ name: "AdvancedControlNet.autosize", + async beforeRegisterNodeDef(nodeType, nodeData, app) { + //since python_module is based off folder path, + //it could be changed by users and should only be used as fallback + if (nodeData?.name?.startsWith("ACN_") + || nodeData.python_module == 'custom_nodes.ComfyUI-Advanced-ControlNet') { + if (nodeData?.input?.hidden?.autosize) { + addResizeHook(nodeType.prototype, nodeData.input.hidden.autosize[1]?.padding) + } else if (!nodeData?.input?.optional?.autosize) { + addResizeHook(nodeType.prototype, 0, true) + } + } + }, async getCustomWidgets() { return { ACNAUTOSIZE(node, inputName, inputData) { @@ -17,14 +45,7 @@ app.registerExtension({ node.widgets = [] } node.widgets.push(w) - let origOnCreated = node.onNodeCreated - node.onNodeCreated = function() { - let r = origOnCreated?.apply(this, arguments) - let size = this.computeSize(); - size[0] += inputData[1].padding || 0; - this.setSize(size); - return r - } + addResizeHook(node, inputData[1].padding); return w; } }