diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 2258fba..75a5df4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![allow(clippy::use_self)] +use log::*; use std::collections::HashMap; use eframe::{App, CreationContext}; @@ -12,6 +13,8 @@ use egui_snarl::{ }, }; +mod preview; + const STRING_COLOR: Color32 = Color32::from_rgb(0x00, 0xb0, 0x00); const NUMBER_COLOR: Color32 = Color32::from_rgb(0xb0, 0x00, 0x00); const IMAGE_COLOR: Color32 = Color32::from_rgb(0xb0, 0x00, 0xb0); @@ -928,7 +931,7 @@ impl Expr { pub struct DemoApp { snarl: Snarl<DemoNode>, - style: SnarlStyle, + preview: preview::Custom3d, } const fn default_style() -> SnarlStyle { @@ -975,15 +978,12 @@ impl DemoApp { }); // let snarl = Snarl::new(); - let style = cx.storage.map_or_else(default_style, |storage| { - storage - .get_string("style") - .and_then(|style| serde_json::from_str(&style).ok()) - .unwrap_or_else(default_style) - }); - // let style = SnarlStyle::new(); + info!("about to init"); - DemoApp { snarl, style } + DemoApp { + snarl, + preview: preview::Custom3d::new(cx).expect("Failed to init preview"), + } } } @@ -1011,13 +1011,7 @@ impl App for DemoApp { }); }); - egui::SidePanel::left("style").show(ctx, |ui| { - egui::ScrollArea::vertical().show(ui, |ui| { - egui_probe::Probe::new(&mut self.style).show(ui); - }); - }); - - egui::SidePanel::right("selected-list").show(ctx, |ui| { + egui::SidePanel::left("selected-list").show(ctx, |ui| { egui::ScrollArea::vertical().show(ui, |ui| { ui.strong("Selected nodes"); @@ -1049,10 +1043,18 @@ impl App for DemoApp { }); }); + egui::SidePanel::right("preview").show(ctx, |ui| { + egui::ScrollArea::vertical().show(ui, |ui| { + egui::Frame::canvas(ui.style()).show(ui, |ui| { + self.preview.custom_painting(ui); + }); + }); + }); + egui::CentralPanel::default().show(ctx, |ui| { SnarlWidget::new() .id(Id::new("snarl-demo")) - .style(self.style) + .style(default_style()) .show(&mut self.snarl, &mut DemoViewer, ui); }); } @@ -1060,9 +1062,6 @@ impl App for DemoApp { fn save(&mut self, storage: &mut dyn eframe::Storage) { let snarl = serde_json::to_string(&self.snarl).unwrap(); storage.set_string("snarl", snarl); - - let style = serde_json::to_string(&self.style).unwrap(); - storage.set_string("style", style); } } @@ -1073,6 +1072,7 @@ fn main() -> eframe::Result<()> { viewport: egui::ViewportBuilder::default() .with_inner_size([400.0, 300.0]) .with_min_inner_size([300.0, 220.0]), + renderer: eframe::Renderer::Wgpu, ..Default::default() }; @@ -1095,6 +1095,8 @@ fn get_canvas_element() -> Option<web_sys::HtmlCanvasElement> { // When compiling to web using trunk: #[cfg(target_arch = "wasm32")] fn main() { + eframe::WebLogger::init(log::LevelFilter::Debug).ok(); + let canvas = get_canvas_element().expect("Failed to find canvas with id 'egui_snarl_demo'"); let web_options = eframe::WebOptions::default(); |
