Add IColorable interface (#549)

* Add IColorable interface

* Set color option

* nit

* nit

* nit
This commit is contained in:
Chenlei Hu
2025-02-19 13:56:08 -05:00
committed by GitHub
parent 2592c18790
commit 6b1e40a011
5 changed files with 73 additions and 18 deletions

View File

@@ -1,8 +1,10 @@
// @ts-strict-ignore
import type {
CanvasColour,
ColorOption,
ConnectingLink,
Dictionary,
IColorable,
IContextMenuValue,
IFoundSlot,
INodeFlags,
@@ -142,7 +144,7 @@ export interface LGraphNode {
* @param {string} name a name for the node
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class LGraphNode implements Positionable, IPinnable {
export class LGraphNode implements Positionable, IPinnable, IColorable {
// Static properties used by dynamic child classes
static title?: string
static MAX_CONSOLE?: number
@@ -234,6 +236,27 @@ export class LGraphNode implements Positionable, IPinnable {
return this.boxcolor || colState || LiteGraph.NODE_DEFAULT_BOXCOLOR
}
/** The color option used to set {@link color} and {@link bgcolor}. */
#colorOption: ColorOption | null = null
/** @inheritdoc {@link IColorable.setColorOption} */
setColorOption(colorOption: ColorOption | null): void {
if (colorOption == null) {
delete this.color
delete this.bgcolor
this.#colorOption = null
} else {
this.color = colorOption.color
this.bgcolor = colorOption.bgcolor
this.#colorOption = colorOption
}
}
/** @inheritdoc {@link IColorable.getColorOption} */
getColorOption(): ColorOption | null {
return this.#colorOption
}
exec_version: number
action_call?: string
execute_triggered: number