-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathbasic.rs
More file actions
45 lines (37 loc) · 974 Bytes
/
basic.rs
File metadata and controls
45 lines (37 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use eframe::{run_native, App, CreationContext, NativeOptions};
use egui_graphs::{DefaultGraphView, Graph};
use petgraph::stable_graph::StableGraph;
pub struct BasicApp {
g: Graph,
}
impl BasicApp {
fn new(_: &CreationContext<'_>) -> Self {
let g = generate_graph();
Self { g: Graph::from(&g) }
}
}
impl App for BasicApp {
fn ui(&mut self, ui: &mut egui::Ui, _: &mut eframe::Frame) {
egui::CentralPanel::default().show_inside(ui, |ui| {
ui.add(&mut DefaultGraphView::new(&mut self.g));
});
}
}
fn generate_graph() -> StableGraph<(), ()> {
let mut g = StableGraph::new();
let a = g.add_node(());
let b = g.add_node(());
let c = g.add_node(());
g.add_edge(a, b, ());
g.add_edge(b, c, ());
g.add_edge(c, a, ());
g
}
fn main() {
run_native(
"basic",
NativeOptions::default(),
Box::new(|cc| Ok(Box::new(BasicApp::new(cc)))),
)
.unwrap();
}