From b80c0e6ff6602be39dd2eb8787e026bce03cf66b Mon Sep 17 00:00:00 2001 From: Barugon <16503728+Barugon@users.noreply.github.com> Date: Tue, 18 Apr 2023 05:55:09 -0700 Subject: [PATCH] Add option to show icon (#2910) --- crates/egui_extras/src/datepicker/button.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/egui_extras/src/datepicker/button.rs b/crates/egui_extras/src/datepicker/button.rs index 07acb664..e8aafef7 100644 --- a/crates/egui_extras/src/datepicker/button.rs +++ b/crates/egui_extras/src/datepicker/button.rs @@ -14,6 +14,7 @@ pub struct DatePickerButton<'a> { arrows: bool, calendar: bool, calendar_week: bool, + show_icon: bool, } impl<'a> DatePickerButton<'a> { @@ -25,6 +26,7 @@ impl<'a> DatePickerButton<'a> { arrows: true, calendar: true, calendar_week: true, + show_icon: true, } } @@ -58,6 +60,12 @@ impl<'a> DatePickerButton<'a> { self.calendar_week = week; self } + + /// Show the calender icon on the button. (Default: true) + pub fn show_icon(mut self, show_icon: bool) -> Self { + self.show_icon = show_icon; + self + } } impl<'a> Widget for DatePickerButton<'a> { @@ -67,7 +75,11 @@ impl<'a> Widget for DatePickerButton<'a> { .memory_mut(|mem| mem.data.get_persisted::(id)) .unwrap_or_default(); - let mut text = RichText::new(format!("{} 📆", self.selection.format("%Y-%m-%d"))); + let mut text = if self.show_icon { + RichText::new(format!("{} 📆", self.selection.format("%Y-%m-%d"))) + } else { + RichText::new(format!("{}", self.selection.format("%Y-%m-%d"))) + }; let visuals = ui.visuals().widgets.open; if button_state.picker_visible { text = text.color(visuals.text_color());