From 68056432044c3ad54a3f7aabd918e6f33e681dd3 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Wed, 12 Mar 2025 06:28:15 +1100 Subject: [PATCH] Snap to widget - fast widget conversion (#758) - Initial basic impl. - Tracking issue for proper impl. #757 --- src/LGraphCanvas.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 569fbff917..2e4f0fefd8 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2610,6 +2610,8 @@ export class LGraphCanvas implements ConnectionColorContext { LiteGraph.isValidConnection(linkConnector.renderLinks[0]?.fromSlot.type, widgetLinkType) && firstLink.node.isValidWidgetLink?.(firstLink.fromSlotIndex, node, overWidget) !== false ) { + const { pos: [nodeX, nodeY] } = node + highlightPos = [nodeX + 10, nodeY + 10 + overWidget.y] linkConnector.overWidget = overWidget linkConnector.overWidgetType = widgetLinkType } @@ -3973,6 +3975,39 @@ export class LGraphCanvas implements ConnectionColorContext { ctx.strokeStyle = linearGradient ctx.stroke() + const { linkConnector } = this + const { overWidget } = linkConnector + if (overWidget) { + const { computedHeight } = overWidget + + ctx.beginPath() + const { pos: [nodeX, nodeY] } = node + const height = LiteGraph.NODE_WIDGET_HEIGHT + if ( + overWidget.type.startsWith("custom") && + computedHeight != null && + computedHeight > height * 2 + ) { + // Most likely DOM widget text box + ctx.rect( + nodeX + 9, + nodeY + overWidget.y + 9, + (overWidget.width ?? area[2]) - 18, + computedHeight - 18, + ) + } else { + // Regular widget, probably + ctx.roundRect( + nodeX + 15, + nodeY + overWidget.y, + overWidget.width ?? area[2], + height, + height * 0.5, + ) + } + ctx.stroke() + } + ctx.strokeStyle = gradient ctx.stroke()