egui: add button to toggle showing ratsnest

This commit is contained in:
Mikolaj Wielgus 2024-05-20 21:15:57 +02:00
parent f03545124f
commit 8999fcb160
1 changed files with 28 additions and 18 deletions

View File

@ -68,6 +68,9 @@ pub struct App {
#[serde(skip)] #[serde(skip)]
from_rect: egui::emath::Rect, from_rect: egui::emath::Rect,
#[serde(skip)]
show_ratsnest: bool,
} }
impl Default for App { impl Default for App {
@ -78,6 +81,7 @@ impl Default for App {
shared_data: Default::default(), shared_data: Default::default(),
text_channel: channel(), text_channel: channel(),
from_rect: egui::Rect::from_x_y_ranges(0.0..=1000000.0, 0.0..=500000.0), from_rect: egui::Rect::from_x_y_ranges(0.0..=1000000.0, 0.0..=500000.0),
show_ratsnest: true,
} }
} }
} }
@ -267,6 +271,10 @@ impl eframe::App for App {
ui.separator(); ui.separator();
ui.toggle_value(&mut self.show_ratsnest, "Show Ratsnest");
ui.separator();
egui::widgets::global_dark_light_mode_buttons(ui); egui::widgets::global_dark_light_mode_buttons(ui);
}); });
}); });
@ -367,25 +375,27 @@ impl eframe::App for App {
painter.paint_polygon(&layout.zone(zone).shape().polygon, color) painter.paint_polygon(&layout.zone(zone).shape().polygon, color)
} }
for edge in overlay.ratsnest().graph().edge_references() { if self.show_ratsnest {
let from = overlay for edge in overlay.ratsnest().graph().edge_references() {
.ratsnest() let from = overlay
.graph() .ratsnest()
.node_weight(edge.source()) .graph()
.unwrap() .node_weight(edge.source())
.pos; .unwrap()
let to = overlay .pos;
.ratsnest() let to = overlay
.graph() .ratsnest()
.node_weight(edge.target()) .graph()
.unwrap() .node_weight(edge.target())
.pos; .unwrap()
.pos;
painter.paint_edge( painter.paint_edge(
from, from,
to, to,
egui::Stroke::new(1.0, egui::Color32::from_rgb(90, 90, 200)), egui::Stroke::new(1.0, egui::Color32::from_rgb(90, 90, 200)),
); );
}
} }
if let Some(navmesh) = &shared_data.navmesh { if let Some(navmesh) = &shared_data.navmesh {