aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs59
1 files changed, 52 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 35a3ca3..ad81cea 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,7 +19,7 @@ mod wasm;
use library::NodeIndex;
use node::{AnyNode, ConcreteNode};
-use snarl_ext::{Compilable, WithSignatures};
+use snarl_ext::{Compilable, GraphError, WithSignatures};
use types::{Dimension, FloatPrecision, ScalarType, Type};
impl Into<PinInfo> for Type {
@@ -41,12 +41,30 @@ impl Into<PinInfo> for Type {
}
}
+static ERROR_COLOR: Color32 = Color32::from_rgb(0xc0, 0x00, 0x00);
+
pub struct Viewer {
dirty: bool,
filename: Option<PathBuf>,
+ error: Option<GraphError>,
+
+ #[cfg(target_arch = "wasm32")]
save_as_dialog: Option<String>,
}
+impl Default for Viewer {
+ fn default() -> Self {
+ Self {
+ dirty: true,
+ filename: None,
+ error: None,
+
+ #[cfg(target_arch = "wasm32")]
+ save_as_dialog: None,
+ }
+ }
+}
+
impl SnarlViewer<AnyNode> for Viewer {
#[inline]
fn connect(&mut self, from: &OutPin, to: &InPin, snarl: &mut Snarl<AnyNode>) {
@@ -126,6 +144,23 @@ impl SnarlViewer<AnyNode> for Viewer {
}
}
+ fn node_frame(
+ &mut self,
+ mut default: egui::Frame,
+ node: NodeId,
+ _inputs: &[InPin],
+ _outputs: &[OutPin],
+ _snarl: &Snarl<AnyNode>,
+ ) -> egui::Frame {
+ if Some(node) == self.error.and_then(|e| e.1) {
+ default.stroke = egui::Stroke {
+ width: 2.0,
+ color: ERROR_COLOR,
+ };
+ }
+
+ default
+ }
fn has_graph_menu(&mut self, _pos: egui::Pos2, _snarl: &mut Snarl<AnyNode>) -> bool {
true
}
@@ -133,6 +168,7 @@ impl SnarlViewer<AnyNode> for Viewer {
fn show_graph_menu(&mut self, pos: egui::Pos2, ui: &mut Ui, snarl: &mut Snarl<AnyNode>) {
if let Some(node) = AnyNode::pick_node(ui) {
snarl.insert_node(pos, node);
+ self.dirty = true;
ui.close();
}
}
@@ -152,6 +188,7 @@ impl SnarlViewer<AnyNode> for Viewer {
ui.label("Node menu");
if ui.button("Remove").clicked() {
snarl.remove_node(node);
+ self.dirty = true;
ui.close();
}
}
@@ -221,11 +258,7 @@ impl App {
App {
snarl,
- viewer: Viewer {
- dirty: true,
- filename: None,
- save_as_dialog: None,
- },
+ viewer: Default::default(),
preview: preview::Preview::new(cx).expect("Failed to init preview"),
}
}
@@ -371,10 +404,13 @@ impl eframe::App for App {
match self.snarl.compile(&mut buf) {
Ok(()) => {
info!("{}", buf);
+ self.viewer.error = None;
Some(buf)
}
Err(x) => {
- error!("Error compiling: {}", x);
+ error!("Error compiling: {:?}", x);
+ self.viewer.dirty = false;
+ self.viewer.error = Some(x);
None
}
}
@@ -388,6 +424,15 @@ impl eframe::App for App {
self.viewer.dirty = false;
}
});
+
+ if let Some(err) = &self.viewer.error {
+ let message = if let Some(node) = err.1 {
+ format!("Error in node {}: {:?}", node.0, err.0)
+ } else {
+ format!("Error while compiling: {:?}", err.0)
+ };
+ ui.colored_label(Color32::from_rgb(0xff, 0, 0), message);
+ }
});
egui::CentralPanel::default().show(ctx, |ui| {