mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user