Skip to content

Commit

Permalink
Fix custom widgets not receiving pointermove events (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfiltered authored Nov 22, 2024
1 parent 1f572b4 commit ae6422b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/types/widgets.ts
Original file line number Diff line number Diff line change
@@ -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<TValue = unknown> extends Record<string, unknown> {
on?: string
Expand Down Expand Up @@ -135,7 +135,14 @@ export interface IBaseWidget<TElement extends HTMLElement = HTMLElement> {
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,
Expand Down

0 comments on commit ae6422b

Please sign in to comment.