From 6ff80cfd36e819d229cda9712882f85e5bc070bb Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 11 May 2025 00:47:48 +1000 Subject: [PATCH] [Cleanup] Fix node background drawn twice / misc (#1040) --- src/DragAndScale.ts | 2 -- src/LGraph.ts | 10 ++++++++-- src/LGraphCanvas.ts | 4 ++-- src/litegraph.ts | 8 +++----- src/measure.ts | 4 ++++ src/widgets/BaseWidget.ts | 6 +++--- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/DragAndScale.ts b/src/DragAndScale.ts index 0aaa272aa..ab25933c4 100644 --- a/src/DragAndScale.ts +++ b/src/DragAndScale.ts @@ -128,9 +128,7 @@ export class DragAndScale { } else if (value > this.max_scale) { value = this.max_scale } - if (value == this.scale) return - if (!this.element) return const rect = this.element.getBoundingClientRect() if (!rect) return diff --git a/src/LGraph.ts b/src/LGraph.ts index d47f13a9f..94fe12ac1 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -837,9 +837,15 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable v ? a : (b < v ? b : v) -} - // Load legacy polyfills loadPolyfills() @@ -29,7 +25,9 @@ loadPolyfills() // Type definitions for litegraph.js 0.7.0 // Project: litegraph.js // Definitions by: NateScarlet +/** @deprecated Use {@link Point} instead. */ export type Vector2 = Point +/** @deprecated Use {@link Rect} instead. */ export type Vector4 = [number, number, number, number] export interface IContextMenuItem { @@ -133,7 +131,7 @@ export { LGraphCanvas, type LGraphCanvasState } from "./LGraphCanvas" export { LGraphGroup } from "./LGraphGroup" export { LGraphNode, type NodeId } from "./LGraphNode" export { type LinkId, LLink } from "./LLink" -export { createBounds } from "./measure" +export { clamp, createBounds } from "./measure" export { Reroute, type RerouteId } from "./Reroute" export type { CanvasPointerEvent } from "./types/events" export { diff --git a/src/measure.ts b/src/measure.ts index ee6e611df..762895c81 100644 --- a/src/measure.ts +++ b/src/measure.ts @@ -368,3 +368,7 @@ export function snapPoint(pos: Point | Rect, snapTo: number): boolean { pos[1] = snapTo * Math.round(pos[1] / snapTo) return true } + +export function clamp(value: number, min: number, max: number): number { + return value < min ? min : (value > max ? max : value) +} diff --git a/src/widgets/BaseWidget.ts b/src/widgets/BaseWidget.ts index feca3c484..eb3b374ce 100644 --- a/src/widgets/BaseWidget.ts +++ b/src/widgets/BaseWidget.ts @@ -165,7 +165,7 @@ export abstract class BaseWidget impl * @param options The options for drawing the widget * @remarks Leaves {@link ctx} dirty. */ - protected drawWidgetShape(ctx: CanvasRenderingContext2D, { width, showText }: DrawWidgetOptions) { + protected drawWidgetShape(ctx: CanvasRenderingContext2D, { width, showText }: DrawWidgetOptions): void { const { height, y } = this const { margin } = BaseWidget @@ -192,7 +192,7 @@ export abstract class BaseWidget impl width, leftPadding = 5, rightPadding = 20, - }: DrawTruncatingTextOptions) { + }: DrawTruncatingTextOptions): void { const { height, y } = this const { margin } = BaseWidget @@ -264,7 +264,7 @@ export abstract class BaseWidget impl * @param value The value to set * @param options The options for setting the value */ - setValue(value: TWidget["value"], { e, node, canvas }: WidgetEventOptions) { + setValue(value: TWidget["value"], { e, node, canvas }: WidgetEventOptions): void { const oldValue = this.value if (value === this.value) return