-
Notifications
You must be signed in to change notification settings - Fork 64
draft: Show widget name when connected, hiding only the value #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3411,42 +3411,54 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { | |
| return !isHidden | ||
| } | ||
|
|
||
| // sync number of widgets with the number of widgets in the node | ||
| drawWidgets(ctx: CanvasRenderingContext2D, { | ||
| lowQuality = false, | ||
| editorAlpha = 1, | ||
| }: DrawWidgetsOptions): void { | ||
| if (!this.widgets) return | ||
|
|
||
| const nodeWidth = this.size[0] | ||
| const { widgets } = this | ||
| const H = LiteGraph.NODE_WIDGET_HEIGHT | ||
| const showText = !lowQuality | ||
| ctx.save() | ||
| ctx.globalAlpha = editorAlpha | ||
|
|
||
| for (const widget of widgets) { | ||
| if (!this.isWidgetVisible(widget)) continue | ||
|
|
||
| const { y } = widget | ||
| const outlineColour = widget.advanced ? LiteGraph.WIDGET_ADVANCED_OUTLINE_COLOR : LiteGraph.WIDGET_OUTLINE_COLOR | ||
| const outlineColour = widget.advanced | ||
| ? LiteGraph.WIDGET_ADVANCED_OUTLINE_COLOR | ||
| : LiteGraph.WIDGET_OUTLINE_COLOR | ||
|
|
||
| widget.last_y = y | ||
| // Disable widget if it is disabled or if the value is passed from socket connection. | ||
| widget.computedDisabled = widget.disabled || this.getSlotFromWidget(widget)?.link != null | ||
|
|
||
| // 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never use type assertions. |
||
|
|
||
| ctx.strokeStyle = outlineColour | ||
| ctx.fillStyle = "#222" | ||
| ctx.textAlign = "left" | ||
|
|
||
| if (widget.computedDisabled) ctx.globalAlpha *= 0.5 | ||
| const width = widget.width || nodeWidth | ||
|
|
||
| const forceHideValue = (widget as any).hideValue | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure ty for the advice. |
||
|
|
||
| if (typeof widget.draw === "function") { | ||
| widget.draw(ctx, this, width, y, H, lowQuality) | ||
| } else { | ||
| toConcreteWidget(widget, this, false)?.drawWidget(ctx, { width, showText }) | ||
| toConcreteWidget(widget, this, false)?.drawWidget(ctx, { | ||
| width, | ||
| showText: !forceHideValue, | ||
| }) | ||
| } | ||
|
|
||
| ctx.globalAlpha = editorAlpha | ||
| } | ||
|
|
||
| ctx.restore() | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| import type { IBaseWidget } from "@/types/widgets" | ||
|
|
||
| import { drawTextInArea } from "@/draw" | ||
| import { Rectangle } from "@/infrastructure/Rectangle" | ||
|
|
||
| import { BaseWidget, type DrawWidgetOptions, type WidgetEventOptions } from "./BaseWidget" | ||
|
|
||
| /** | ||
|
|
@@ -64,6 +67,18 @@ export abstract class BaseSteppedWidget<TWidget extends IBaseWidget = IBaseWidge | |
| if (!this.computedDisabled) this.drawArrowButtons(ctx, options.width) | ||
|
|
||
| this.drawTruncatingText({ ctx, width: options.width }) | ||
| } else { | ||
| // Just draw the name, truncated | ||
| 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", | ||
| }) | ||
|
Comment on lines
+72
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we are repeating this logic twice, can we extract to helper function or class method? |
||
| } | ||
|
|
||
| // Restore original context attributes | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the comment referring to?