egui_graphs basic example
crate is ready
This commit is contained in:
commit
98f2698ee6
4 changed files with 4290 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
4233
Cargo.lock
generated
Normal file
4233
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "brainwave"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
eframe = "0.32"
|
||||
egui = "0.32"
|
||||
egui_graphs = "0.28.0"
|
||||
petgraph = "0.8.3"
|
46
src/main.rs
Normal file
46
src/main.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use eframe::{App, CreationContext, NativeOptions, run_native};
|
||||
use egui::Context;
|
||||
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 update(&mut self, ctx: &Context, _: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue