From ae6422bad19150c1b1dd82d866a043905cc23c89 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sat, 23 Nov 2024 02:45:39 +1100 Subject: [PATCH] Fix custom widgets not receiving pointermove events (#335) --- src/LGraphCanvas.ts | 13 +++++++++++-- src/types/widgets.ts | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index d6f4f1a..6073a98 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2947,8 +2947,17 @@ export class LGraphCanvas { } // Resize corner - if (this.canvas && !e.ctrlKey) { - if (node.inResizeCorner(e.canvasX, e.canvasY)) underPointer |= CanvasItem.ResizeSe + if (node.inResizeCorner(e.canvasX, e.canvasY)) { + underPointer |= CanvasItem.ResizeSe + } else { + // Legacy widget mouse callbacks for pointermove events + const widget = node.getWidgetOnPos(e.canvasX, e.canvasY) + + if (widget?.mouse) { + const x = e.canvasX - node.pos[0] + const y = e.canvasY - node.pos[1] + this.dirty_canvas = widget.mouse(e, [x, y], node) + } } } else { // Not over a node diff --git a/src/types/widgets.ts b/src/types/widgets.ts index 7077094..ae9ad49 100644 --- a/src/types/widgets.ts +++ b/src/types/widgets.ts @@ -1,6 +1,6 @@ import { CanvasColour, Point, Size } from "../interfaces" import type { LGraphCanvas, LGraphNode } from "../litegraph" -import type { CanvasMouseEvent } from "./events" +import type { CanvasMouseEvent, CanvasPointerEvent } from "./events" export interface IWidgetOptions extends Record { on?: string @@ -135,7 +135,14 @@ export interface IBaseWidget { onRemove?(): void beforeQueued?(): void - mouse?(event: CanvasMouseEvent, arg1: number[], node: LGraphNode): boolean + /** + * Simple callback for pointer events, allowing custom widgets to events relevant to them. + * @param event The pointer event that triggered this callback + * @param pointerOffset Offset of the pointer relative to {@link node.pos} + * @param node The node this widget belongs to + * @todo Expose CanvasPointer API to custom widgets + */ + mouse?(event: CanvasPointerEvent, pointerOffset: Point, node: LGraphNode): boolean draw?( ctx: CanvasRenderingContext2D, node: LGraphNode,