mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-11 13:58:28 +00:00
Send disconnect event on node delete
This commit is contained in:
parent
c6c517644a
commit
aecb0f5031
@ -168,6 +168,10 @@ where
|
||||
|
||||
/* Handle responses from drawing nodes */
|
||||
|
||||
// Some responses generate additional responses when processed. These
|
||||
// are stored here to report them back to the user.
|
||||
let mut extra_responses : Vec<NodeResponse<UserResponse>> = Vec::new();
|
||||
|
||||
for response in delayed_responses.iter().copied() {
|
||||
match response {
|
||||
NodeResponse::ConnectEventStarted(node_id, port) => {
|
||||
@ -199,7 +203,8 @@ where
|
||||
self.selected_node = Some(node_id);
|
||||
}
|
||||
NodeResponse::DeleteNode(node_id) => {
|
||||
self.graph.remove_node(node_id);
|
||||
let (ins, _) = self.graph.remove_node(node_id);
|
||||
extra_responses.extend(ins.into_iter().map(NodeResponse::DisconnectEvent));
|
||||
self.node_positions.remove(node_id);
|
||||
// Make sure to not leave references to old nodes hanging
|
||||
if self.selected_node.map(|x| x == node_id).unwrap_or(false) {
|
||||
@ -232,6 +237,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// Push any responses that were generated during response handling.
|
||||
// These are only informative for the end-user and need no special
|
||||
// treatment here.
|
||||
delayed_responses.extend(extra_responses);
|
||||
|
||||
/* Mouse input handling */
|
||||
|
||||
// This locks the context, so don't hold on to it for too long.
|
||||
|
||||
@ -63,18 +63,20 @@ impl<NodeData, DataType, ValueType> Graph<NodeData, DataType, ValueType> {
|
||||
output_id
|
||||
}
|
||||
|
||||
pub fn remove_node(&mut self, node_id: NodeId) {
|
||||
/// Returns the list of input and output ids that were disconnected.
|
||||
pub fn remove_node(&mut self, node_id: NodeId) -> (SVec<InputId>, SVec<OutputId>) {
|
||||
self.connections
|
||||
.retain(|i, o| !(self.outputs[*o].node == node_id || self.inputs[i].node == node_id));
|
||||
let inputs: SVec<_> = self[node_id].input_ids().collect();
|
||||
for input in inputs {
|
||||
self.inputs.remove(input);
|
||||
for input in &inputs {
|
||||
self.inputs.remove(*input);
|
||||
}
|
||||
let outputs: SVec<_> = self[node_id].output_ids().collect();
|
||||
for output in outputs {
|
||||
self.outputs.remove(output);
|
||||
for output in &outputs {
|
||||
self.outputs.remove(*output);
|
||||
}
|
||||
self.nodes.remove(node_id);
|
||||
(inputs, outputs)
|
||||
}
|
||||
|
||||
pub fn remove_connection(&mut self, input_id: InputId) -> Option<OutputId> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user