pub struct CalendarState { /* private fields */ }Expand description
State for a Calendar component.
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3)
.with_selected_day(15)
.with_title("Events");
assert_eq!(state.year(), 2026);
assert_eq!(state.month(), 3);
assert_eq!(state.selected_day(), Some(15));
assert_eq!(state.month_name(), "March");Implementations§
Source§impl CalendarState
impl CalendarState
Sourcepub fn new(year: i32, month: u32) -> Self
pub fn new(year: i32, month: u32) -> Self
Creates a new calendar for the given year and month.
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3);
assert_eq!(state.year(), 2026);
assert_eq!(state.month(), 3);
assert_eq!(state.selected_day(), None);Sourcepub fn with_selected_day(self, day: u32) -> Self
pub fn with_selected_day(self, day: u32) -> Self
Sets the initially selected day (builder method).
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3).with_selected_day(15);
assert_eq!(state.selected_day(), Some(15));Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Sets the title (builder method).
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3).with_title("My Calendar");Sourcepub fn with_event(self, year: i32, month: u32, day: u32, color: Color) -> Self
pub fn with_event(self, year: i32, month: u32, day: u32, color: Color) -> Self
Adds an event marker (builder method).
§Example
use envision::component::CalendarState;
use ratatui::style::Color;
let state = CalendarState::new(2026, 3)
.with_event(2026, 3, 15, Color::Green);
assert!(state.has_event(2026, 3, 15));Sourcepub fn year(&self) -> i32
pub fn year(&self) -> i32
Returns the current year.
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3);
assert_eq!(state.year(), 2026);Sourcepub fn month(&self) -> u32
pub fn month(&self) -> u32
Returns the current month (1-12).
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3);
assert_eq!(state.month(), 3);Sourcepub fn selected_day(&self) -> Option<u32>
pub fn selected_day(&self) -> Option<u32>
Returns the currently selected day, if any.
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3).with_selected_day(20);
assert_eq!(state.selected_day(), Some(20));Sourcepub fn title(&self) -> Option<&str>
pub fn title(&self) -> Option<&str>
Returns the title, if set.
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 3).with_title("My Calendar");
assert_eq!(state.title(), Some("My Calendar"));
let state2 = CalendarState::new(2026, 3);
assert_eq!(state2.title(), None);Sourcepub fn set_title(&mut self, title: impl Into<String>)
pub fn set_title(&mut self, title: impl Into<String>)
Sets the title.
§Example
use envision::component::CalendarState;
let mut state = CalendarState::new(2026, 3);
state.set_title("Events");
assert_eq!(state.title(), Some("Events"));Sourcepub fn set_selected_day(&mut self, day: Option<u32>)
pub fn set_selected_day(&mut self, day: Option<u32>)
Sets the selected day.
§Example
use envision::component::CalendarState;
let mut state = CalendarState::new(2026, 3);
state.set_selected_day(Some(15));
assert_eq!(state.selected_day(), Some(15));
state.set_selected_day(None);
assert_eq!(state.selected_day(), None);Sourcepub fn month_name(&self) -> &str
pub fn month_name(&self) -> &str
Returns the name of the current month.
§Example
use envision::component::CalendarState;
let state = CalendarState::new(2026, 1);
assert_eq!(state.month_name(), "January");Sourcepub fn add_event(&mut self, year: i32, month: u32, day: u32, color: Color)
pub fn add_event(&mut self, year: i32, month: u32, day: u32, color: Color)
Adds an event marker for the given date with the given color.
§Example
use envision::component::CalendarState;
use ratatui::style::Color;
let mut state = CalendarState::new(2026, 3);
state.add_event(2026, 3, 15, Color::Red);
assert!(state.has_event(2026, 3, 15));Sourcepub fn clear_events(&mut self)
pub fn clear_events(&mut self)
Removes all event markers.
§Example
use envision::component::CalendarState;
use ratatui::style::Color;
let mut state = CalendarState::new(2026, 3);
state.add_event(2026, 3, 15, Color::Red);
state.clear_events();
assert!(!state.has_event(2026, 3, 15));Sourcepub fn has_event(&self, year: i32, month: u32, day: u32) -> bool
pub fn has_event(&self, year: i32, month: u32, day: u32) -> bool
Returns whether there is an event marker for the given date.
§Example
use envision::component::CalendarState;
use ratatui::style::Color;
let state = CalendarState::new(2026, 3)
.with_event(2026, 3, 15, Color::Green);
assert!(state.has_event(2026, 3, 15));
assert!(!state.has_event(2026, 3, 16));Sourcepub fn update(&mut self, msg: CalendarMessage) -> Option<CalendarOutput>
pub fn update(&mut self, msg: CalendarMessage) -> Option<CalendarOutput>
Updates the calendar state with a message, returning any output.
§Example
use envision::component::{CalendarMessage, CalendarOutput, CalendarState};
let mut state = CalendarState::new(2026, 3);
let output = state.update(CalendarMessage::NextMonth);
assert_eq!(output, Some(CalendarOutput::MonthChanged(2026, 4)));Trait Implementations§
Source§impl Clone for CalendarState
impl Clone for CalendarState
Source§fn clone(&self) -> CalendarState
fn clone(&self) -> CalendarState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CalendarState
impl Debug for CalendarState
Source§impl Default for CalendarState
impl Default for CalendarState
Source§fn default() -> Self
fn default() -> Self
Returns a calendar for January 1970 with no selected day, no events, and no title.
This mirrors the conventional Unix epoch default used by date libraries
like chrono’s NaiveDate::default(). For meaningful UI, construct
state with CalendarState::new for the desired year and month.
§Example
use envision::component::CalendarState;
let state = CalendarState::default();
assert_eq!(state.year(), 1970);
assert_eq!(state.month(), 1);
assert_eq!(state.selected_day(), None);Source§impl<'de> Deserialize<'de> for CalendarState
impl<'de> Deserialize<'de> for CalendarState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for CalendarState
impl PartialEq for CalendarState
Source§impl Serialize for CalendarState
impl Serialize for CalendarState
impl StructuralPartialEq for CalendarState
Auto Trait Implementations§
impl Freeze for CalendarState
impl RefUnwindSafe for CalendarState
impl Send for CalendarState
impl Sync for CalendarState
impl Unpin for CalendarState
impl UnsafeUnpin for CalendarState
impl UnwindSafe for CalendarState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more