From 303af6ac142c0caddb83bdb3c407fb9d50a89158 Mon Sep 17 00:00:00 2001 From: KOKI Date: Fri, 27 May 2022 21:33:57 +0900 Subject: [PATCH] support light mode --- egui_node_graph/src/editor_ui.rs | 18 +++++++++++++----- egui_node_graph/src/node_finder.rs | 12 ++++++++++-- egui_node_graph_example/src/app.rs | 5 +++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 5a725cb..c63fffe 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -319,10 +319,18 @@ where ) -> Vec> { let margin = egui::vec2(15.0, 5.0); let mut responses = Vec::new(); - - let background_color = color_from_hex("#3f3f3f").unwrap(); - let titlebar_color = background_color.lighten(0.8); - let text_color = color_from_hex("#fefefe").unwrap(); + 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("#000000").unwrap(); + } ui.visuals_mut().widgets.noninteractive.fg_stroke = Stroke::new(2.0, text_color); @@ -348,7 +356,7 @@ where ui.add(Label::new( RichText::new(&self.graph[self.node_id].label) .text_style(TextStyle::Button) - .color(color_from_hex("#fefefe").unwrap()), + .color(text_color), )); }); ui.add_space(margin.y); diff --git a/egui_node_graph/src/node_finder.rs b/egui_node_graph/src/node_finder.rs index 5213c57..5feaadc 100644 --- a/egui_node_graph/src/node_finder.rs +++ b/egui_node_graph/src/node_finder.rs @@ -34,8 +34,16 @@ where ui: &mut Ui, all_kinds: impl NodeTemplateIter, ) -> Option { - let background_color = color_from_hex("#3f3f3f").unwrap(); - let text_color = color_from_hex("#fefefe").unwrap(); + let background_color; + let text_color; + + if ui.visuals().dark_mode { + background_color = color_from_hex("#3f3f3f").unwrap(); + text_color = color_from_hex("#fefefe").unwrap(); + } else { + background_color = color_from_hex("#fefefe").unwrap(); + text_color = color_from_hex("#3f3f3f").unwrap(); + } ui.visuals_mut().widgets.noninteractive.fg_stroke = Stroke::new(2.0, text_color); diff --git a/egui_node_graph_example/src/app.rs b/egui_node_graph_example/src/app.rs index be4ea3f..6e0379a 100644 --- a/egui_node_graph_example/src/app.rs +++ b/egui_node_graph_example/src/app.rs @@ -349,6 +349,11 @@ impl eframe::App for NodeGraphExample { /// Called each time the UI needs repainting, which may be many times per second. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. 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); + }); + }); let graph_response = egui::CentralPanel::default() .show(ctx, |ui| { self.state.draw_graph_editor(ui, AllMyNodeTemplates)