Skip to content

Commit 976ba6f

Browse files
authored
Merge pull request #385 from MarcMeszaros/moveable-interaction-off
Allow interactions per node override
2 parents 7ab10b5 + 1dc1670 commit 976ba6f

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

guides/README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Slots have the next information:
110110
* **dir**: optional, could be LiteGraph.UP, LiteGraph.RIGHT, LiteGraph.DOWN, LiteGraph.LEFT
111111
* **color_on**: color to render when it is connected
112112
* **color_off**: color to render when it is not connected
113-
113+
114114
To retrieve the data traveling through a link you can call ```node.getInputData``` or ```node.getOutputData```
115115

116116
### Define your Graph Node
@@ -151,7 +151,7 @@ node.onDrawForeground = function(ctx, graphcanvas)
151151
}
152152
```
153153

154-
### Custom Node Behaviour
154+
### Custom Node Behaviour
155155

156156
You can also grab events from the mouse in case your node has some sort of special interactivity.
157157

@@ -192,11 +192,11 @@ This is the list of supported widgets:
192192
* **"combo"** to select between multiple choices, the syntax is:
193193

194194
```this.addWidget("combo","Combo", "red", callback, { values:["red","green","blue"]} );```
195-
195+
196196
or if you want to use objects:
197-
197+
198198
```this.addWidget("combo","Combo", value1, callback, { values: { "title1":value1, "title2":value2 } } );```
199-
199+
200200
* **"text"** to edit a short string
201201
* **"toggle"** like a checkbox
202202
* **"button"**
@@ -223,11 +223,18 @@ Or if you want to associate a widget with a property of the node, then specify i
223223
function MyNode()
224224
{
225225
this.properties = { surname: "smith" };
226-
this.addWidget("text","Surname","", { property: "surname"}); //this will modify the node.properties
226+
this.addWidget("text","Surname","", { property: "surname"}); //this will modify the node.properties
227227
}
228228
```
229229
## LGraphCanvas
230230
LGraphCanvas is the class in charge of rendering/interaction with the nodes inside the browser.
231+
232+
## LGraphCanvas settings
233+
There are graph canvas settings that could be defined or modified to change behaviour:
234+
235+
* **allow_interaction**: when set to `false` disable interaction with the canvas
236+
* **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
237+
231238
### Canvas Shortcuts
232239
* 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.
233240
* Ctrl/Shift + Click - Add clicked node to selection.
@@ -277,7 +284,7 @@ To define slots for nodes you must use the type LiteGraph.ACTION for inputs, and
277284
function MyNode()
278285
{
279286
this.addInput("play", LiteGraph.ACTION );
280-
this.addInput("onFinish", LiteGraph.EVENT );
287+
this.addInput("onFinish", LiteGraph.EVENT );
281288
}
282289
```
283290

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;
5217+
this.drag_mode = false; // allow dragging when interactions are disabled
52185218
this.dragging_rectangle = null;
52195219

52205220
this.filter = null; //allows to filter to only accept some type of nodes in a graph
@@ -5865,13 +5865,13 @@ 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 && !skip_action && !this.read_only) {
5868+
if (node && (this.allow_interaction || (!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?
58725872

58735873
//not dragging mouse to connect two slots
5874-
if ( !this.connecting_node && !node.flags.collapsed && !this.live_mode ) {
5874+
if ( this.allow_interaction && !this.connecting_node && !node.flags.collapsed && !this.live_mode ) {
58755875
//Search for corner for resize
58765876
if ( !skip_action &&
58775877
node.resizable !== false &&
@@ -6025,7 +6025,7 @@ LGraphNode.prototype.executeAction = function(action)
60256025
}
60266026

60276027
//double clicking
6028-
if (is_double_click && this.selected_nodes[node.id]) {
6028+
if (this.allow_interaction && is_double_click && this.selected_nodes[node.id]) {
60296029
//double click node
60306030
if (node.onDblClick) {
60316031
node.onDblClick( e, pos, this );
@@ -6328,7 +6328,7 @@ LGraphNode.prototype.executeAction = function(action)
63286328
this.ds.offset[1] += delta[1] / this.ds.scale;
63296329
this.dirty_canvas = true;
63306330
this.dirty_bgcanvas = true;
6331-
} else if (this.allow_interaction && !this.read_only) {
6331+
} else if ((this.allow_interaction || (!this.allow_interaction && this.drag_mode)) && !this.read_only) {
63326332
if (this.connecting_node) {
63336333
this.dirty_canvas = true;
63346334
}
@@ -9912,7 +9912,7 @@ LGraphNode.prototype.executeAction = function(action)
99129912
event,
99139913
active_widget
99149914
) {
9915-
if (!node.widgets || !node.widgets.length) {
9915+
if (!node.widgets || !node.widgets.length || (!this.allow_interaction && !node.flags.allow_interaction)) {
99169916
return null;
99179917
}
99189918

0 commit comments

Comments
 (0)