refactor(litegraph): add widget filtering helper methods

- Add getLayoutWidgets() to LGraphNode for layout calculations
- Add hasAdvancedWidgets() to LGraphNode for advanced widget checks
- Update _arrangeWidgets() to use getLayoutWidgets()
- Update toggleAdvanced() and context menu to use hasAdvancedWidgets()

Part of Phase 2 WidgetValueStore expansion (Step 5).

Amp-Thread-ID: https://ampcode.com/threads/T-019c263e-978e-7324-b320-57e15bf6065c
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-02-03 17:27:30 -08:00
parent 4a491c5734
commit bb13bec8d6
2 changed files with 18 additions and 3 deletions

View File

@@ -8221,7 +8221,7 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
callback: LGraphCanvas.onMenuNodeCollapse
})
}
if (node.widgets?.some((w) => w.advanced)) {
if (node.hasAdvancedWidgets()) {
options.push({
content: node.showAdvanced ? 'Hide Advanced' : 'Show Advanced',
callback: LGraphCanvas.onMenuToggleAdvanced

View File

@@ -3511,7 +3511,7 @@ export class LGraphNode
* Toggles advanced mode of the node, showing advanced widgets
*/
toggleAdvanced() {
if (!this.widgets?.some((w) => w.advanced)) return
if (!this.hasAdvancedWidgets()) return
if (!this.graph) throw new NullGraphError()
this.graph._version++
this.showAdvanced = !this.showAdvanced
@@ -3889,6 +3889,21 @@ export class LGraphNode
return !isHidden
}
/**
* Returns all widgets that should participate in layout calculations.
* Filters out hidden widgets only (not collapsed/advanced).
*/
getLayoutWidgets(): IBaseWidget[] {
return this.widgets?.filter((w) => !w.hidden) ?? []
}
/**
* Returns `true` if the node has any advanced widgets.
*/
hasAdvancedWidgets(): boolean {
return this.widgets?.some((w) => w.advanced) ?? false
}
updateComputedDisabled() {
if (!this.widgets) return
for (const widget of this.widgets)
@@ -4099,7 +4114,7 @@ export class LGraphNode
w: IBaseWidget
}[] = []
const visibleWidgets = this.widgets.filter((w) => !w.hidden)
const visibleWidgets = this.getLayoutWidgets()
for (const w of visibleWidgets) {
if (w.computeSize) {