Add LGraphNode.strokeStyles API (#868)

This should allow frontend drop the stroke logic in hijack of
`drawNodeShape`. Example usage:

```ts
node.strokeStyles["executionError"] = (this: LGraphNode) => 
  app.lastNodeErrors?.[this.id] ? { colour: 'red', thickness: 2 } : undefined
```
This commit is contained in:
Chenlei Hu
2025-03-30 11:29:37 -04:00
committed by GitHub
parent 27a2b785ac
commit 854ac4350f
6 changed files with 80 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
import type { DragAndScale } from "./DragAndScale"
import type { IDrawBoundingOptions } from "./draw"
import type {
CanvasColour,
ColorOption,
@@ -256,6 +257,11 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
) ?? null
}
/**
* The stroke styles that should be applied to the node.
*/
strokeStyles: Record<string, (this: LGraphNode) => IDrawBoundingOptions | undefined>
exec_version?: number
action_call?: string
execute_triggered?: number
@@ -586,12 +592,34 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
overWidget: IWidget,
): boolean | undefined
#getErrorStrokeStyle(this: LGraphNode): IDrawBoundingOptions | undefined {
if (this.has_errors) {
return {
padding: 12,
thickness: 10,
colour: LiteGraph.NODE_ERROR_COLOUR,
}
}
}
#getSelectedStrokeStyle(this: LGraphNode): IDrawBoundingOptions | undefined {
if (this.selected) {
return {
padding: this.has_errors ? 20 : undefined,
}
}
}
constructor(title: string, type?: string) {
this.id = LiteGraph.use_uuids ? LiteGraph.uuidv4() : -1
this.title = title || "Unnamed"
this.type = type ?? ""
this.size = [LiteGraph.NODE_WIDTH, 60]
this.pos = [10, 10]
this.strokeStyles = {
error: this.#getErrorStrokeStyle,
selected: this.#getSelectedStrokeStyle,
}
}
/**