Skip to content

Commit

Permalink
add some common interfaces to the model, make visible public
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony4dev committed Jan 16, 2025
1 parent 1914006 commit 4580701
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/widget/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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> {
Expand Down

0 comments on commit 4580701

Please sign in to comment.