[Refactor] NodeSlot.drawCollapsed (#498)

This commit is contained in:
Chenlei Hu
2025-02-08 23:00:58 -05:00
committed by GitHub
parent 7472d1d9a1
commit f26807f931
2 changed files with 39 additions and 28 deletions

View File

@@ -186,6 +186,39 @@ export abstract class NodeSlot implements INodeSlot {
ctx.strokeStyle = originalStrokeStyle
ctx.lineWidth = originalLineWidth
}
drawCollapsed(ctx: CanvasRenderingContext2D, options: { pos: Point }) {
const [x, y] = options.pos
// Save original styles
const originalFillStyle = ctx.fillStyle
ctx.fillStyle = "#686"
ctx.beginPath()
if (this.type === SlotType.Event || this.shape === RenderShape.BOX) {
ctx.rect(x - 7 + 0.5, y - 4, 14, 8)
} else if (this.shape === RenderShape.ARROW) {
// Adjust arrow direction based on whether this is an input or output slot
const isInput = this instanceof NodeInputSlot
if (isInput) {
ctx.moveTo(x + 8, y)
ctx.lineTo(x - 4, y - 4)
ctx.lineTo(x - 4, y + 4)
} else {
ctx.moveTo(x + 6, y)
ctx.lineTo(x - 6, y - 4)
ctx.lineTo(x - 6, y + 4)
}
ctx.closePath()
} else {
ctx.arc(x, y, 4, 0, Math.PI * 2)
}
ctx.fill()
// Restore original styles
ctx.fillStyle = originalFillStyle
}
}
export class NodeInputSlot extends NodeSlot implements INodeInputSlot {