From f2cc3aac4f3f67440a8470d77d824676909d7582 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 9 May 2025 08:02:49 +1000 Subject: [PATCH 1/3] nit --- src/widgets/LegacyWidget.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/widgets/LegacyWidget.ts b/src/widgets/LegacyWidget.ts index 84e9a61c5..bbf75c519 100644 --- a/src/widgets/LegacyWidget.ts +++ b/src/widgets/LegacyWidget.ts @@ -23,8 +23,7 @@ export class LegacyWidget extends Bas override drawWidget(ctx: CanvasRenderingContext2D, options: DrawWidgetOptions) { const H = LiteGraph.NODE_WIDGET_HEIGHT - const thisAsICustomWidget = this - thisAsICustomWidget.draw?.(ctx, this.node, options.width, this.y, H, !!options.showText) + this.draw?.(ctx, this.node, options.width, this.y, H, !!options.showText) } override onClick() { From ea6e0bf20ae28390dc56d2d2743f74f9b365975c Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 9 May 2025 08:35:44 +1000 Subject: [PATCH 2/3] [TS] Declare missing types in BaseWidget --- src/LGraphNode.ts | 2 +- src/widgets/BaseWidget.ts | 7 +++++++ src/widgets/KnobWidget.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index bcb60e376..ea890c0df 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -217,7 +217,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { properties: Dictionary = {} properties_info: INodePropertyInfo[] = [] flags: INodeFlags = {} - widgets?: IBaseWidget[] + widgets?: (IBaseWidget | BaseWidget)[] /** * The amount of space available for widgets to grow into. * @see {@link layoutWidgets} diff --git a/src/widgets/BaseWidget.ts b/src/widgets/BaseWidget.ts index 67438a4d6..feca3c484 100644 --- a/src/widgets/BaseWidget.ts +++ b/src/widgets/BaseWidget.ts @@ -42,6 +42,13 @@ export abstract class BaseWidget impl static labelValueGap = 5 declare computedHeight?: number + declare serialize?: boolean + computeLayoutSize?(node: LGraphNode): { + minHeight: number + maxHeight?: number + minWidth: number + maxWidth?: number + } #node: LGraphNode /** The node that this widget belongs to. */ diff --git a/src/widgets/KnobWidget.ts b/src/widgets/KnobWidget.ts index 688bb6cc7..c9351e427 100644 --- a/src/widgets/KnobWidget.ts +++ b/src/widgets/KnobWidget.ts @@ -12,7 +12,7 @@ export class KnobWidget extends BaseWidget implements IKnobWidget { * Compute the layout size of the widget. * @returns The layout size of the widget. */ - computeLayoutSize(): { + override computeLayoutSize(): { minHeight: number maxHeight?: number minWidth: number From fc8022d0e0cc31eef09d9e8f330e7a814637d619 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 9 May 2025 09:58:58 +1000 Subject: [PATCH 3/3] Subclass all 3rd party custom widgets on ingestion - Warns in console (once) when a POJO is detected - Minor perf improvement (POJO widgets will suffer perf hit) --- src/LGraphNode.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index ea890c0df..26ce2b533 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -43,6 +43,7 @@ import { TitleMode, } from "./types/globalEnums" import { findFreeSlotOfType } from "./utils/collections" +import { warnDeprecated } from "./utils/feedback" import { distributeSpace } from "./utils/spaceDistribution" import { toClass } from "./utils/type" import { BaseWidget } from "./widgets/BaseWidget" @@ -1730,7 +1731,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { custom_widget: TPlainWidget, ): TPlainWidget | WidgetTypeMap[TPlainWidget["type"]] { this.widgets ||= [] - const widget = toConcreteWidget(custom_widget, this, false) ?? custom_widget + const widget = toConcreteWidget(custom_widget, this) this.widgets.push(widget) return widget } @@ -3385,7 +3386,6 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { const nodeWidth = this.size[0] const { widgets } = this - const H = LiteGraph.NODE_WIDGET_HEIGHT const showText = !lowQuality ctx.save() ctx.globalAlpha = editorAlpha @@ -3406,11 +3406,13 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { if (widget.computedDisabled) ctx.globalAlpha *= 0.5 const width = widget.width || nodeWidth - const widgetInstance = toConcreteWidget(widget, this, false) - if (widgetInstance) { - widgetInstance.drawWidget(ctx, { width, showText }) + // Bypass full type-checking + if ("drawWidget" in widget) { + widget.drawWidget(ctx, { width, showText }) } else { - widget.draw?.(ctx, this, width, y, H, lowQuality) + // Assume this is a POJO added directly to widget array + warnDeprecated(`DEPRECATED: Found invalid widget [${widget.name}] - use BaseWidget subclass or use node.addCustomWidget`, widget) + toConcreteWidget(widget, this).drawWidget(ctx, { width, showText }) } ctx.globalAlpha = editorAlpha }