From 1c6f04f1dba83ab7aa35124fca6f3725ef7cca19 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:41:10 +0900 Subject: [PATCH] Add event when readonly changes (#160) * Add even when readonly is changed * Swap to ts private instead of es --- public/litegraph.d.ts | 1 + src/LGraphCanvas.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/public/litegraph.d.ts b/public/litegraph.d.ts index 16ef84b62..3f63bec72 100644 --- a/public/litegraph.d.ts +++ b/public/litegraph.d.ts @@ -1393,6 +1393,7 @@ export declare class LGraphCanvas { graph_mouse: Vector2; pointer_is_down?: boolean; + read_only: boolean; /** clears all the data inside */ clear(): void; diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 43ae3c648..aeaa7ebdf 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -69,6 +69,21 @@ export class LGraphCanvas { } } + // if set to true users cannot modify the graph + private _read_only = false; + get read_only() { + return this._read_only + } + set read_only(value) { + if (value != this._read_only) { + this._read_only = value; + this.emitEvent({ + subType: "read-only", + readOnly: value + }) + } + } + constructor(canvas, graph, options) { this.options = options = options || {}; @@ -113,7 +128,6 @@ export class LGraphCanvas { this.clear_background = true; this.clear_background_color = "#222"; - this.read_only = false; //if set to true users cannot modify the graph this.render_only_selected = true; this.live_mode = false; this.show_info = true;