Enable autosize by widget instead of namespace.

Also adds a padding option which, if supplied is summed with the
calculated width when auto-sizing is applied.
This commit is contained in:
Austin Mroz
2024-07-10 22:05:50 -05:00
parent 8b86f64908
commit 7a8415b560
2 changed files with 26 additions and 8 deletions
+1
View File
@@ -298,6 +298,7 @@ class CustomCFGKeyframeSimpleNode:
"optional": {
"prev_custom_cfg": ("CUSTOM_CFG",),
"cfg_extras": ("CFG_EXTRAS",),
"autosize": ("ADEAUTOSIZE", {"padding": 10}),
}
}
+25 -8
View File
@@ -1,14 +1,31 @@
import { app } from '../../../scripts/app.js'
app.registerExtension({
name: "AnimateDiffEvolved.autosize",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if(nodeData?.name?.startsWith("ADE_") ||
nodeData?.name?.startsWith("ACN_")) {
let origOnCreated = nodeType.prototype.onNodeCreated
nodeType.prototype.onNodeCreated = function() {
const r = origOnCreated ? origOnCreated.apply(this) : undefined;
this.setSize(this.computeSize(0));
return r
async nodeCreated(node) {
if(node.adeAutosize) {
let size = node.computeSize(0);
size[0] += node.adeAutosize?.padding || 0;
node.setSize(size);
}
},
async getCustomWidgets() {
return {
ADEAUTOSIZE(node, inputName, inputData) {
let w = {
name : inputName,
type : "ADE.AUTOSIZE",
value : "",
options : {"serialize": false},
computeSize : function(width) {
return [0, -4];
}
}
node.adeAutosize = inputData[1];
if (!node.widgets) {
node.widgets = []
}
node.widgets.push(w)
return w;
}
}
}