Add CanvasPointer callback for node widgets (#363)

* Add CanvasPointer callback for node widgets

* Add API documentation

* nit - Docs
This commit is contained in:
filtered
2024-12-02 12:31:48 +11:00
committed by GitHub
parent a0b50dcf15
commit 8cda1ac48a
4 changed files with 228 additions and 1 deletions

View File

@@ -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<TValue = unknown> extends Record<string, unknown> {
@@ -151,4 +151,19 @@ export interface IBaseWidget<TElement extends HTMLElement = HTMLElement> {
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
}