Skip to content

Commit

Permalink
Simplify the allow_interaction override to use node flags
Browse files Browse the repository at this point in the history
Remove the need to use 'drag_mode' on the graph cavas and instead use a
similarly name flag on the node 'allow_interaction' to allow per node
interaction when the global 'allow_interaction' flag is set to false.
  • Loading branch information
MarcMeszaros committed Apr 30, 2023
1 parent e27ecd1 commit 044b29c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ LGraphCanvas is the class in charge of rendering/interaction with the nodes insi
## LGraphCanvas settings
There are graph canvas settings that could be defined or modified to change behaviour:

* **allow_interaction**: when set to `false` disable interaction with the canvas
* **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
* **allow_interaction**: when set to `false` disable interaction with the canvas (`flags.allow_interaction` on node can be used to override graph canvas setting)

### Canvas Shortcuts
* 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.
Expand Down
12 changes: 6 additions & 6 deletions src/litegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5214,7 +5214,7 @@ LGraphNode.prototype.executeAction = function(action)
this.allow_reconnect_links = true; //allows to change a connection with having to redo it again
this.align_to_grid = false; //snap to grid

this.drag_mode = false; // allow dragging when interactions are disabled
this.drag_mode = false;
this.dragging_rectangle = null;

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

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

//get node over
var node = this.graph.getNodeOnPos(e.canvasX,e.canvasY,this.visible_nodes);

if (this.dragging_rectangle)
{
this.dragging_rectangle[2] = e.canvasX - this.dragging_rectangle[0];
Expand Down Expand Up @@ -6328,14 +6331,11 @@ LGraphNode.prototype.executeAction = function(action)
this.ds.offset[1] += delta[1] / this.ds.scale;
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
} else if ((this.allow_interaction || (!this.allow_interaction && this.drag_mode)) && !this.read_only) {
} else if ((this.allow_interaction || (node && node.flags.allow_interaction)) && !this.read_only) {
if (this.connecting_node) {
this.dirty_canvas = true;
}

//get node over
var node = this.graph.getNodeOnPos(e.canvasX,e.canvasY,this.visible_nodes);

//remove mouseover flag
for (var i = 0, l = this.graph._nodes.length; i < l; ++i) {
if (this.graph._nodes[i].mouseOver && node != this.graph._nodes[i] ) {
Expand Down

0 comments on commit 044b29c

Please sign in to comment.