From 2e2fc30335254fc507867dd07da83f67285bd2af Mon Sep 17 00:00:00 2001 From: sn0w12 Date: Fri, 10 May 2024 23:00:21 +0200 Subject: [PATCH] add resizeNode --- web/simpleSamplerCustom.js | 49 ++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/web/simpleSamplerCustom.js b/web/simpleSamplerCustom.js index a795c3b..4a18779 100644 --- a/web/simpleSamplerCustom.js +++ b/web/simpleSamplerCustom.js @@ -26,20 +26,18 @@ app.registerExtension({ } } else if (slot === 5) { const initialCount = countWidgetsOfType(targetSlot.widgets, "converted-widget"); + const originalSize = [targetSlot.size[0], targetSlot.size[1]]; hideAllSchedulerWidgets(targetSlot); SettingUtils.hideWidget(targetSlot, findWidget(targetSlot, "scheduler_name")); - const finalCount = countWidgetsOfType(targetSlot.widgets, "converted-widget"); - targetSlot.size[0] = targetSlot.size[0]; - targetSlot.size[1] = targetSlot.size[1] + (initialCount - finalCount) * (70 / 3); + resizeNode(targetSlot, initialCount, originalSize); } else if (slot === 6) { const initialCount = countWidgetsOfType(targetSlot.widgets, "converted-widget"); + const originalSize = [targetSlot.size[0], targetSlot.size[1]]; hideAllLatentWidgets(targetSlot); - const finalCount = countWidgetsOfType(targetSlot.widgets, "converted-widget"); - targetSlot.size[0] = targetSlot.size[0]; - targetSlot.size[1] = targetSlot.size[1] + (initialCount - finalCount) * (70 / 3); + resizeNode(targetSlot, initialCount, originalSize); } onConnectInput?.apply(targetSlot, type, output, originNode, originSlot); @@ -51,7 +49,7 @@ app.registerExtension({ if (slot === 5) { if (this.inputs[slot].link === null) { const initialCount = countWidgetsOfType(this.widgets, "converted-widget"); - const originalSize = [this.size[0], this.size[1]] + const originalSize = [this.size[0], this.size[1]]; const schedulerWidget = findWidget(this, "scheduler_name"); showSchedulerInputs(this, schedulerWidget.value); @@ -59,20 +57,16 @@ app.registerExtension({ if (schedulerWidget.type === undefined) schedulerWidget.type = "combo"; - const finalCount = countWidgetsOfType(this.widgets, "converted-widget"); - this.size[0] = originalSize[0]; - this.size[1] = originalSize[1] + (initialCount - finalCount) * (70 / 3); + resizeNode(this, initialCount, originalSize); } } else if (slot === 6) { const initialCount = countWidgetsOfType(this.widgets, "converted-widget"); - const originalSize = [this.size[0], this.size[1]] + const originalSize = [this.size[0], this.size[1]]; if (this.inputs[slot].link === null) showAllLatentWidgets(this); - const finalCount = countWidgetsOfType(this.widgets, "converted-widget"); - this.size[0] = originalSize[0]; - this.size[1] = originalSize[1] + (initialCount - finalCount) * (70 / 3); + resizeNode(this, initialCount, originalSize); } onConnectionsChange?.apply(side, slot, connect, link_info, output); } @@ -159,6 +153,12 @@ app.registerExtension({ return widgets.filter(widget => widget.type === type).length; } + function resizeNode(node, initialCount, originalSize) { + const finalCount = countWidgetsOfType(node.widgets, "converted-widget"); + node.size[0] = originalSize[0]; + node.size[1] = originalSize[1] + (initialCount - finalCount) * (70 / 3); + } + function getWidgetOutputs(node, WidgetsToGet) { const widgets = node.widgets; @@ -222,13 +222,12 @@ app.registerExtension({ } function showSchedulerInputs(node, schedulerName, desiredWidgets = undefined) { - const originalWidth = node.size[0]; - const originalHeight = node.size[1]; - const originalWidgets = node.widgets; + const shouldResizeNode = !desiredWidgets; + const initialCount = countWidgetsOfType(node.widgets, "converted-widget"); + const originalSize = [node.size[0], node.size[1]]; const originalWidgetTypes = new Map(); - const resizeNode = !desiredWidgets; - for (const widget of originalWidgets) { + for (const widget of node.widgets) { originalWidgetTypes.set(widget.name, widget.type); } @@ -269,9 +268,8 @@ app.registerExtension({ } // Adjust the size based on widgets added/removed - if (resizeNode) { - node.size[0] = originalWidth; - node.size[1] = originalHeight + (addedWidgets - removedWidgets) * (70 / 3); + if (shouldResizeNode) { + resizeNode(node, initialCount, originalSize); } } @@ -331,14 +329,13 @@ app.registerExtension({ } } - const originalWidth = node.size[0]; - const originalHeight = node.size[1]; + const originalSize = [node.size[0], node.size[1]]; rearrangeWidgets(node, 8, 10); const nodesHidden = hideAllSchedulerWidgets(node); - node.size[0] = originalWidth; - node.size[1] = originalHeight + (-nodesHidden * (70 / 3)); + node.size[0] = originalSize[0]; + node.size[1] = originalSize[1] + (-nodesHidden * (70 / 3)); } } },