From a91dbce1c4b9f105f5ab1e5ef08e4c160dc3ad85 Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Sun, 29 Dec 2024 23:30:52 -0800 Subject: [PATCH 1/8] try right --- egui_node_graph2/src/editor_ui.rs | 61 ++++++++++++++++--------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index 9c3323b..465f69b 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -709,6 +709,38 @@ where title_height = ui.min_size().y; // First pass: Draw the inner fields. Compute port heights + let outputs = self.graph[self.node_id].outputs.clone(); + for (param_name, param_id) in outputs { + let height_before = ui.min_rect().bottom(); + + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + responses.extend( + self.graph[self.node_id] + .user_data + .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) + .into_iter(), + ); + }); + + self.graph[self.node_id].user_data.separator( + ui, + self.node_id, + AnyParameterId::Output(param_id), + self.graph, + user_state, + ); + + let height_after = ui.min_rect().bottom(); + output_port_heights.push((height_before + height_after) / 2.0); + } + + responses.extend(self.graph[self.node_id].user_data.bottom_ui( + ui, + self.node_id, + self.graph, + user_state, + )); + let inputs = self.graph[self.node_id].inputs.clone(); for (param_name, param_id) in inputs { if self.graph[param_id].shown_inline { @@ -783,35 +815,6 @@ where input_port_heights.push((height_before + height_after) / 2.0); } } - - let outputs = self.graph[self.node_id].outputs.clone(); - for (param_name, param_id) in outputs { - let height_before = ui.min_rect().bottom(); - responses.extend( - self.graph[self.node_id] - .user_data - .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) - .into_iter(), - ); - - self.graph[self.node_id].user_data.separator( - ui, - self.node_id, - AnyParameterId::Output(param_id), - self.graph, - user_state, - ); - - let height_after = ui.min_rect().bottom(); - output_port_heights.push((height_before + height_after) / 2.0); - } - - responses.extend(self.graph[self.node_id].user_data.bottom_ui( - ui, - self.node_id, - self.graph, - user_state, - )); }); // Second pass, iterate again to draw the ports. This happens outside From 1de640123744a7f44be26c5b9e18486d149587ea Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Sun, 29 Dec 2024 23:32:24 -0800 Subject: [PATCH 2/8] try fix --- egui_node_graph2/src/editor_ui.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index 465f69b..7247614 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -713,14 +713,19 @@ where for (param_name, param_id) in outputs { let height_before = ui.min_rect().bottom(); - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - responses.extend( - self.graph[self.node_id] - .user_data - .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) - .into_iter(), - ); - }); + let response = ui.scope(|ui| { + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + responses.extend( + self.graph[self.node_id] + .user_data + .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) + .into_iter(), + ); + }); + }).response; + + let rect = response.rect; + output_port_heights.push(rect.center().y); self.graph[self.node_id].user_data.separator( ui, @@ -729,9 +734,6 @@ where self.graph, user_state, ); - - let height_after = ui.min_rect().bottom(); - output_port_heights.push((height_before + height_after) / 2.0); } responses.extend(self.graph[self.node_id].user_data.bottom_ui( From 6987d91a2e371bdf9c8073051b406cafc0bf2590 Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Sun, 29 Dec 2024 23:33:44 -0800 Subject: [PATCH 3/8] try fix2 --- egui_node_graph2/src/editor_ui.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index 7247614..374891a 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -713,19 +713,16 @@ where for (param_name, param_id) in outputs { let height_before = ui.min_rect().bottom(); - let response = ui.scope(|ui| { - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - responses.extend( - self.graph[self.node_id] - .user_data - .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) - .into_iter(), - ); - }); - }).response; - - let rect = response.rect; - output_port_heights.push(rect.center().y); + ui.horizontal(|ui| { + ui.allocate_space(ui.available_size()); // Push everything to the right + + responses.extend( + self.graph[self.node_id] + .user_data + .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) + .into_iter(), + ); + }); self.graph[self.node_id].user_data.separator( ui, @@ -734,6 +731,9 @@ where self.graph, user_state, ); + + let height_after = ui.min_rect().bottom(); + output_port_heights.push((height_before + height_after) / 2.0); } responses.extend(self.graph[self.node_id].user_data.bottom_ui( From c961186dd484b9f6ff0eadd740c073fc22de0b32 Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Sun, 29 Dec 2024 23:40:44 -0800 Subject: [PATCH 4/8] Replace deprecated egui methods. Fix example --- egui_node_graph2/src/editor_ui.rs | 10 +++------- egui_node_graph2/src/graph_impls.rs | 4 ++-- egui_node_graph2_example/src/app.rs | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index 374891a..aa11981 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -617,12 +617,8 @@ where ui: &mut Ui, 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()), - Layout::default(), - self.node_id, - None, - ); + let max_rect = Rect::from_min_size(*self.position + self.pan, Self::MAX_NODE_SIZE.into()); + let mut child_ui = ui.new_child(UiBuilder::new().max_rect(max_rect).id_salt(self.node_id)); Self::show_graph_node(self, pan_zoom, &mut child_ui, user_state) } @@ -666,7 +662,7 @@ where inner_rect.max.x = inner_rect.max.x.max(inner_rect.min.x); inner_rect.max.y = inner_rect.max.y.max(inner_rect.min.y); - let mut child_ui = ui.child_ui(inner_rect, *ui.layout(), None); + let mut child_ui = ui.new_child(UiBuilder::new().max_rect(inner_rect).layout(*ui.layout())); // Get interaction rect from memory, it may expand after the window response on resize. let interaction_rect = ui diff --git a/egui_node_graph2/src/graph_impls.rs b/egui_node_graph2/src/graph_impls.rs index a117b95..9ab0e3e 100644 --- a/egui_node_graph2/src/graph_impls.rs +++ b/egui_node_graph2/src/graph_impls.rs @@ -241,14 +241,14 @@ impl Node { pub fn inputs<'a, DataType, DataValue>( &'a self, graph: &'a Graph, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { self.input_ids().map(|id| graph.get_input(id)) } pub fn outputs<'a, DataType, DataValue>( &'a self, graph: &'a Graph, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { self.output_ids().map(|id| graph.get_output(id)) } diff --git a/egui_node_graph2_example/src/app.rs b/egui_node_graph2_example/src/app.rs index e5daf74..aeeb756 100644 --- a/egui_node_graph2_example/src/app.rs +++ b/egui_node_graph2_example/src/app.rs @@ -412,7 +412,7 @@ impl eframe::App for NodeGraphExample { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::TopBottomPanel::top("top").show(ctx, |ui| { egui::menu::bar(ui, |ui| { - egui::widgets::global_dark_light_mode_switch(ui); + egui::widgets::global_theme_preference_switch(ui); }); }); let graph_response = egui::CentralPanel::default() From e19ce71bf00724089661329708af9aa26bd2af20 Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Sun, 29 Dec 2024 23:42:59 -0800 Subject: [PATCH 5/8] . --- egui_node_graph2/src/editor_ui.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index aa11981..b4a8daf 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -710,7 +710,7 @@ where let height_before = ui.min_rect().bottom(); ui.horizontal(|ui| { - ui.allocate_space(ui.available_size()); // Push everything to the right + ui.allocate_space(ui.available_size()); responses.extend( self.graph[self.node_id] From e74fe3a1f8daa8864c163c76839a09ae793cfce7 Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Sun, 29 Dec 2024 23:44:09 -0800 Subject: [PATCH 6/8] . --- egui_node_graph2/src/graph_impls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egui_node_graph2/src/graph_impls.rs b/egui_node_graph2/src/graph_impls.rs index 9ab0e3e..fa2a91e 100644 --- a/egui_node_graph2/src/graph_impls.rs +++ b/egui_node_graph2/src/graph_impls.rs @@ -241,14 +241,14 @@ impl Node { pub fn inputs<'a, DataType, DataValue>( &'a self, graph: &'a Graph, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> { self.input_ids().map(|id| graph.get_input(id)) } pub fn outputs<'a, DataType, DataValue>( &'a self, graph: &'a Graph, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> { self.output_ids().map(|id| graph.get_output(id)) } From 211c3b1e092d4ad99d3130a2cf00fb6cd9423d1f Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Mon, 30 Dec 2024 08:56:35 -0800 Subject: [PATCH 7/8] Rename user_data to node_data for consistency. --- egui_node_graph2/src/editor_ui.rs | 22 +++++++++++----------- egui_node_graph2/src/graph.rs | 2 +- egui_node_graph2/src/graph_impls.rs | 4 ++-- egui_node_graph2/src/traits.rs | 2 +- egui_node_graph2_example/src/app.rs | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index b4a8daf..5122d94 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -278,7 +278,7 @@ where if let Some(node_kind) = node_finder.show(ui, all_kinds, user_state) { let new_node = self.graph.add_node( node_kind.node_graph_label(user_state), - node_kind.user_data(user_state), + node_kind.node_data(user_state), |graph, node_id| node_kind.build_node(graph, user_state, node_id), ); self.node_positions.insert( @@ -693,7 +693,7 @@ where .text_style(TextStyle::Button) .color(text_color), )); - responses.extend(self.graph[self.node_id].user_data.top_bar_ui( + responses.extend(self.graph[self.node_id].node_data.top_bar_ui( ui, self.node_id, self.graph, @@ -714,13 +714,13 @@ where responses.extend( self.graph[self.node_id] - .user_data + .node_data .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) .into_iter(), ); }); - self.graph[self.node_id].user_data.separator( + self.graph[self.node_id].node_data.separator( ui, self.node_id, AnyParameterId::Output(param_id), @@ -732,7 +732,7 @@ where output_port_heights.push((height_before + height_after) / 2.0); } - responses.extend(self.graph[self.node_id].user_data.bottom_ui( + responses.extend(self.graph[self.node_id].node_data.bottom_ui( ui, self.node_id, self.graph, @@ -745,7 +745,7 @@ where let height_before = ui.min_rect().bottom(); if self.graph[param_id].max_connections == NonZeroU32::new(1) { - // NOTE: We want to pass the `user_data` to + // NOTE: We want to pass the `node_data` to // `value_widget`, but we can't since that would require // borrowing the graph twice. Here, we make the // assumption that the value is cheaply replaced, and @@ -760,7 +760,7 @@ where self.node_id, ui, user_state, - &self.graph[self.node_id].user_data, + &self.graph[self.node_id].node_data, ); responses.extend(node_responses.into_iter().map(NodeResponse::User)); @@ -770,7 +770,7 @@ where self.node_id, ui, user_state, - &self.graph[self.node_id].user_data, + &self.graph[self.node_id].node_data, ); responses.extend(node_responses.into_iter().map(NodeResponse::User)); @@ -800,7 +800,7 @@ where ui.add_space(missing_space); } - self.graph[self.node_id].user_data.separator( + self.graph[self.node_id].node_data.separator( ui, self.node_id, AnyParameterId::Input(param_id), @@ -1075,7 +1075,7 @@ where rect: titlebar_rect, rounding, fill: self.graph[self.node_id] - .user_data + .node_data .titlebar_color(ui, self.node_id, self.graph, user_state) .unwrap_or_else(|| background_color.lighten(0.8)), stroke: Stroke::NONE, @@ -1139,7 +1139,7 @@ where // --- Interaction --- // Titlebar buttons - let can_delete = self.graph.nodes[self.node_id].user_data.can_delete( + let can_delete = self.graph.nodes[self.node_id].node_data.can_delete( self.node_id, self.graph, user_state, diff --git a/egui_node_graph2/src/graph.rs b/egui_node_graph2/src/graph.rs index 85c142e..6ae1512 100644 --- a/egui_node_graph2/src/graph.rs +++ b/egui_node_graph2/src/graph.rs @@ -15,7 +15,7 @@ pub struct Node { pub label: String, pub inputs: Vec<(String, InputId)>, pub outputs: Vec<(String, OutputId)>, - pub user_data: NodeData, + pub node_data: NodeData, } /// The three kinds of input params. These describe how the graph must behave diff --git a/egui_node_graph2/src/graph_impls.rs b/egui_node_graph2/src/graph_impls.rs index fa2a91e..e79d3e0 100644 --- a/egui_node_graph2/src/graph_impls.rs +++ b/egui_node_graph2/src/graph_impls.rs @@ -15,7 +15,7 @@ impl Graph { pub fn add_node( &mut self, label: String, - user_data: NodeData, + node_data: NodeData, f: impl FnOnce(&mut Graph, NodeId), ) -> NodeId { let node_id = self.nodes.insert_with_key(|node_id| { @@ -25,7 +25,7 @@ impl Graph { // These get filled in later by the user function inputs: Vec::default(), outputs: Vec::default(), - user_data, + node_data, } }); diff --git a/egui_node_graph2/src/traits.rs b/egui_node_graph2/src/traits.rs index 694c090..9eb9f9e 100644 --- a/egui_node_graph2/src/traits.rs +++ b/egui_node_graph2/src/traits.rs @@ -266,7 +266,7 @@ pub trait NodeTemplateTrait: Clone { fn node_graph_label(&self, user_state: &mut Self::UserState) -> String; /// Returns the user data for this node kind. - fn user_data(&self, user_state: &mut Self::UserState) -> Self::NodeData; + fn node_data(&self, user_state: &mut Self::UserState) -> Self::NodeData; /// This function is run when this node kind gets added to the graph. The /// node will be empty by default, and this function can be used to fill its diff --git a/egui_node_graph2_example/src/app.rs b/egui_node_graph2_example/src/app.rs index aeeb756..e937c1d 100644 --- a/egui_node_graph2_example/src/app.rs +++ b/egui_node_graph2_example/src/app.rs @@ -158,7 +158,7 @@ impl NodeTemplateTrait for MyNodeTemplate { self.node_finder_label(user_state).into() } - fn user_data(&self, _user_state: &mut Self::UserState) -> Self::NodeData { + fn node_data(&self, _user_state: &mut Self::UserState) -> Self::NodeData { MyNodeData { template: *self } } @@ -524,7 +524,7 @@ pub fn evaluate_node( let node = &graph[node_id]; let mut evaluator = Evaluator::new(graph, outputs_cache, node_id); - match node.user_data.template { + match node.node_data.template { MyNodeTemplate::AddScalar => { let a = evaluator.input_scalar("A")?; let b = evaluator.input_scalar("B")?; From 1a05797969cf1416193bd953064d9444a29cb544 Mon Sep 17 00:00:00 2001 From: cybersoulK Date: Tue, 31 Dec 2024 02:59:18 -0800 Subject: [PATCH 8/8] Rename variable from node to node_id. --- egui_node_graph2/src/editor_ui.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index 5122d94..441ed44 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -59,7 +59,7 @@ pub enum NodeResponse /// Emitted when a node is interacted with, and should be raised RaiseNode(NodeId), MoveNode { - node: NodeId, + node_id: NodeId, drag_delta: Vec2, }, User(UserResponse), @@ -468,12 +468,12 @@ where self.node_order.remove(old_pos); self.node_order.push(*node_id); } - NodeResponse::MoveNode { node, drag_delta } => { - self.node_positions[*node] += *drag_delta; + NodeResponse::MoveNode { node_id, drag_delta } => { + self.node_positions[*node_id] += *drag_delta; // Handle multi-node selection movement - if self.selected_nodes.contains(node) && self.selected_nodes.len() > 1 { + if self.selected_nodes.contains(node_id) && self.selected_nodes.len() > 1 { for n in self.selected_nodes.iter().copied() { - if n != *node { + if n != *node_id { self.node_positions[n] += *drag_delta; } } @@ -1153,7 +1153,7 @@ where let drag_delta = window_response.drag_delta(); if drag_delta.length_sq() > 0.0 { responses.push(NodeResponse::MoveNode { - node: self.node_id, + node_id: self.node_id, drag_delta, }); responses.push(NodeResponse::RaiseNode(self.node_id));