mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-11 22:08:28 +00:00
Fixed connections and close buttons
This commit is contained in:
parent
303af6ac14
commit
fffdaebe8b
@ -151,19 +151,24 @@ where
|
|||||||
|
|
||||||
/* Draw connections */
|
/* 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 {
|
if let Some((_, ref locator)) = self.connection_in_progress {
|
||||||
let start_pos = port_locations[locator];
|
let start_pos = port_locations[locator];
|
||||||
let (src_pos, dst_pos) = match locator {
|
let (src_pos, dst_pos) = match locator {
|
||||||
AnyParameterId::Output(_) => (start_pos, cursor_pos),
|
AnyParameterId::Output(_) => (start_pos, cursor_pos),
|
||||||
AnyParameterId::Input(_) => (cursor_pos, start_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() {
|
for (input, output) in self.graph.iter_connections() {
|
||||||
let src_pos = port_locations[&AnyParameterId::Output(output)];
|
let src_pos = port_locations[&AnyParameterId::Output(output)];
|
||||||
let dst_pos = port_locations[&AnyParameterId::Input(input)];
|
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 */
|
/* Handle responses from drawing nodes */
|
||||||
@ -265,11 +270,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_connection(painter: &Painter, src_pos: Pos2, dst_pos: Pos2) {
|
fn draw_connection(painter: &Painter, src_pos: Pos2, dst_pos: Pos2, color: Color32) {
|
||||||
let connection_stroke = egui::Stroke {
|
let connection_stroke = egui::Stroke { width: 5.0, color };
|
||||||
width: 5.0,
|
|
||||||
color: color_from_hex("#efefef").unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let control_scale = ((dst_pos.x - src_pos.x) / 2.0).max(30.0);
|
let control_scale = ((dst_pos.x - src_pos.x) / 2.0).max(30.0);
|
||||||
let src_control = src_pos + Vec2::X * control_scale;
|
let src_control = src_pos + Vec2::X * control_scale;
|
||||||
@ -319,6 +321,7 @@ where
|
|||||||
) -> Vec<NodeResponse<UserResponse>> {
|
) -> Vec<NodeResponse<UserResponse>> {
|
||||||
let margin = egui::vec2(15.0, 5.0);
|
let margin = egui::vec2(15.0, 5.0);
|
||||||
let mut responses = Vec::new();
|
let mut responses = Vec::new();
|
||||||
|
|
||||||
let background_color;
|
let background_color;
|
||||||
let titlebar_color;
|
let titlebar_color;
|
||||||
let text_color;
|
let text_color;
|
||||||
@ -329,7 +332,7 @@ where
|
|||||||
} else {
|
} else {
|
||||||
background_color = color_from_hex("#ffffff").unwrap();
|
background_color = color_from_hex("#ffffff").unwrap();
|
||||||
titlebar_color = background_color.lighten(0.8);
|
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);
|
ui.visuals_mut().widgets.noninteractive.fg_stroke = Stroke::new(2.0, text_color);
|
||||||
@ -607,12 +610,25 @@ where
|
|||||||
let rect = Rect::from_center_size(position, vec2(size, size));
|
let rect = Rect::from_center_size(position, vec2(size, size));
|
||||||
let resp = ui.allocate_rect(rect, Sense::click());
|
let resp = ui.allocate_rect(rect, Sense::click());
|
||||||
|
|
||||||
|
let dark_mode = ui.visuals().dark_mode;
|
||||||
let color = if resp.clicked() {
|
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() {
|
} else if resp.hovered() {
|
||||||
color_from_hex("#dddddd").unwrap()
|
if dark_mode {
|
||||||
|
color_from_hex("#dddddd").unwrap()
|
||||||
|
} else {
|
||||||
|
color_from_hex("#222222").unwrap()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
color_from_hex("#aaaaaa").unwrap()
|
if dark_mode {
|
||||||
|
color_from_hex("#aaaaaa").unwrap()
|
||||||
|
} else {
|
||||||
|
color_from_hex("#555555").unwrap()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let stroke = Stroke {
|
let stroke = Stroke {
|
||||||
width: stroke_width,
|
width: stroke_width,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user