diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 3c32f6e..82cabfa 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2517,6 +2517,13 @@ export class LGraphCanvas { #processWidgetClick(e: CanvasPointerEvent, node: LGraphNode, widget: IWidget) { const { pointer } = this + + // Custom widget - CanvasPointer + if (typeof widget.onPointerDown === "function") { + const handled = widget.onPointerDown(pointer, node, this) + if (handled) return + } + const width = widget.width || node.width const oldValue = widget.value diff --git a/src/types/widgets.ts b/src/types/widgets.ts index ae9ad49..b027c04 100644 --- a/src/types/widgets.ts +++ b/src/types/widgets.ts @@ -1,5 +1,5 @@ import { CanvasColour, Point, Size } from "../interfaces" -import type { LGraphCanvas, LGraphNode } from "../litegraph" +import type { CanvasPointer, LGraphCanvas, LGraphNode } from "../litegraph" import type { CanvasMouseEvent, CanvasPointerEvent } from "./events" export interface IWidgetOptions extends Record { @@ -151,4 +151,19 @@ export interface IBaseWidget { H: number, ): void computeSize?(width: number): Size + + /** + * Callback for pointerdown events, allowing custom widgets to register callbacks to occur + * for all {@link CanvasPointer} events. + * + * This callback is operated early in the pointerdown logic; actions that prevent it from firing are: + * - `Ctrl + Drag` Multi-select + * - `Alt + Click/Drag` Clone node + * @param pointer The CanvasPointer handling this event + * @param node The node this widget belongs to + * @param canvas The LGraphCanvas where this event originated + * @return Returning `true` from this callback forces Litegraph to ignore the event and + * not process it any further. + */ + onPointerDown(pointer: CanvasPointer, node: LGraphNode, canvas: LGraphCanvas): boolean }