Skip to content

Commit 802dfaa

Browse files
authored
Merge pull request #386 from MarcMeszaros/simplified-allow-interaction-override
Simplify the allow_interaction override to only use node flags
2 parents e27ecd1 + 044b29c commit 802dfaa

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

guides/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ LGraphCanvas is the class in charge of rendering/interaction with the nodes insi
233233
## LGraphCanvas settings
234234
There are graph canvas settings that could be defined or modified to change behaviour:
235235

236-
* **allow_interaction**: when set to `false` disable interaction with the canvas
237-
* **drag_mode**: when set to `true` and `allow_interaction` is `false`, allow individual nodes with `flags.allow_interaction` set to `true` to be interacted with
236+
* **allow_interaction**: when set to `false` disable interaction with the canvas (`flags.allow_interaction` on node can be used to override graph canvas setting)
238237

239238
### Canvas Shortcuts
240239
* Space - Holding space key while moving the cursor moves the canvas around. It works when holding the mouse button down so it is easier to connect different nodes when the canvas gets too large.

src/litegraph.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,7 +5214,7 @@ LGraphNode.prototype.executeAction = function(action)
52145214
this.allow_reconnect_links = true; //allows to change a connection with having to redo it again
52155215
this.align_to_grid = false; //snap to grid
52165216

5217-
this.drag_mode = false; // allow dragging when interactions are disabled
5217+
this.drag_mode = false;
52185218
this.dragging_rectangle = null;
52195219

52205220
this.filter = null; //allows to filter to only accept some type of nodes in a graph
@@ -5865,7 +5865,7 @@ LGraphNode.prototype.executeAction = function(action)
58655865

58665866
//when clicked on top of a node
58675867
//and it is not interactive
5868-
if (node && (this.allow_interaction || (!this.allow_interaction && node.flags.allow_interaction)) && !skip_action && !this.read_only) {
5868+
if (node && (this.allow_interaction || node.flags.allow_interaction) && !skip_action && !this.read_only) {
58695869
if (!this.live_mode && !node.flags.pinned) {
58705870
this.bringToFront(node);
58715871
} //if it wasn't selected?
@@ -6299,6 +6299,9 @@ LGraphNode.prototype.executeAction = function(action)
62996299
this.dirty_canvas = true;
63006300
}
63016301

6302+
//get node over
6303+
var node = this.graph.getNodeOnPos(e.canvasX,e.canvasY,this.visible_nodes);
6304+
63026305
if (this.dragging_rectangle)
63036306
{
63046307
this.dragging_rectangle[2] = e.canvasX - this.dragging_rectangle[0];
@@ -6328,14 +6331,11 @@ LGraphNode.prototype.executeAction = function(action)
63286331
this.ds.offset[1] += delta[1] / this.ds.scale;
63296332
this.dirty_canvas = true;
63306333
this.dirty_bgcanvas = true;
6331-
} else if ((this.allow_interaction || (!this.allow_interaction && this.drag_mode)) && !this.read_only) {
6334+
} else if ((this.allow_interaction || (node && node.flags.allow_interaction)) && !this.read_only) {
63326335
if (this.connecting_node) {
63336336
this.dirty_canvas = true;
63346337
}
63356338

6336-
//get node over
6337-
var node = this.graph.getNodeOnPos(e.canvasX,e.canvasY,this.visible_nodes);
6338-
63396339
//remove mouseover flag
63406340
for (var i = 0, l = this.graph._nodes.length; i < l; ++i) {
63416341
if (this.graph._nodes[i].mouseOver && node != this.graph._nodes[i] ) {

0 commit comments

Comments
 (0)