From ad3c9b13835711ff53c29ab303d93ff82f2607c4 Mon Sep 17 00:00:00 2001 From: IsseW Date: Fri, 27 May 2022 18:45:58 +0200 Subject: [PATCH 1/2] widget response --- egui_node_graph/src/editor_ui.rs | 12 +++++++++--- egui_node_graph/src/traits.rs | 3 ++- egui_node_graph_example/src/app.rs | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index ab37351..c3f2fd4 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -52,7 +52,7 @@ where ValueType = ValueType, >, UserResponse: UserResponseTrait, - ValueType: WidgetValueTrait, + ValueType: WidgetValueTrait, NodeTemplate: NodeTemplateTrait, DataType: DataTypeTrait, @@ -297,7 +297,7 @@ where ValueType = ValueType, >, UserResponse: UserResponseTrait, - ValueType: WidgetValueTrait, + ValueType: WidgetValueTrait, DataType: DataTypeTrait, { pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0]; @@ -373,7 +373,13 @@ where if self.graph.connection(param_id).is_some() { ui.label(param_name); } else { - self.graph[param_id].value.value_widget(¶m_name, ui); + responses.extend( + self.graph[param_id] + .value + .value_widget(¶m_name, ui) + .into_iter() + .map(NodeResponse::User), + ); } let height_after = ui.min_rect().bottom(); input_port_heights.push((height_before + height_after) / 2.0); diff --git a/egui_node_graph/src/traits.rs b/egui_node_graph/src/traits.rs index 5be8908..7665346 100644 --- a/egui_node_graph/src/traits.rs +++ b/egui_node_graph/src/traits.rs @@ -4,7 +4,8 @@ use super::*; /// [`Graph`]. The trait allows drawing custom inline widgets for the different /// types of the node graph. pub trait WidgetValueTrait { - fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui); + type Response; + fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec; } /// This trait must be implemented by the `DataType` generic parameter of the diff --git a/egui_node_graph_example/src/app.rs b/egui_node_graph_example/src/app.rs index 6e0379a..147b7ca 100644 --- a/egui_node_graph_example/src/app.rs +++ b/egui_node_graph_example/src/app.rs @@ -250,7 +250,8 @@ impl NodeTemplateIter for AllMyNodeTemplates { } impl WidgetValueTrait for MyValueType { - fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) { + type Response = MyResponse; + fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec { // This trait is used to tell the library which UI to display for the // inline parameter widgets. match self { @@ -270,6 +271,8 @@ impl WidgetValueTrait for MyValueType { }); } } + // This allows you to retorn your responses from the inline widgets. + Vec::new() } } From 6174e14a0f3c287e7ea997afb357a2d5404f3591 Mon Sep 17 00:00:00 2001 From: IsseW Date: Tue, 31 May 2022 11:03:13 +0200 Subject: [PATCH 2/2] add doc comment, and fix typo --- egui_node_graph/src/traits.rs | 4 ++++ egui_node_graph_example/src/app.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/egui_node_graph/src/traits.rs b/egui_node_graph/src/traits.rs index 7665346..376d870 100644 --- a/egui_node_graph/src/traits.rs +++ b/egui_node_graph/src/traits.rs @@ -5,6 +5,10 @@ use super::*; /// types of the node graph. pub trait WidgetValueTrait { type Response; + /// This method will be called for each input parameter with a widget. The + /// return value is a vector of custom response objects which can be used + /// to implement handling of side effects. If unsure, the response Vec can + /// be empty. fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec; } diff --git a/egui_node_graph_example/src/app.rs b/egui_node_graph_example/src/app.rs index 147b7ca..1c2c812 100644 --- a/egui_node_graph_example/src/app.rs +++ b/egui_node_graph_example/src/app.rs @@ -271,7 +271,7 @@ impl WidgetValueTrait for MyValueType { }); } } - // This allows you to retorn your responses from the inline widgets. + // This allows you to return your responses from the inline widgets. Vec::new() } }