Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom widgets not receiving pointermove events #335

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading