From ba2a00ef7611c99bb278fcc1303257d5bd9eaab6 Mon Sep 17 00:00:00 2001 From: Kamil Koczurek Date: Thu, 4 May 2023 14:21:39 +0200 Subject: [PATCH] Add top bar UI Users can specify UI that will be added to the top bar of a node via the new top_bar_ui method in NodeDataTrait. A default definition is provided because it's not core to the functionality and so as to avoid unnecessarily breaking existing programs. --- egui_node_graph/src/editor_ui.rs | 6 ++++++ egui_node_graph/src/traits.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index dbc61a8..cbd51c2 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -527,6 +527,12 @@ where .text_style(TextStyle::Button) .color(text_color), )); + responses.extend( + self.graph[self.node_id] + .user_data + .top_bar_ui(ui, self.node_id, self.graph, user_state) + .into_iter(), + ); ui.add_space(8.0); // The size of the little cross icon }); ui.add_space(margin.y); diff --git a/egui_node_graph/src/traits.rs b/egui_node_graph/src/traits.rs index a9cf2ef..31a9a6d 100644 --- a/egui_node_graph/src/traits.rs +++ b/egui_node_graph/src/traits.rs @@ -91,6 +91,20 @@ where where Self::Response: UserResponseTrait; + // UI to draw on the top bar of the node. + fn top_bar_ui( + &self, + _ui: &mut egui::Ui, + _node_id: NodeId, + _graph: &Graph, + _user_state: &mut Self::UserState, + ) -> Vec> + where + Self::Response: UserResponseTrait, + { + Default::default() + } + /// Set background color on titlebar /// If the return value is None, the default color is set. fn titlebar_color(