Simplifies the preset-chip picker (Smart Resize / Smart Batch Resize) to a single canvas implementation - drops the dual DOM-widget path, so chips stay positioned correctly under "Longest side (px)" in both classic and Nodes 2.0 rendering instead of jumping to the bottom of the node. Adds a shared setWidgetVisible() helper so dynamic show/hide (Counter start, the hidden customtext output on every node) actually works under Nodes 2.0's Vue reactivity - it previously only worked in classic canvas mode. Fixes two silent Nodes 2.0 rendering bugs: widgets only repaint via their own triggerDraw(), not setDirtyCanvas(), so the active preset chip and status-box text were going visually stale after an update even though the underlying value was correct. And Nodes 2.0's WidgetLegacy bridge permanently stamps a widget.width that classic mode's own click hit-test then reads forever after - once a node had ever rendered under Nodes 2.0, classic mode silently lost clicks on the right side of a wide node. Both fixed by keeping widget state in sync on every draw() instead of trusting it to survive across renderer switches. Also centers section-divider labels with flanking lines (was label-left/line-right) and brightens the line color, which had become nearly invisible under Nodes 2.0's extra canvas scaling. README: reorders node sections into actual pipeline order (Prompt Controller -> Profile Switch -> Resize -> Resolution Multiplier -> Batch Resize, standalone tool last instead of mid-list), adds a Nodes 2.0 compatibility screenshot, and refreshes the Smart Batch Resize screenshot to match its current UI.
37 lines
1.9 KiB
JavaScript
37 lines
1.9 KiB
JavaScript
// Dynamically show/hide a widget (e.g. a field that only makes sense when
|
|
// another toggle is on) in a way that works in BOTH classic LiteGraph and
|
|
// Nodes 2.0.
|
|
//
|
|
// Classic mode collapses a row by giving it computeSize() => [0, -4] — the
|
|
// canvas layout loop calls computeSize() every frame, so this is enough on
|
|
// its own there.
|
|
//
|
|
// Nodes 2.0 never calls computeSize() at all; its widget list is a Vue
|
|
// `shallowReactive` array (see ComfyUI's useGraphNodeManager.ts) that only
|
|
// tracks the array's own indices/length, not properties nested inside each
|
|
// widget (like widget.options.hidden). So setting widget.hidden/options.hidden
|
|
// is necessary but NOT sufficient — nothing tells Vue to re-run the computed
|
|
// that reads it. A push-then-splice-it-back no-op on node.widgets forces a
|
|
// real structural array mutation, which Vue's reactive array DOES notify on,
|
|
// causing the widget list to re-evaluate and pick up the new hidden state.
|
|
export function setWidgetVisible(node, widget, visible) {
|
|
// Widgets don't always define their own computeSize (many rely on
|
|
// LiteGraph's built-in default row sizing), so it can legitimately be
|
|
// undefined — guard capture with a separate flag rather than truthiness,
|
|
// or a later call would "capture" the already-collapsed [0,-4] function.
|
|
if (!widget._visibilityDefaultCaptured) {
|
|
widget._defaultComputeSize = widget.computeSize;
|
|
widget._visibilityDefaultCaptured = true;
|
|
}
|
|
widget.computeSize = visible ? widget._defaultComputeSize : () => [0, -4];
|
|
widget.hidden = !visible;
|
|
if (!widget.options) widget.options = {};
|
|
widget.options.hidden = !visible;
|
|
|
|
const nudge = { name: "__visibility_nudge__", type: "custom", value: null, computeSize: () => [0, 0], draw() {} };
|
|
node.widgets.push(nudge);
|
|
node.widgets.splice(node.widgets.indexOf(nudge), 1);
|
|
|
|
node.setDirtyCanvas(true, true);
|
|
}
|