62 lines
1.9 KiB
Rust
62 lines
1.9 KiB
Rust
use eframe::egui;
|
|
use ramen::{TestGraphBuilder, TestOpKind};
|
|
use ramen_egui::NodeEditor;
|
|
|
|
fn main() {
|
|
let native_options = eframe::NativeOptions::default();
|
|
eframe::run_native(
|
|
"Ramen example",
|
|
native_options,
|
|
Box::new(|cc| Box::new(Application::new(cc))),
|
|
);
|
|
}
|
|
|
|
struct Application {
|
|
editor: NodeEditor,
|
|
}
|
|
|
|
impl Application {
|
|
fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
|
cc.egui_ctx.set_visuals(egui::Visuals::dark());
|
|
|
|
let scale = 250.0;
|
|
let pos = |x, y| glam::Vec2::new(x, y) * scale;
|
|
|
|
let mut builder = TestGraphBuilder::new();
|
|
let n0 = builder.add(builder.make_literal(1.0).at(pos(1.0, 1.0)));
|
|
let n1 = builder.add(builder.make_literal(2.0).at(pos(1.0, 2.0)));
|
|
let n2 = builder.add(builder.make_op(TestOpKind::Add, n0, n1).at(pos(2.0, 1.5)));
|
|
let n3 = builder.add(builder.make_literal(4.0).at(pos(2.0, 2.5)));
|
|
let n4 = builder.add(builder.make_op(TestOpKind::Div, n2, n3).at(pos(3.0, 2.0)));
|
|
let n5 = builder.add(builder.make_op(TestOpKind::Mul, n4, n4).at(pos(4.0, 2.0)));
|
|
let _n6 = builder.add(builder.make_op(TestOpKind::Add, n5, n0).at(pos(3.0, 1.0)));
|
|
|
|
Self {
|
|
editor: NodeEditor::from_graph(builder.graph),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl eframe::App for Application {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
egui::TopBottomPanel::top("menu_panel").show(ctx, |ui| {
|
|
egui::menu::bar(ui, |ui| {
|
|
egui::widgets::global_dark_light_mode_switch(ui);
|
|
|
|
if ui.button("Undo").clicked() {
|
|
self.editor.undo();
|
|
}
|
|
|
|
if ui.button("Redo").clicked() {
|
|
self.editor.redo();
|
|
}
|
|
});
|
|
});
|
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
ui.heading("Hello world!");
|
|
self.editor.show(ui);
|
|
});
|
|
}
|
|
}
|