From 14e0963e50f3434da3e47a330febad82b1042022 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 Jan 2021 18:47:09 +0100 Subject: [PATCH] Add Label::weak for fainter text --- egui/src/style.rs | 4 ++++ egui/src/widgets/label.rs | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/egui/src/style.rs b/egui/src/style.rs index cbf21934..ac2b426b 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -170,6 +170,10 @@ impl Visuals { .unwrap_or_else(|| self.widgets.noninteractive.text_color()) } + pub fn weak_text_color(&self) -> Color32 { + self.widgets.disabled.text_color() + } + pub fn strong_text_color(&self) -> Color32 { self.widgets.active.text_color() } diff --git a/egui/src/widgets/label.rs b/egui/src/widgets/label.rs index e4348f26..0004af51 100644 --- a/egui/src/widgets/label.rs +++ b/egui/src/widgets/label.rs @@ -11,6 +11,7 @@ pub struct Label { pub(crate) text_color: Option, code: bool, strong: bool, + weak: bool, strikethrough: bool, underline: bool, italics: bool, @@ -26,6 +27,7 @@ impl Label { text_color: None, code: false, strong: false, + weak: false, strikethrough: false, underline: false, italics: false, @@ -67,12 +69,18 @@ impl Label { self.text_style(TextStyle::Monospace) } - /// Extra white text + /// Extra strong text (stronger color). pub fn strong(mut self) -> Self { self.strong = true; self } + /// Extra weak text (fainter color). + pub fn weak(mut self) -> Self { + self.weak = true; + self + } + /// draw a line under the text pub fn underline(mut self) -> Self { self.underline = true; @@ -139,6 +147,7 @@ impl Label { mut background_color, code, strong, + weak, strikethrough, underline, italics, @@ -148,6 +157,8 @@ impl Label { let text_color = self.text_color.unwrap_or_else(|| { if strong { ui.style().visuals.strong_text_color() + } else if weak { + ui.style().visuals.weak_text_color() } else { ui.style().visuals.text_color() }