mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-11 02:15:17 +00:00
Group options
- Add Group For Selected Nodes - Add Selected Nodes To Group - Fit Group To Nodes
This commit is contained in:
parent
7e09e889e3
commit
7d5d0fd577
@ -5,6 +5,49 @@ function setNodeMode(node, mode) {
|
|||||||
node.graph.change();
|
node.graph.change();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addNodesToGroup(group, nodes=[]) {
|
||||||
|
var x1, y1, x2, y2;
|
||||||
|
var nx1, ny1, nx2, ny2;
|
||||||
|
var node;
|
||||||
|
|
||||||
|
x1 = y1 = x2 = y2 = -1;
|
||||||
|
nx1 = ny1 = nx2 = ny2 = -1;
|
||||||
|
|
||||||
|
for (var n of [group._nodes, nodes]) {
|
||||||
|
for (var i in n) {
|
||||||
|
node = n[i]
|
||||||
|
|
||||||
|
nx1 = node.pos[0]
|
||||||
|
ny1 = node.pos[1]
|
||||||
|
nx2 = node.pos[0] + node.size[0]
|
||||||
|
ny2 = node.pos[1] + node.size[1]
|
||||||
|
|
||||||
|
if (x1 == -1 || nx1 < x1) {
|
||||||
|
x1 = nx1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y1 == -1 || ny1 < y1) {
|
||||||
|
y1 = ny1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x2 == -1 || nx2 > x2) {
|
||||||
|
x2 = nx2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y2 == -1 || ny2 > y2) {
|
||||||
|
y2 = ny2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var padding = 10;
|
||||||
|
|
||||||
|
y1 = y1 - Math.round(group.font_size * 2.7);
|
||||||
|
|
||||||
|
group.pos = [x1 - padding, y1 - padding];
|
||||||
|
group.size = [x2 - x1 + padding * 2, y2 - y1 + padding * 2];
|
||||||
|
}
|
||||||
|
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "Comfy.GroupOptions",
|
name: "Comfy.GroupOptions",
|
||||||
setup() {
|
setup() {
|
||||||
@ -14,6 +57,17 @@ app.registerExtension({
|
|||||||
const options = orig.apply(this, arguments);
|
const options = orig.apply(this, arguments);
|
||||||
const group = this.graph.getGroupOnPos(this.graph_mouse[0], this.graph_mouse[1]);
|
const group = this.graph.getGroupOnPos(this.graph_mouse[0], this.graph_mouse[1]);
|
||||||
if (!group) {
|
if (!group) {
|
||||||
|
options.push({
|
||||||
|
content: "Add Group For Selected Nodes",
|
||||||
|
disabled: !Object.keys(app.canvas.selected_nodes || {}).length,
|
||||||
|
callback: () => {
|
||||||
|
var group = new LiteGraph.LGraphGroup();
|
||||||
|
addNodesToGroup(group, this.selected_nodes)
|
||||||
|
app.canvas.graph.add(group);
|
||||||
|
this.graph.change();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +92,23 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.push({
|
||||||
|
content: "Add Selected Nodes To Group",
|
||||||
|
disabled: !Object.keys(app.canvas.selected_nodes || {}).length,
|
||||||
|
callback: () => {
|
||||||
|
addNodesToGroup(group, this.selected_nodes)
|
||||||
|
this.graph.change();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
options.push({
|
||||||
|
content: "Fit Group To Nodes",
|
||||||
|
callback: () => {
|
||||||
|
addNodesToGroup(group)
|
||||||
|
this.graph.change();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
options.push({
|
options.push({
|
||||||
content: "Select Nodes",
|
content: "Select Nodes",
|
||||||
callback: () => {
|
callback: () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user