From 365d035b20da72c560f0861413673d76762dd98d Mon Sep 17 00:00:00 2001 From: hiyosilver <130156584+hiyosilver@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:09:19 +0100 Subject: [PATCH] Added ability to disable highlighting of weekend days in DatePickerPopup. (#4151) I added a handfull of lines to allow for the red highlight on weekends in `DatePickerPopup` to be disabled. I tried to follow the rules, but I've never done any kind of PR before, and I'm also not sure if this is at all the kind of thing that is wanted at the moment. If it is not, I'm happy to just have this removed. Just a tiny little addition I would find useful. --------- Co-authored-by: Emil Ernerfeldt --- crates/egui_extras/src/datepicker/button.rs | 10 ++++++++++ crates/egui_extras/src/datepicker/popup.rs | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/egui_extras/src/datepicker/button.rs b/crates/egui_extras/src/datepicker/button.rs index a81747ff..839adebf 100644 --- a/crates/egui_extras/src/datepicker/button.rs +++ b/crates/egui_extras/src/datepicker/button.rs @@ -17,6 +17,7 @@ pub struct DatePickerButton<'a> { calendar_week: bool, show_icon: bool, format: String, + highlight_weekends: bool, } impl<'a> DatePickerButton<'a> { @@ -30,6 +31,7 @@ impl<'a> DatePickerButton<'a> { calendar_week: true, show_icon: true, format: "%Y-%m-%d".to_owned(), + highlight_weekends: true, } } @@ -83,6 +85,13 @@ impl<'a> DatePickerButton<'a> { self.format = format.into(); self } + + /// Highlight weekend days. (Default: true) + #[inline] + pub fn highlight_weekends(mut self, highlight_weekends: bool) -> Self { + self.highlight_weekends = highlight_weekends; + self + } } impl<'a> Widget for DatePickerButton<'a> { @@ -148,6 +157,7 @@ impl<'a> Widget for DatePickerButton<'a> { arrows: self.arrows, calendar: self.calendar, calendar_week: self.calendar_week, + highlight_weekends: self.highlight_weekends, } .draw(ui) }) diff --git a/crates/egui_extras/src/datepicker/popup.rs b/crates/egui_extras/src/datepicker/popup.rs index a787d3c5..c5bd41d5 100644 --- a/crates/egui_extras/src/datepicker/popup.rs +++ b/crates/egui_extras/src/datepicker/popup.rs @@ -33,6 +33,7 @@ pub(crate) struct DatePickerPopup<'a> { pub arrows: bool, pub calendar: bool, pub calendar_week: bool, + pub highlight_weekends: bool, } impl<'a> DatePickerPopup<'a> { @@ -304,8 +305,9 @@ impl<'a> DatePickerPopup<'a> { && popup_state.day == day.day() { ui.visuals().selection.bg_fill - } else if day.weekday() == Weekday::Sat - || day.weekday() == Weekday::Sun + } else if (day.weekday() == Weekday::Sat + || day.weekday() == Weekday::Sun) + && self.highlight_weekends { if ui.visuals().dark_mode { Color32::DARK_RED