From e92b9342681e9baaa97feb131692c2523d7325cd Mon Sep 17 00:00:00 2001 From: Kamil Koczurek Date: Sun, 7 May 2023 18:25:06 +0200 Subject: [PATCH] Add NodeDataTrait::output_ui This method draws the UI for each of the outputs corresponding to the node. Defaults to the label that was the previous hard-coded behavior. The default impl also means this isn't a breaking change. --- egui_node_graph/src/editor_ui.rs | 7 ++++++- egui_node_graph/src/traits.rs | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 7ab452f..d009e42 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -610,7 +610,12 @@ where let outputs = self.graph[self.node_id].outputs.clone(); for (param_name, _param) in outputs { let height_before = ui.min_rect().bottom(); - ui.label(¶m_name); + responses.extend( + self.graph[self.node_id] + .user_data + .output_ui(ui, self.node_id, self.graph, user_state, ¶m_name) + .into_iter(), + ); let height_after = ui.min_rect().bottom(); output_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 c25dbb4..72a81e6 100644 --- a/egui_node_graph/src/traits.rs +++ b/egui_node_graph/src/traits.rs @@ -127,6 +127,25 @@ where Default::default() } + /// UI to draw for each output + /// + /// Defaults to showing param_name as a simple label. + fn output_ui( + &self, + ui: &mut egui::Ui, + _node_id: NodeId, + _graph: &Graph, + _user_state: &mut Self::UserState, + param_name: &str, + ) -> Vec> + where + Self::Response: UserResponseTrait, + { + ui.label(param_name); + + Default::default() + } + /// Set background color on titlebar /// If the return value is None, the default color is set. fn titlebar_color(