diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 9b0c7a0..e168c34 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -47,7 +47,15 @@ pub enum NodeResponse pub struct GraphResponse { pub node_responses: Vec>, } - +impl Default + for GraphResponse +{ + fn default() -> Self { + Self { + node_responses: Default::default(), + } + } +} pub struct GraphNodeWidget<'a, NodeData, DataType, ValueType> { pub position: &'a mut Pos2, pub graph: &'a mut Graph, diff --git a/egui_node_graph/src/ui_state.rs b/egui_node_graph/src/ui_state.rs index 43ceba5..7d21303 100644 --- a/egui_node_graph/src/ui_state.rs +++ b/egui_node_graph/src/ui_state.rs @@ -4,7 +4,7 @@ use std::marker::PhantomData; #[cfg(feature = "persistence")] use serde::{Deserialize, Serialize}; -#[derive(Copy, Clone)] +#[derive(Default, Copy, Clone)] #[cfg_attr(feature = "persistence", derive(Serialize, Deserialize))] pub struct PanZoom { pub pan: egui::Vec2, @@ -38,17 +38,27 @@ impl { pub fn new(default_zoom: f32) -> Self { Self { - graph: Graph::new(), - node_order: Vec::new(), - connection_in_progress: None, - selected_node: None, - node_positions: SecondaryMap::new(), - node_finder: None, pan_zoom: PanZoom { pan: egui::Vec2::ZERO, zoom: default_zoom, }, - _user_state: PhantomData, + ..Default::default() + } + } +} +impl Default + for GraphEditorState +{ + fn default() -> Self { + Self { + graph: Default::default(), + node_order: Default::default(), + connection_in_progress: Default::default(), + selected_node: Default::default(), + node_positions: Default::default(), + node_finder: Default::default(), + pan_zoom: Default::default(), + _user_state: Default::default(), } } } diff --git a/egui_node_graph_example/src/app.rs b/egui_node_graph_example/src/app.rs index 395d1aa..0bad5c9 100644 --- a/egui_node_graph_example/src/app.rs +++ b/egui_node_graph_example/src/app.rs @@ -341,6 +341,7 @@ type MyGraph = Graph; type MyEditorState = GraphEditorState; +#[derive(Default)] pub struct NodeGraphExample { // The `GraphEditorState` is the top-level object. You "register" all your // custom types by specifying it as its generic parameters. @@ -349,14 +350,6 @@ pub struct NodeGraphExample { user_state: MyGraphState, } -impl Default for NodeGraphExample { - fn default() -> Self { - Self { - state: GraphEditorState::new(1.0), - user_state: MyGraphState::default(), - } - } -} #[cfg(feature = "persistence")] const PERSISTENCE_KEY: &str = "egui_node_graph"; @@ -368,7 +361,7 @@ impl NodeGraphExample { let state = cc .storage .and_then(|storage| eframe::get_value(storage, PERSISTENCE_KEY)) - .unwrap_or_else(|| GraphEditorState::new(0.0)); + .unwrap_or_default(); Self { state, user_state: MyGraphState::default(),