Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
142aac30
Commit
142aac30
authored
Oct 16, 2023
by
comfyanonymous
Browse files
Merge branch 'group-options' of
https://github.com/jn-jairo/ComfyUI
parents
bb064c97
682c84cc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
web/extensions/core/groupOptions.js
web/extensions/core/groupOptions.js
+83
-0
No files found.
web/extensions/core/groupOptions.js
View file @
142aac30
...
@@ -5,6 +5,61 @@ function setNodeMode(node, mode) {
...
@@ -5,6 +5,61 @@ 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
(
node
.
type
!=
"
Reroute
"
)
{
ny1
-=
LiteGraph
.
NODE_TITLE_HEIGHT
;
}
if
(
node
.
flags
?.
collapsed
)
{
ny2
=
ny1
+
LiteGraph
.
NODE_TITLE_HEIGHT
;
if
(
node
?.
_collapsed_width
)
{
nx2
=
nx1
+
Math
.
round
(
node
.
_collapsed_width
);
}
}
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
*
1.4
);
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 +69,17 @@ app.registerExtension({
...
@@ -14,6 +69,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
;
}
}
...
@@ -21,6 +87,15 @@ app.registerExtension({
...
@@ -21,6 +87,15 @@ app.registerExtension({
group
.
recomputeInsideNodes
();
group
.
recomputeInsideNodes
();
const
nodesInGroup
=
group
.
_nodes
;
const
nodesInGroup
=
group
.
_nodes
;
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
();
}
});
// No nodes in group, return default options
// No nodes in group, return default options
if
(
nodesInGroup
.
length
===
0
)
{
if
(
nodesInGroup
.
length
===
0
)
{
return
options
;
return
options
;
...
@@ -38,6 +113,14 @@ app.registerExtension({
...
@@ -38,6 +113,14 @@ app.registerExtension({
}
}
}
}
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
:
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment