support light mode

This commit is contained in:
KOKI 2022-05-27 21:33:57 +09:00
parent c6c517644a
commit 303af6ac14
3 changed files with 28 additions and 7 deletions

View File

@ -319,10 +319,18 @@ where
) -> Vec<NodeResponse<UserResponse>> { ) -> Vec<NodeResponse<UserResponse>> {
let margin = egui::vec2(15.0, 5.0); let margin = egui::vec2(15.0, 5.0);
let mut responses = Vec::new(); let mut responses = Vec::new();
let background_color;
let background_color = color_from_hex("#3f3f3f").unwrap(); let titlebar_color;
let titlebar_color = background_color.lighten(0.8); let text_color;
let text_color = color_from_hex("#fefefe").unwrap(); 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); ui.visuals_mut().widgets.noninteractive.fg_stroke = Stroke::new(2.0, text_color);
@ -348,7 +356,7 @@ where
ui.add(Label::new( ui.add(Label::new(
RichText::new(&self.graph[self.node_id].label) RichText::new(&self.graph[self.node_id].label)
.text_style(TextStyle::Button) .text_style(TextStyle::Button)
.color(color_from_hex("#fefefe").unwrap()), .color(text_color),
)); ));
}); });
ui.add_space(margin.y); ui.add_space(margin.y);

View File

@ -34,8 +34,16 @@ where
ui: &mut Ui, ui: &mut Ui,
all_kinds: impl NodeTemplateIter<Item = NodeTemplate>, all_kinds: impl NodeTemplateIter<Item = NodeTemplate>,
) -> Option<NodeTemplate> { ) -> Option<NodeTemplate> {
let background_color = color_from_hex("#3f3f3f").unwrap(); let background_color;
let text_color = color_from_hex("#fefefe").unwrap(); 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); ui.visuals_mut().widgets.noninteractive.fg_stroke = Stroke::new(2.0, text_color);

View File

@ -349,6 +349,11 @@ impl eframe::App for NodeGraphExample {
/// Called each time the UI needs repainting, which may be many times per second. /// 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`. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { 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() let graph_response = egui::CentralPanel::default()
.show(ctx, |ui| { .show(ctx, |ui| {
self.state.draw_graph_editor(ui, AllMyNodeTemplates) self.state.draw_graph_editor(ui, AllMyNodeTemplates)