diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 710a16e..a63f237 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -82,7 +82,7 @@ where &mut self, ui: &mut Ui, all_kinds: impl NodeTemplateIter, - user_state: &UserState, + user_state: &mut UserState, ) -> GraphResponse { // This causes the graph editor to use as much free space as it can. // (so for windows it will use up to the resizeably set limit @@ -357,7 +357,7 @@ where pub fn show( self, ui: &mut Ui, - user_state: &UserState, + user_state: &mut UserState, ) -> Vec> { let mut child_ui = ui.child_ui_with_id_source( Rect::from_min_size(*self.position + self.pan, Self::MAX_NODE_SIZE.into()), @@ -373,7 +373,7 @@ where fn show_graph_node( self, ui: &mut Ui, - user_state: &UserState, + user_state: &mut UserState, ) -> Vec> { let margin = egui::vec2(15.0, 5.0); let mut responses = Vec::>::new(); @@ -468,7 +468,7 @@ where ui: &mut Ui, graph: &Graph, node_id: NodeId, - user_state: &UserState, + user_state: &mut UserState, port_pos: Pos2, responses: &mut Vec>, param_id: AnyParameterId, diff --git a/egui_node_graph/src/traits.rs b/egui_node_graph/src/traits.rs index ccf4388..8b90191 100644 --- a/egui_node_graph/src/traits.rs +++ b/egui_node_graph/src/traits.rs @@ -17,7 +17,7 @@ pub trait WidgetValueTrait { /// to the user. pub trait DataTypeTrait: PartialEq + Eq { /// The associated port color of this datatype - fn data_type_color(&self, user_state: &UserState) -> egui::Color32; + fn data_type_color(&self, user_state: &mut UserState) -> egui::Color32; /// The name of this datatype. Return type is specified as Cow because /// some implementations will need to allocate a new string to provide an @@ -71,7 +71,7 @@ where ui: &mut egui::Ui, node_id: NodeId, graph: &Graph, - user_state: &Self::UserState, + user_state: &mut Self::UserState, ) -> Vec> where Self::Response: UserResponseTrait; @@ -83,7 +83,7 @@ where _ui: &egui::Ui, _node_id: NodeId, _graph: &Graph, - _user_state: &Self::UserState, + _user_state: &mut Self::UserState, ) -> Option { None } @@ -126,7 +126,7 @@ pub trait NodeTemplateTrait: Clone { fn build_node( &self, graph: &mut Graph, - user_state: &Self::UserState, + user_state: &mut Self::UserState, node_id: NodeId, ); } diff --git a/egui_node_graph_example/src/app.rs b/egui_node_graph_example/src/app.rs index 7a04a80..395d1aa 100644 --- a/egui_node_graph_example/src/app.rs +++ b/egui_node_graph_example/src/app.rs @@ -95,7 +95,7 @@ pub struct MyGraphState { // A trait for the data types, to tell the library how to display them impl DataTypeTrait for MyDataType { - fn data_type_color(&self, _user_state: &MyGraphState) -> egui::Color32 { + fn data_type_color(&self, _user_state: &mut MyGraphState) -> egui::Color32 { match self { MyDataType::Scalar => egui::Color32::from_rgb(38, 109, 211), MyDataType::Vec2 => egui::Color32::from_rgb(238, 207, 109), @@ -143,7 +143,7 @@ impl NodeTemplateTrait for MyNodeTemplate { fn build_node( &self, graph: &mut Graph, - _user_state: &Self::UserState, + _user_state: &mut Self::UserState, node_id: NodeId, ) { // The nodes are created empty by default. This function needs to take @@ -300,7 +300,7 @@ impl NodeDataTrait for MyNodeData { ui: &mut egui::Ui, node_id: NodeId, _graph: &Graph, - user_state: &Self::UserState, + user_state: &mut Self::UserState, ) -> Vec> where MyResponse: UserResponseTrait, @@ -394,7 +394,7 @@ impl eframe::App for NodeGraphExample { let graph_response = egui::CentralPanel::default() .show(ctx, |ui| { self.state - .draw_graph_editor(ui, AllMyNodeTemplates, &self.user_state) + .draw_graph_editor(ui, AllMyNodeTemplates, &mut self.user_state) }) .inner; for node_response in graph_response.node_responses {