diff --git a/src/widget/calendar.rs b/src/widget/calendar.rs index e7fad16823a..d5a2f51ce3d 100644 --- a/src/widget/calendar.rs +++ b/src/widget/calendar.rs @@ -42,9 +42,10 @@ pub fn set_day(date_selected: NaiveDate, day: u32) -> NaiveDate { } } +#[derive(Default, Clone)] pub struct CalendarModel { pub selected: NaiveDate, - visible: NaiveDate, + pub visible: NaiveDate, } impl CalendarModel { @@ -57,11 +58,8 @@ impl CalendarModel { } } - pub fn new(selected: NaiveDate) -> Self { - CalendarModel { - selected, - visible: selected.clone(), - } + pub fn new(selected: NaiveDate, visible: NaiveDate) -> Self { + CalendarModel { selected, visible } } pub fn show_prev_month(&mut self) { @@ -93,6 +91,11 @@ impl CalendarModel { self.show_next_month(); self.selected = self.visible.clone(); } + + pub fn set_selected_visible(&mut self, selected: NaiveDate) { + self.selected = selected; + self.visible = self.selected.clone(); + } } pub struct Calendar<'a, M> {