From 72d1001a3f5adfd305181b10b85a7a632b999a68 Mon Sep 17 00:00:00 2001 From: KOKI Date: Mon, 30 May 2022 17:02:15 +0900 Subject: [PATCH 1/2] added titlebar_color() --- egui_node_graph/src/editor_ui.rs | 8 ++++---- egui_node_graph/src/traits.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index ab37351..66c404b 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -323,15 +323,12 @@ where let mut responses = Vec::new(); let background_color; - let titlebar_color; let text_color; if ui.visuals().dark_mode { background_color = color_from_hex("#3f3f3f").unwrap(); - titlebar_color = background_color.lighten(0.8); text_color = color_from_hex("#fefefe").unwrap(); } else { background_color = color_from_hex("#ffffff").unwrap(); - titlebar_color = background_color.lighten(0.8); text_color = color_from_hex("#505050").unwrap(); } @@ -522,7 +519,10 @@ where let titlebar = Shape::Rect(RectShape { rect: titlebar_rect, rounding, - fill: titlebar_color, + fill: self.graph[self.node_id] + .user_data + .titlebar_color(ui, self.node_id, self.graph, user_state) + .unwrap_or(background_color.lighten(0.8)), stroke: Stroke::none(), }); diff --git a/egui_node_graph/src/traits.rs b/egui_node_graph/src/traits.rs index 5be8908..a57c14e 100644 --- a/egui_node_graph/src/traits.rs +++ b/egui_node_graph/src/traits.rs @@ -43,6 +43,18 @@ where ) -> Vec> where Self::Response: UserResponseTrait; + + /// Set background color on titlebar + /// If the return value is None, the default color is set. + fn titlebar_color( + &self, + _ui: &egui::Ui, + _node_id: NodeId, + _graph: &Graph, + _user_state: &Self::UserState, + ) -> Option { + None + } } /// This trait can be implemented by any user type. The trait tells the library From a9402c77e2ec1b851713224115285d51d734bdb7 Mon Sep 17 00:00:00 2001 From: KOKI Date: Mon, 30 May 2022 18:10:18 +0900 Subject: [PATCH 2/2] fix clippy --- egui_node_graph/src/editor_ui.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 66c404b..07988ae 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -522,7 +522,7 @@ where fill: self.graph[self.node_id] .user_data .titlebar_color(ui, self.node_id, self.graph, user_state) - .unwrap_or(background_color.lighten(0.8)), + .unwrap_or_else(|| background_color.lighten(0.8)), stroke: Stroke::none(), });