浏览代码

Add arrangeAll (thanks mamuesp, from #141)

dds
PaulStoffregen 9 年前
父节点
当前提交
ad5eeb150c
共有 2 个文件被更改,包括 64 次插入2 次删除
  1. +1
    -1
      gui/red/nodes.js
  2. +63
    -1
      gui/red/ui/view.js

+ 1
- 1
gui/red/nodes.js 查看文件

@@ -487,7 +487,7 @@ RED.nodes = (function() {
}

// ... and it has to end with an semikolon ...
var pattSe = new RegExp(/.*;$/);
var pattSe = new RegExp(/.*;.*$/);
var pattCoord = new RegExp(/.*\/\/xy=\d+,\d+$/);
if (pattSe.test(line) || pattCoord.test(line)) {
var word = parts[1].trim();

+ 63
- 1
gui/red/ui/view.js 查看文件

@@ -1454,8 +1454,70 @@ RED.view = (function() {
}
}

function doSort (arr) {
arr.sort(function (a, b) {
var nameA = a.name ? a.name : a.id;
var nameB = b.name ? b.name : b.id;
return nameA.localeCompare(nameB, 'en', {numeric: 'true'});
});
}

function setNewCoords (lastX, lastY, arr) {
var x = lastX;
var y = lastY;
for (var i = 0; i < arr.length; i++) {
var node = arr[i];
var name = node.name ? node.name : node.id;
var def = node._def;
var dH = Math.max(RED.view.defaults.height, (Math.max(def.outputs, def.inputs) || 0) * 15);
x = lastX + Math.max(RED.view.defaults.width, RED.view.calculateTextWidth(name) + (def.inputs > 0 ? 7 : 0));
node.x = x;
node.y = y + dH/2;
y = y + dH + 15;
node.dirty = true;
}
return { x: x, y: y };
}

function arrangeAll() {
// TODO: arrange imported nodes without coordinates
var ioNoIn = [];
var ioInOut = [];
var ioMultiple = [];
var ioNoOut = [];
var ioCtrl = [];

RED.nodes.eachNode(function (node) {

if (node._def.inputs == 0 && node._def.outputs == 0) {
ioCtrl.push(node);
} else if (node._def.inputs == 0) {
ioNoIn.push(node);
} else if (node._def.outputs == 0) {
ioNoOut.push(node);
} else if (node._def.inputs == 1 && node._def.outputs == 1) {
ioInOut.push(node);
} else if (node._def.inputs > 1) {
ioMultiple.push(node);
}
});

var cols = new Array(ioNoIn, ioInOut, ioMultiple, ioNoOut, ioCtrl);
var lowestY = 0;

for (var i = 0; i < cols.length; i++) {
var dX = ((i < cols.length - 1) ? i : 0) * (RED.view.defaults.width * 2) + (RED.view.defaults.width / 2) + 15;
var dY = ((i < cols.length - 1) ? (RED.view.defaults.height / 4) : lowestY) + 15;
var startX = 0;
var startY = 0;

doSort(cols[i]);
var last = setNewCoords(startX + dX, startY + dY, cols[i]);
lowestY = Math.max(lowestY, last.y);
startX = ((i < cols.length - 1) ? last.x : 0) + (RED.view.defaults.width) * 4;
startY = lowestY + (RED.view.defaults.height * 1.5);
}
RED.storage.update();
redraw();
}

RED.keyboard.add(/* z */ 90,{ctrl:true},function(){RED.history.pop();});

正在加载...
取消
保存