Skip to content

Commit

Permalink
Fixed connections and close buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
kkngsm committed May 27, 2022
1 parent 303af6a commit fffdaeb
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions egui_node_graph/src/editor_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,24 @@ where

/* Draw connections */

let connection_color = if ui.visuals().dark_mode {
color_from_hex("#efefef").unwrap()
} else {
color_from_hex("#bbbbbb").unwrap()
};
if let Some((_, ref locator)) = self.connection_in_progress {
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),
};
draw_connection(ui.painter(), src_pos, dst_pos);
draw_connection(ui.painter(), src_pos, dst_pos, connection_color);
}

for (input, output) in self.graph.iter_connections() {
let src_pos = port_locations[&AnyParameterId::Output(output)];
let dst_pos = port_locations[&AnyParameterId::Input(input)];
draw_connection(ui.painter(), src_pos, dst_pos);
draw_connection(ui.painter(), src_pos, dst_pos, connection_color);
}

/* Handle responses from drawing nodes */
Expand Down Expand Up @@ -265,11 +270,8 @@ where
}
}

fn draw_connection(painter: &Painter, src_pos: Pos2, dst_pos: Pos2) {
let connection_stroke = egui::Stroke {
width: 5.0,
color: color_from_hex("#efefef").unwrap(),
};
fn draw_connection(painter: &Painter, src_pos: Pos2, dst_pos: Pos2, color: Color32) {
let connection_stroke = egui::Stroke { width: 5.0, color };

let control_scale = ((dst_pos.x - src_pos.x) / 2.0).max(30.0);
let src_control = src_pos + Vec2::X * control_scale;
Expand Down Expand Up @@ -319,6 +321,7 @@ where
) -> Vec<NodeResponse<UserResponse>> {
let margin = egui::vec2(15.0, 5.0);
let mut responses = Vec::new();

let background_color;
let titlebar_color;
let text_color;
Expand All @@ -329,7 +332,7 @@ where
} else {
background_color = color_from_hex("#ffffff").unwrap();
titlebar_color = background_color.lighten(0.8);
text_color = color_from_hex("#000000").unwrap();
text_color = color_from_hex("#505050").unwrap();
}

ui.visuals_mut().widgets.noninteractive.fg_stroke = Stroke::new(2.0, text_color);
Expand Down Expand Up @@ -607,12 +610,25 @@ where
let rect = Rect::from_center_size(position, vec2(size, size));
let resp = ui.allocate_rect(rect, Sense::click());

let dark_mode = ui.visuals().dark_mode;
let color = if resp.clicked() {
color_from_hex("#ffffff").unwrap()
if dark_mode {
color_from_hex("#ffffff").unwrap()
} else {
color_from_hex("#000000").unwrap()
}
} else if resp.hovered() {
color_from_hex("#dddddd").unwrap()
if dark_mode {
color_from_hex("#dddddd").unwrap()
} else {
color_from_hex("#222222").unwrap()
}
} else {
color_from_hex("#aaaaaa").unwrap()
if dark_mode {
color_from_hex("#aaaaaa").unwrap()
} else {
color_from_hex("#555555").unwrap()
}
};
let stroke = Stroke {
width: stroke_width,
Expand Down

0 comments on commit fffdaeb

Please sign in to comment.