From a38123f46e0ecdc19cbafd8e069d28025d789fbc Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 1 Oct 2022 14:21:35 +0200 Subject: [PATCH] Make `weak_text_color` an Option --- crates/egui/src/style.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 7ebae021..ced77820 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -451,7 +451,9 @@ pub struct Visuals { pub code_bg_color: Color32, /// Color used for weak text. - pub weak_text_color: Color32, + /// + /// If `None`, a color is automatially chosen based on [`Self::text_color`] and [`Self::window_fill`]. + pub weak_text_color: Option, /// A good color for warning text (e.g. orange). pub warn_fg_color: Color32, @@ -491,9 +493,10 @@ impl Visuals { .unwrap_or_else(|| self.widgets.noninteractive.text_color()) } - #[inline] pub fn weak_text_color(&self) -> Color32 { - self.weak_text_color + self.weak_text_color.unwrap_or_else(|| { + crate::color::tint_color_towards(self.text_color(), self.window_fill()) + }) } #[inline(always)] @@ -679,7 +682,7 @@ impl Visuals { faint_bg_color: Color32::from_gray(35), extreme_bg_color: Color32::from_gray(10), // e.g. TextEdit background code_bg_color: Color32::from_gray(64), - weak_text_color: Color32::from_gray(83), + weak_text_color: None, warn_fg_color: Color32::from_rgb(255, 143, 0), // orange error_fg_color: Color32::from_rgb(255, 0, 0), // red window_rounding: Rounding::same(6.0), @@ -704,7 +707,6 @@ impl Visuals { faint_bg_color: Color32::from_gray(242), extreme_bg_color: Color32::from_gray(255), // e.g. TextEdit background code_bg_color: Color32::from_gray(230), - weak_text_color: Color32::from_gray(164), warn_fg_color: Color32::from_rgb(255, 0, 0), // red also, beecause orange doesn't look great because of https://github.com/emilk/egui/issues/1455 error_fg_color: Color32::from_rgb(255, 0, 0), // red window_shadow: Shadow::big_light(), @@ -1187,7 +1189,7 @@ impl Visuals { faint_bg_color, extreme_bg_color, code_bg_color, - weak_text_color, + weak_text_color: _, // TODO(emilk) warn_fg_color, error_fg_color, window_rounding, @@ -1231,7 +1233,6 @@ impl Visuals { &mut widgets.noninteractive.fg_stroke.color, "Text color", ); - ui_color(ui, weak_text_color, RichText::new("Weak text")); ui_color(ui, warn_fg_color, RichText::new("Warnings")); ui_color(ui, error_fg_color, RichText::new("Errors")); });