Support for hidden & advanced widgets (#250)

This commit is contained in:
pythongosssss
2024-11-01 01:41:31 +00:00
committed by GitHub
parent d9d0837423
commit eaaa0a4c39
4 changed files with 48 additions and 2 deletions

View File

@@ -180,6 +180,7 @@ export class LGraphNode {
has_errors?: boolean
removable?: boolean
block_delete?: boolean
showAdvanced?: boolean
_pos: Point
public get pos() {
@@ -408,7 +409,8 @@ export class LGraphNode {
size: this.size,
flags: LiteGraph.cloneObject(this.flags),
order: this.order,
mode: this.mode
mode: this.mode,
showAdvanced: this.showAdvanced
}
//special case for when there were errors
@@ -1265,6 +1267,7 @@ export class LGraphNode {
if (this.widgets?.length) {
for (let i = 0, l = this.widgets.length; i < l; ++i) {
const widget = this.widgets[i]
if (widget.hidden || (widget.advanced && !this.showAdvanced)) continue;
widgets_height += widget.computeSize
? widget.computeSize(size[0])[1] + 4
@@ -2297,6 +2300,20 @@ export class LGraphNode {
this.setDirtyCanvas(true, true)
}
/**
* Toggles advanced mode of the node, showing advanced widgets
*/
toggleAdvanced() {
if (!this.widgets?.some(w => w.advanced)) return
this.graph._version++
this.showAdvanced = !this.showAdvanced
const prefSize = this.computeSize()
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)
}
get pinned() {
return !!this.flags.pinned
}