Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/lib/litegraph/src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5793,15 +5793,19 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
drawSnapGuide(
ctx: CanvasRenderingContext2D,
item: Positionable,
shape = RenderShape.ROUND
shape = RenderShape.ROUND,
{ offsetToSlot }: { offsetToSlot?: boolean } = {}
) {
const snapGuide = temp
snapGuide.set(item.boundingRect)

// Not all items have pos equal to top-left of bounds
const { pos } = item
const offsetX = pos[0] - snapGuide[0]
const offsetY = pos[1] - snapGuide[1]
const offsetY =
pos[1] -
snapGuide[1] -
(offsetToSlot ? LiteGraph.NODE_SLOT_HEIGHT * 0.7 : 0)

// Normalise boundingRect to pos to snap
snapGuide[0] += offsetX
Expand Down Expand Up @@ -5978,7 +5982,9 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
this.isDragging &&
this.selectedItems.has(reroute)
) {
this.drawSnapGuide(ctx, reroute, RenderShape.CIRCLE)
this.drawSnapGuide(ctx, reroute, RenderShape.CIRCLE, {
offsetToSlot: true
})
}
reroute.draw(ctx, this._pattern)

Expand Down
4 changes: 3 additions & 1 deletion src/lib/litegraph/src/Reroute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
ReadOnlyRect,
ReadonlyLinkNetwork
} from './interfaces'
import { LiteGraph } from './litegraph'
import { distance, isPointInRect } from './measure'
import type { Serialisable, SerialisableReroute } from './types/serialisation'

Expand Down Expand Up @@ -428,9 +429,10 @@ export class Reroute
snapToGrid(snapTo: number): boolean {
if (!snapTo) return false

const offsetY = LiteGraph.NODE_SLOT_HEIGHT * 0.7
const { pos } = this
pos[0] = snapTo * Math.round(pos[0] / snapTo)
pos[1] = snapTo * Math.round(pos[1] / snapTo)
pos[1] = snapTo * Math.round((pos[1] - offsetY) / snapTo) + offsetY
return true
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export abstract class SubgraphIONodeBase<
{
static margin = 10
static minWidth = 100
static roundedRadius = 10
static roundedRadius = 4

private readonly _boundingRect: Rectangle = new Rectangle()

Expand Down
Loading