Drag out links to disconnect nodes (#894)

* Disconnecting Links

* Fix bug if nodeid is 0
This commit is contained in:
0HyperCube
2022-12-21 19:19:24 +00:00
committed by Keavon Chambers
parent 4f637ee18b
commit 5e95090504
4 changed files with 58 additions and 3 deletions

View File

@@ -25,6 +25,10 @@ pub enum NodeGraphMessage {
node_id: NodeId,
},
DeleteSelectedNodes,
DisconnectNodes {
node_id: NodeId,
input_index: usize,
},
DoubleClickNode {
node: NodeId,
},

View File

@@ -392,6 +392,22 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &InputPreprocessorMessageH
}
}
}
NodeGraphMessage::DisconnectNodes { node_id, input_index } => {
let Some(network) = self.get_active_network_mut(document) else {
warn!("No network");
return;
};
let Some(node) = network.nodes.get_mut(&node_id) else {
warn!("Invalid node");
return;
};
let Some(node_type) = resolve_document_node_type(&node.name) else {
warn!("Node {} not in library", node.name);
return;
};
node.inputs[input_index] = node_type.inputs[input_index].default.clone();
Self::send_graph(network, responses);
}
NodeGraphMessage::DoubleClickNode { node } => {
self.selected_nodes = Vec::new();
if let Some(network) = self.get_active_network_mut(document) {