mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
Add LGraphNode.expandToFitContent (#558)
This commit is contained in:
@@ -1303,6 +1303,17 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
this.onResize?.(this.size)
|
this.onResize?.(this.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expands the node size to fit its content.
|
||||||
|
*/
|
||||||
|
expandToFitContent(): void {
|
||||||
|
const newSize = this.computeSize()
|
||||||
|
this.setSize([
|
||||||
|
Math.max(this.size[0], newSize[0]),
|
||||||
|
Math.max(this.size[1], newSize[1]),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a new property to this node
|
* add a new property to this node
|
||||||
* @param type string defining the output type ("vec3","number",...)
|
* @param type string defining the output type ("vec3","number",...)
|
||||||
@@ -1355,7 +1366,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
if (LiteGraph.auto_load_slot_types)
|
if (LiteGraph.auto_load_slot_types)
|
||||||
LiteGraph.registerNodeAndSlotType(this, type, true)
|
LiteGraph.registerNodeAndSlotType(this, type, true)
|
||||||
|
|
||||||
this.setSize(this.computeSize())
|
this.expandToFitContent()
|
||||||
this.setDirtyCanvas(true, true)
|
this.setDirtyCanvas(true, true)
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
@@ -1382,7 +1393,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
LiteGraph.registerNodeAndSlotType(this, info[1], true)
|
LiteGraph.registerNodeAndSlotType(this, info[1], true)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSize(this.computeSize())
|
this.expandToFitContent()
|
||||||
this.setDirtyCanvas(true, true)
|
this.setDirtyCanvas(true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1404,7 +1415,6 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSize(this.computeSize())
|
|
||||||
this.onOutputRemoved?.(slot)
|
this.onOutputRemoved?.(slot)
|
||||||
this.setDirtyCanvas(true, true)
|
this.setDirtyCanvas(true, true)
|
||||||
}
|
}
|
||||||
@@ -1425,7 +1435,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
|
|
||||||
this.inputs ||= []
|
this.inputs ||= []
|
||||||
this.inputs.push(input)
|
this.inputs.push(input)
|
||||||
this.setSize(this.computeSize())
|
this.expandToFitContent()
|
||||||
|
|
||||||
this.onInputAdded?.(input)
|
this.onInputAdded?.(input)
|
||||||
LiteGraph.registerNodeAndSlotType(this, type)
|
LiteGraph.registerNodeAndSlotType(this, type)
|
||||||
@@ -1456,7 +1466,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
LiteGraph.registerNodeAndSlotType(this, info[1])
|
LiteGraph.registerNodeAndSlotType(this, info[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSize(this.computeSize())
|
this.expandToFitContent()
|
||||||
this.setDirtyCanvas(true, true)
|
this.setDirtyCanvas(true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1474,7 +1484,6 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
|
|
||||||
link.target_slot -= 1
|
link.target_slot -= 1
|
||||||
}
|
}
|
||||||
this.setSize(this.computeSize())
|
|
||||||
this.onInputRemoved?.(slot, slot_info[0])
|
this.onInputRemoved?.(slot, slot_info[0])
|
||||||
this.setDirtyCanvas(true, true)
|
this.setDirtyCanvas(true, true)
|
||||||
}
|
}
|
||||||
@@ -1696,7 +1705,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const widget = this.addCustomWidget(w)
|
const widget = this.addCustomWidget(w)
|
||||||
this.setSize(this.computeSize())
|
this.expandToFitContent()
|
||||||
return widget
|
return widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2774,13 +2783,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
if (!this.widgets?.some(w => w.advanced)) return
|
if (!this.widgets?.some(w => w.advanced)) return
|
||||||
this.graph._version++
|
this.graph._version++
|
||||||
this.showAdvanced = !this.showAdvanced
|
this.showAdvanced = !this.showAdvanced
|
||||||
const prefSize = this.computeSize()
|
this.expandToFitContent()
|
||||||
if (this.size[0] < prefSize[0] || this.size[1] < prefSize[1]) {
|
|
||||||
this.setSize([
|
|
||||||
Math.max(this.size[0], prefSize[0]),
|
|
||||||
Math.max(this.size[1], prefSize[1]),
|
|
||||||
])
|
|
||||||
}
|
|
||||||
this.setDirtyCanvas(true, true)
|
this.setDirtyCanvas(true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user