draft: Show widget name when connected, hiding only the value#1076
draft: Show widget name when connected, hiding only the value#1076yiqun12 wants to merge 5 commits into
Conversation
Previously, when a widget was connected to an input link, the entire widget's text (name and value) would disappear. This made it difficult to identify the widget's function at a glance. This commit modifies the drawing behavior to: - Only hide the widget's value when it has an active input connection. - Continue to display the widget's name/label. This improves user experience by providing better visual context for connected widgets. Refactor: - Introduced a \hideValue\ property in \LGraphNode.drawWidgets\ to decouple value visibility from the widget's disabled state. - Updated \BaseSteppedWidget\ and \TextWidget\ to render only the \displayName\ when the value is hidden.
| return !isHidden | ||
| } | ||
|
|
||
| // sync number of widgets with the number of widgets in the node |
There was a problem hiding this comment.
What is the comment referring to?
| // Check if locked: either disabled or has an input connection | ||
| const connectedSlot = this.getSlotFromWidget(widget) | ||
| widget.computedDisabled = widget.disabled || connectedSlot?.link != null | ||
| ;(widget as any).hideValue = connectedSlot?.link != null |
There was a problem hiding this comment.
Never use type assertions.
| const { margin } = BaseWidget | ||
| const x = margin * 2 | ||
| const area = new Rectangle(x, this.y, options.width - x - margin, this.height * 0.7) | ||
| ctx.fillStyle = this.secondary_text_color | ||
| drawTextInArea({ | ||
| ctx, | ||
| text: this.displayName, | ||
| area, | ||
| align: "left", | ||
| }) |
There was a problem hiding this comment.
It seems we are repeating this logic twice, can we extract to helper function or class method?
| if (widget.computedDisabled) ctx.globalAlpha *= 0.5 | ||
| const width = widget.width || nodeWidth | ||
|
|
||
| const forceHideValue = (widget as any).hideValue |
There was a problem hiding this comment.
Never use type assertions. We need to look through the code to understand the classes, interfaces, types, and so on. After that, we should implement a solution that naturally extends the current system. If we do this successfuly, we may find that we never need to use type assertions.
To do this properly, it may require approaching the problem by doing research and asking LLM to explain the architecture and objects/classes in the codebase first.
Related to Comfy-Org/ComfyUI_frontend#4025
Previously, when a widget was connected to an input link, the entire widget's text (name and value) would disappear. This made it difficult to identify the widget's function at a glance.
This commit modifies the drawing behavior to:
This improves user experience by providing better visual context for connected widgets.
Refactor: