Skip to content

Commit

Permalink
Edges selection in configurable example
Browse files Browse the repository at this point in the history
  • Loading branch information
blitzarx1 committed Nov 28, 2023
1 parent 2b93ab8 commit d2612a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions examples/configurable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub struct ConfigurableApp {
settings_navigation: SettingsNavigation,
settings_style: SettingsStyle,

selected_nodes: Vec<Node<(), (), Directed, DefaultIx>>,
selected_edges: Vec<Edge<(), (), Directed>>,
selected_nodes: Vec<NodeIndex>,
selected_edges: Vec<EdgeIndex>,
last_events: Vec<String>,

simulation_stopped: bool,
Expand Down Expand Up @@ -128,6 +128,7 @@ impl ConfigurableApp {
/// If node or edge is selected it is added to the corresponding selected field in `self`.
fn sync_graph_with_simulation(&mut self) {
self.selected_nodes = vec![];
self.selected_edges = vec![];

let g_indices = self.g.g.node_indices().collect::<Vec<_>>();
for g_n_idx in &g_indices {
Expand All @@ -138,7 +139,14 @@ impl ConfigurableApp {
g_n.set_location(Pos2::new(loc.x, loc.y));

if g_n.selected() {
self.selected_nodes.push(g_n.clone());
self.selected_nodes.push(*g_n_idx);
}
}

for g_e_idx in self.g.g.edge_indices() {
let g_e = self.g.g.edge_weight(g_e_idx).unwrap();
if g_e.selected() {
self.selected_edges.push(g_e_idx);
}
}

Expand Down Expand Up @@ -489,10 +497,10 @@ impl ConfigurableApp {
CollapsingHeader::new("Selected").default_open(true).show(ui, |ui| {
ScrollArea::vertical().auto_shrink([false, true]).max_height(200.).show(ui, |ui| {
self.selected_nodes.iter().for_each(|node| {
ui.label(format!("{:?}", node));
ui.label(format!("{node:?}"));
});
self.selected_edges.iter().for_each(|edge| {
ui.label(format!("{:?}", edge));
ui.label(format!("{edge:?}"));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion examples/label_change/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl BasicApp {

fn read_data(&mut self) {
if let Some((selected_idx, _)) = self.g.nodes_iter().find(|(_, n)| n.selected()) {
self.selected_node = Some(selected_idx.clone());
self.selected_node = Some(selected_idx);
self.label_input = self.g.node(selected_idx).unwrap().label();
}
}
Expand Down

0 comments on commit d2612a3

Please sign in to comment.