import { Point } from '../interfaces'; import { CanvasPointer, LGraphCanvas, LGraphNode, Size } from '../litegraph'; import { CanvasPointerEvent } from '../types/events'; import { IBaseWidget } from '../types/widgets'; export interface DrawWidgetOptions { /** The width of the node where this widget will be displayed. */ width: number; /** Synonym for "low quality". */ showText?: boolean; } export interface DrawTruncatingTextOptions extends DrawWidgetOptions { /** The canvas context to draw the text on. */ ctx: CanvasRenderingContext2D; /** The amount of padding to add to the left of the text. */ leftPadding?: number; /** The amount of padding to add to the right of the text. */ rightPadding?: number; } export interface WidgetEventOptions { e: CanvasPointerEvent; node: LGraphNode; canvas: LGraphCanvas; } export declare abstract class BaseWidget implements IBaseWidget { #private; /** From node edge to widget edge */ static margin: number; /** From widget edge to tip of arrow button */ static arrowMargin: number; /** Arrow button width */ static arrowWidth: number; /** Absolute minimum display width of widget values */ static minValueWidth: number; /** Minimum gap between label and value */ static labelValueGap: number; computedHeight?: number; serialize?: boolean; computeLayoutSize?(node: LGraphNode): { minHeight: number; maxHeight?: number; minWidth: number; maxWidth?: number; }; /** The node that this widget belongs to. */ get node(): LGraphNode; linkedWidgets?: IBaseWidget[]; name: string; options: TWidget["options"]; label?: string; type: TWidget["type"]; y: number; last_y?: number; width?: number; disabled?: boolean; computedDisabled?: boolean; hidden?: boolean; advanced?: boolean; tooltip?: string; element?: HTMLElement; callback?(value: any, canvas?: LGraphCanvas, node?: LGraphNode, pos?: Point, e?: CanvasPointerEvent): void; mouse?(event: CanvasPointerEvent, pointerOffset: Point, node: LGraphNode): boolean; computeSize?(width?: number): Size; onPointerDown?(pointer: CanvasPointer, node: LGraphNode, canvas: LGraphCanvas): boolean; get value(): TWidget["value"]; set value(value: TWidget["value"]); constructor(widget: TWidget & { node: LGraphNode; }); constructor(widget: TWidget, node: LGraphNode); get outline_color(): string; get background_color(): string; get height(): number; get text_color(): string; get secondary_text_color(): string; get disabledTextColor(): string; get displayName(): string; get _displayValue(): string; get labelBaseline(): number; /** * Draws the widget * @param ctx The canvas context * @param options The options for drawing the widget * @remarks Not naming this `draw` as `draw` conflicts with the `draw` method in * custom widgets. */ abstract drawWidget(ctx: CanvasRenderingContext2D, options: DrawWidgetOptions): void; /** * Draws the standard widget shape - elongated capsule. The path of the widget shape is not * cleared, and may be used for further drawing. * @param ctx The canvas context * @param options The options for drawing the widget * @remarks Leaves {@link ctx} dirty. */ protected drawWidgetShape(ctx: CanvasRenderingContext2D, { width, showText }: DrawWidgetOptions): void; /** * A shared routine for drawing a label and value as text, truncated * if they exceed the available width. */ protected drawTruncatingText({ ctx, width, leftPadding, rightPadding, }: DrawTruncatingTextOptions): void; /** * Handles the click event for the widget * @param options The options for handling the click event */ abstract onClick(options: WidgetEventOptions): void; /** * Handles the drag event for the widget * @param options The options for handling the drag event */ onDrag?(options: WidgetEventOptions): void; /** * Sets the value of the widget * @param value The value to set * @param options The options for setting the value */ setValue(value: TWidget["value"], { e, node, canvas }: WidgetEventOptions): void; /** * Clones the widget. * @param node The node that will own the cloned widget. * @returns A new widget with the same properties as the original * @remarks Subclasses with custom constructors must override this method. * * Correctly and safely typing this is currently not possible (practical?) in TypeScript 5.8. */ createCopyForNode(node: LGraphNode): this; }