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

change non recurring DFS #52

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions egui_node_graph/src/editor_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,29 @@ where
/* Draw connections */
if let Some((_, ref locator)) = self.connection_in_progress {
let port_type = self.graph.any_param_type(*locator).unwrap();
let connection_color = port_type.data_type_color(&self.user_state);
let start_pos = port_locations[locator];
let (src_pos, dst_pos) = match locator {
AnyParameterId::Output(_) => (start_pos, cursor_pos),
AnyParameterId::Input(_) => (cursor_pos, start_pos),
};

let connection_color;
let src_pos;
let dst_pos;
match locator {
param_id @ AnyParameterId::Output(_) => {
connection_color = port_type.data_type_color(
&self.user_state,
PortConnection::ConnectionCursor(*param_id),
);
src_pos = start_pos;
dst_pos = cursor_pos;
}
param_id @ AnyParameterId::Input(_) => {
connection_color = port_type.data_type_color(
&self.user_state,
PortConnection::ConnectionCursor(*param_id),
);
src_pos = cursor_pos;
dst_pos = start_pos;
}
}
draw_connection(ui.painter(), src_pos, dst_pos, connection_color);
}

Expand All @@ -187,7 +204,8 @@ where
.graph
.any_param_type(AnyParameterId::Output(output))
.unwrap();
let connection_color = port_type.data_type_color(&self.user_state);
let connection_color = port_type
.data_type_color(&self.user_state, PortConnection::Connection(output, input));
let src_pos = port_locations[&AnyParameterId::Output(output)];
let dst_pos = port_locations[&AnyParameterId::Input(input)];
draw_connection(ui.painter(), src_pos, dst_pos, connection_color);
Expand Down Expand Up @@ -467,7 +485,7 @@ where
let port_color = if resp.hovered() {
Color32::WHITE
} else {
port_type.data_type_color(user_state)
port_type.data_type_color(user_state, PortConnection::Port(param_id))
};
ui.painter()
.circle(port_rect.center(), 5.0, port_color, Stroke::none());
Expand Down
7 changes: 7 additions & 0 deletions egui_node_graph/src/id_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ impl AnyParameterId {
}
}
}

#[derive(Clone, Copy, Debug)]
pub enum PortConnection {
Port(AnyParameterId),
ConnectionCursor(AnyParameterId),
Connection(OutputId, InputId),
}
6 changes: 5 additions & 1 deletion egui_node_graph/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ pub trait WidgetValueTrait {
/// to the user.
pub trait DataTypeTrait<UserState>: PartialEq + Eq {
/// The associated port color of this datatype
fn data_type_color(&self, user_state: &UserState) -> egui::Color32;
fn data_type_color(
&self,
user_state: &UserState,
port_connection: PortConnection,
) -> egui::Color32;

/// The name of this datatype. Return type is specified as Cow<str> because
/// some implementations will need to allocate a new string to provide an
Expand Down
Loading