[Cleanup] Fix node background drawn twice / misc (#1040)

This commit is contained in:
filtered
2025-05-11 00:47:48 +10:00
committed by GitHub
parent d452240936
commit 6ff80cfd36
6 changed files with 20 additions and 14 deletions

View File

@@ -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

View File

@@ -837,9 +837,15 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
}
// not found
if (this._nodes_by_id[node.id] == null) return
if (this._nodes_by_id[node.id] == null) {
console.warn("LiteGraph: node not found", node)
return
}
// cannot be removed
if (node.ignore_remove) return
if (node.ignore_remove) {
console.warn("LiteGraph: node cannot be removed", node)
return
}
// sure? - almost sure is wrong
this.beforeChange()

View File

@@ -334,7 +334,6 @@ export class LGraphCanvas {
this.state.draggingCanvas = value
this.#updateCursorStyle()
}
// #endregion Legacy accessors
/**
* @deprecated Use {@link LGraphNode.titleFontStyle} instead.
@@ -342,6 +341,7 @@ export class LGraphCanvas {
get title_text_font(): string {
return `${LiteGraph.NODE_TEXT_SIZE}px ${LiteGraph.NODE_FONT}`
}
// #endregion Legacy accessors
get inner_text_font(): string {
return `normal ${LiteGraph.NODE_SUBTEXT_SIZE}px ${LiteGraph.NODE_FONT}`
@@ -4552,7 +4552,7 @@ export class LGraphCanvas {
// Draw node background (shape)
ctx.beginPath()
if (shape == RenderShape.BOX || low_quality) {
ctx.fillRect(area[0], area[1], area[2], area[3])
ctx.rect(area[0], area[1], area[2], area[3])
} else if (shape == RenderShape.ROUND || shape == RenderShape.CARD) {
ctx.roundRect(
area[0],

View File

@@ -17,10 +17,6 @@ import { loadPolyfills } from "./polyfills"
export const LiteGraph = new LiteGraphGlobal()
export function clamp(v: number, a: number, b: number): number {
return a > 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 <https://github.com/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 {

View File

@@ -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)
}

View File

@@ -165,7 +165,7 @@ export abstract class BaseWidget<TWidget extends IBaseWidget = IBaseWidget> 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<TWidget extends IBaseWidget = IBaseWidget> impl
width,
leftPadding = 5,
rightPadding = 20,
}: DrawTruncatingTextOptions) {
}: DrawTruncatingTextOptions): void {
const { height, y } = this
const { margin } = BaseWidget
@@ -264,7 +264,7 @@ export abstract class BaseWidget<TWidget extends IBaseWidget = IBaseWidget> 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