MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / #processWidgetClick

Method #processWidgetClick

src/LGraphCanvas.ts:2601–2652  ·  view source on GitHub ↗
(e: CanvasPointerEvent, node: LGraphNode, widget: IBaseWidget)

Source from the content-addressed store, hash-verified

2599 }
2600
2601 #processWidgetClick(e: CanvasPointerEvent, node: LGraphNode, widget: IBaseWidget) {
2602 const { pointer } = this
2603
2604 // Custom widget - CanvasPointer
2605 if (typeof widget.onPointerDown === "function") {
2606 const handled = widget.onPointerDown(pointer, node, this)
2607 if (handled) return
2608 }
2609
2610 const oldValue = widget.value
2611
2612 const pos = this.graph_mouse
2613 const x = pos[0] - node.pos[0]
2614 const y = pos[1] - node.pos[1]
2615
2616 const widgetInstance = toConcreteWidget(widget, node, false)
2617 if (widgetInstance) {
2618 pointer.onClick = () => widgetInstance.onClick({
2619 e,
2620 node,
2621 canvas: this,
2622 })
2623 pointer.onDrag = eMove => widgetInstance.onDrag?.({
2624 e: eMove,
2625 node,
2626 canvas: this,
2627 })
2628 } else if (widget.mouse) {
2629 const result = widget.mouse(e, [x, y], node)
2630 if (result != null) this.dirty_canvas = result
2631 }
2632
2633 // value changed
2634 if (oldValue != widget.value) {
2635 node.onWidgetChanged?.(widget.name, widget.value, oldValue, widget)
2636 if (!node.graph) throw new NullGraphError()
2637 node.graph._version++
2638 }
2639
2640 // Clean up state var
2641 pointer.finally = () => {
2642 // Legacy custom widget callback
2643 if (widget.mouse) {
2644 const { eUp } = pointer
2645 if (!eUp) return
2646 const { canvasX, canvasY } = eUp
2647 widget.mouse(eUp, [canvasX - node.pos[0], canvasY - node.pos[1]], node)
2648 }
2649
2650 this.node_widget = null
2651 }
2652 }
2653
2654 /**
2655 * Pointer middle button click processing. Part of {@link processMouseDown}.

Callers 1

#processNodeClickMethod · 0.95

Calls 5

toConcreteWidgetFunction · 0.90
mouseMethod · 0.80
onPointerDownMethod · 0.65
onClickMethod · 0.45
onDragMethod · 0.45

Tested by

no test coverage detected