From ffac0814ceaf358db072f702e61be7dbff44e4c6 Mon Sep 17 00:00:00 2001 From: Tenney Date: Fri, 9 May 2025 12:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=BD=E5=BA=A6=E5=AF=B9?= =?UTF-8?q?=E9=BD=90=E4=BB=A5=E6=9C=80=E5=B0=8F=E5=80=BC=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4=E5=AE=BD=E5=BA=A6=E6=97=B6=E5=80=BC?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E6=95=B4=E6=95=B0=E4=BD=8D=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?5=E7=9A=84=E5=80=8D=E6=95=B0=E5=9B=9B=E8=88=8D=E4=BA=94?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_info.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/node_info.js b/node_info.js index cc5e873..1424e9c 100644 --- a/node_info.js +++ b/node_info.js @@ -7,7 +7,9 @@ const alignTopSvg = ``; const verticalDistributionSvg = ``; const equalWidthSvg = `` +const equalWidth2Svg = `` const equalHeightSvg = `` +const equalHeight2Svg = `` const ButtonManager = { isInitialized: false, // 检查是否已经初始化 @@ -257,8 +259,10 @@ const ButtonManager = { { type: 'divider' }, /* 等宽 */ { id: 'equalWidth', svg: equalWidthSvg, action: this.equalWidth.bind(this) }, + { id: 'equalMinWidth', svg: equalWidth2Svg, action: this.equalMinWidth.bind(this) }, /* 等高 */ { id: 'equalHeight', svg: equalHeightSvg, action: this.equalHeight.bind(this) }, + { id: 'equalMinHeight', svg: equalHeight2Svg, action: this.equalMinHeight.bind(this) }, ]; }, // 显示右键菜单 @@ -737,25 +741,39 @@ const ButtonManager = { LGraphCanvas.active_canvas.setDirty(true, true); } }, - // 等宽 + // 等宽 对齐最大值 equalWidth() { this.equalSize(0); }, + // 等宽 对齐最小值 + equalMinWidth() { + this.equalSize(0, Math.min); + }, // 等高 equalHeight() { this.equalSize(1); + },// 等高 对齐最小值 + equalMinHeight() { + this.equalSize(1, Math.min); }, + // 通用的节点尺寸调整 - equalSize(axis) { + equalSize(axis, comparator = Math.max) { const nodes = this.getSelectedNodes(); if (nodes.length > 0) { - // 找到节点中最大的尺寸 - const maxSize = Math.max(...nodes.map(node => node.size[axis])); + // 使用传入的比较函数(默认为 Math.max) + const sizeValues = nodes.map(node => node.size[axis]); + const targetSize = comparator(...sizeValues); + + // 将尺寸调整为最近的5的倍数 + const roundedTargetSize = Math.round(targetSize / 5) * 5; + nodes.forEach(node => { - node.size[axis] = maxSize; // 设置所有节点的大小为最大值 + node.size[axis] = roundedTargetSize; // 设置所有节点的大小为目标值(5的倍数) }); + LGraphCanvas.active_canvas.setDirty(true, true); } }