Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Make DisconnectEvent specify both endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
gmorenz committed May 26, 2022
1 parent 997c4d3 commit 1e76f94
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions egui_node_graph/src/editor_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub enum NodeResponse<UserResponse: UserResponseTrait> {
CreatedNode(NodeId),
SelectNode(NodeId),
DeleteNode(NodeId),
DisconnectEvent(InputId),
DisconnectEvent {
output: OutputId,
input: InputId,
},
/// Emitted when a node is interacted with, and should be raised
RaiseNode(NodeId),
User(UserResponse),
Expand Down Expand Up @@ -196,15 +199,11 @@ where
}
self.node_order.retain(|id| *id != node_id);
}
NodeResponse::DisconnectEvent(input_id) => {
let corresp_output = self
.graph
.connection(input_id)
.expect("Connection data should be valid");
let other_node = self.graph.get_input(input_id).node();
self.graph.remove_connection(input_id);
NodeResponse::DisconnectEvent { input, output } => {
let other_node = self.graph.get_input(input).node();
self.graph.remove_connection(input);
self.connection_in_progress =
Some((other_node, AnyParameterId::Output(corresp_output)));
Some((other_node, AnyParameterId::Output(output)));
}
NodeResponse::RaiseNode(node_id) => {
let old_pos = self
Expand Down Expand Up @@ -371,7 +370,7 @@ where
param_id: AnyParameterId,
port_locations: &mut PortLocations,
ongoing_drag: Option<(NodeId, AnyParameterId)>,
is_connected_input: bool,
connected_to_output: Option<OutputId>,
) where
DataType: DataTypeTrait,
UserResponse: UserResponseTrait,
Expand All @@ -396,8 +395,11 @@ where
.circle(port_rect.center(), 5.0, port_color, Stroke::none());

if resp.drag_started() {
if is_connected_input {
responses.push(NodeResponse::DisconnectEvent(param_id.assume_input()));
if let Some(output) = connected_to_output {
responses.push(NodeResponse::DisconnectEvent {
output,
input: param_id.assume_input(),
});
} else {
responses.push(NodeResponse::ConnectEventStarted(node_id, param_id));
}
Expand Down Expand Up @@ -445,7 +447,7 @@ where
AnyParameterId::Input(*param),
self.port_locations,
self.ongoing_drag,
self.graph.connection(*param).is_some(),
self.graph.connection(*param),
);
}
}
Expand All @@ -466,7 +468,7 @@ where
AnyParameterId::Output(*param),
self.port_locations,
self.ongoing_drag,
false,
None,
);
}

Expand Down

0 comments on commit 1e76f94

Please sign in to comment.