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
13d94caf
Commit
13d94caf
authored
May 16, 2023
by
comfyanonymous
Browse files
Add control_after_generate to combo primitive.
parent
5f7968f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
29 deletions
+55
-29
web/extensions/core/widgetInputs.js
web/extensions/core/widgetInputs.js
+1
-1
web/scripts/widgets.js
web/scripts/widgets.js
+54
-28
No files found.
web/extensions/core/widgetInputs.js
View file @
13d94caf
...
...
@@ -300,7 +300,7 @@ app.registerExtension({
}
}
if
(
widget
.
type
===
"
number
"
)
{
if
(
widget
.
type
===
"
number
"
||
widget
.
type
===
"
combo
"
)
{
addValueControlWidget
(
this
,
widget
,
"
fixed
"
);
}
...
...
web/scripts/widgets.js
View file @
13d94caf
...
...
@@ -19,35 +19,61 @@ export function addValueControlWidget(node, targetWidget, defaultValue = "random
var
v
=
valueControl
.
value
;
let
min
=
targetWidget
.
options
.
min
;
let
max
=
targetWidget
.
options
.
max
;
// limit to something that javascript can handle
max
=
Math
.
min
(
1125899906842624
,
max
);
min
=
Math
.
max
(
-
1125899906842624
,
min
);
let
range
=
(
max
-
min
)
/
(
targetWidget
.
options
.
step
/
10
);
//adjust values based on valueControl Behaviour
switch
(
v
)
{
case
"
fixed
"
:
break
;
case
"
increment
"
:
targetWidget
.
value
+=
targetWidget
.
options
.
step
/
10
;
break
;
case
"
decrement
"
:
targetWidget
.
value
-=
targetWidget
.
options
.
step
/
10
;
break
;
case
"
randomize
"
:
targetWidget
.
value
=
Math
.
floor
(
Math
.
random
()
*
range
)
*
(
targetWidget
.
options
.
step
/
10
)
+
min
;
default
:
break
;
}
/*check if values are over or under their respective
* ranges and set them to min or max.*/
if
(
targetWidget
.
value
<
min
)
targetWidget
.
value
=
min
;
console
.
log
(
targetWidget
);
if
(
targetWidget
.
type
==
"
combo
"
&&
v
!==
"
fixed
"
)
{
let
current_index
=
targetWidget
.
options
.
values
.
indexOf
(
targetWidget
.
value
);
let
current_length
=
targetWidget
.
options
.
values
.
length
;
switch
(
v
)
{
case
"
increment
"
:
current_index
+=
1
;
break
;
case
"
decrement
"
:
current_index
-=
1
;
break
;
case
"
randomize
"
:
current_index
=
Math
.
floor
(
Math
.
random
()
*
current_length
);
default
:
break
;
}
current_index
=
Math
.
max
(
0
,
current_index
);
current_index
=
Math
.
min
(
current_length
-
1
,
current_index
);
if
(
current_index
>=
0
)
{
let
value
=
targetWidget
.
options
.
values
[
current_index
];
targetWidget
.
value
=
value
;
targetWidget
.
callback
(
value
);
}
}
else
{
//number
let
min
=
targetWidget
.
options
.
min
;
let
max
=
targetWidget
.
options
.
max
;
// limit to something that javascript can handle
max
=
Math
.
min
(
1125899906842624
,
max
);
min
=
Math
.
max
(
-
1125899906842624
,
min
);
let
range
=
(
max
-
min
)
/
(
targetWidget
.
options
.
step
/
10
);
//adjust values based on valueControl Behaviour
switch
(
v
)
{
case
"
fixed
"
:
break
;
case
"
increment
"
:
targetWidget
.
value
+=
targetWidget
.
options
.
step
/
10
;
break
;
case
"
decrement
"
:
targetWidget
.
value
-=
targetWidget
.
options
.
step
/
10
;
break
;
case
"
randomize
"
:
targetWidget
.
value
=
Math
.
floor
(
Math
.
random
()
*
range
)
*
(
targetWidget
.
options
.
step
/
10
)
+
min
;
default
:
break
;
}
/*check if values are over or under their respective
* ranges and set them to min or max.*/
if
(
targetWidget
.
value
<
min
)
targetWidget
.
value
=
min
;
if
(
targetWidget
.
value
>
max
)
targetWidget
.
value
=
max
;
if
(
targetWidget
.
value
>
max
)
targetWidget
.
value
=
max
;
}
}
return
valueControl
;
};
...
...
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