[Refactor] Move slot code out of LGraphNode (#981)

Moves collapsed node slot render code to the slot instances.
This commit is contained in:
filtered
2025-04-29 03:35:45 +10:00
committed by GitHub
parent ccc588b842
commit be92f5bdbb
4 changed files with 30 additions and 35 deletions

View File

@@ -49,6 +49,9 @@ export abstract class NodeSlot implements INodeSlot {
])
}
/** The center point of this slot when the node is collapsed. */
abstract get collapsedPos(): ReadOnlyPoint
#node: LGraphNode
get node(): LGraphNode {
return this.#node
@@ -204,11 +207,11 @@ export abstract class NodeSlot implements INodeSlot {
ctx.lineWidth = originalLineWidth
}
drawCollapsed(ctx: CanvasRenderingContext2D, options: { pos: Point }) {
const [x, y] = options.pos
drawCollapsed(ctx: CanvasRenderingContext2D) {
const [x, y] = this.collapsedPos
// Save original styles
const originalFillStyle = ctx.fillStyle
const { fillStyle } = ctx
ctx.fillStyle = "#686"
ctx.beginPath()
@@ -234,6 +237,6 @@ export abstract class NodeSlot implements INodeSlot {
ctx.fill()
// Restore original styles
ctx.fillStyle = originalFillStyle
ctx.fillStyle = fillStyle
}
}