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);
}
}