pub struct CalendarState { /* private fields */ }Expand description
Retained selection and one roving Tab stop for a Gregorian calendar.
The grid contains six weeks, Monday-first by default, including adjacent-month dates. Keyboard navigation changes the visible month as necessary, without selecting a date. Pointer/native focus preserves the current grid until activation. Enter, Space, and pointer activation commit selection. Date arithmetic uses jiff’s civil date, with no clock or timezone dependency.
One state belongs to one mounted calendar in one window. Render all dates
returned by Self::days once, in order. The supported date range is years
1 through 9998, narrowed by Self::bounds before mounting if needed.
Implementations§
Source§impl CalendarState
impl CalendarState
Sourcepub fn new(initial_date: Date, cx: &mut Context<'_, Self>) -> Self
pub fn new(initial_date: Date, cx: &mut Context<'_, Self>) -> Self
Starts with initial_date focused in its month, in empty single-date mode.
§Panics
initial_date must have a year in 1..=9998.
Sourcepub fn bounds(self, minimum: Date, maximum: Date) -> Self
pub fn bounds(self, minimum: Date, maximum: Date) -> Self
Sets inclusive selectable bounds before mounting. Focus is clamped into the range. Out-of-range single or multiple dates are removed; a range with an out-of-range endpoint is cleared.
§Panics
Bounds must be ordered and lie within years 1..=9998.
Sourcepub fn week_starts_on(self, weekday: Weekday) -> Self
pub fn week_starts_on(self, weekday: Weekday) -> Self
Sets the first weekday before mounting. Day order remains chronological;
use Self::weekdays for the matching application-owned column labels.
Sourcepub fn disabled_dates(self, predicate: impl Fn(Date) -> bool + 'static) -> Self
pub fn disabled_dates(self, predicate: impl Fn(Date) -> bool + 'static) -> Self
Prevents matching dates from being selected, before mounting. Existing single/multiple values are filtered; a range with a disabled endpoint is cleared. Disabled dates may remain inside a range.
Disabled dates within the bounds retain keyboard focus so users can discover unavailable days. They cannot be activated. The predicate should return the same result for a date throughout this state’s lifetime.
Sourcepub fn default_selection(self, selection: CalendarSelection) -> Self
pub fn default_selection(self, selection: CalendarSelection) -> Self
Sets the selection mode and initial value without emitting an event. Multiple dates are sorted and deduplicated. The first selected date also becomes the cursor and visible month; empty selections retain navigation.
§Panics
Dates must be selectable within the configured bounds. Range endpoints must be ordered, and an end requires a start.
pub fn focused_date(&self) -> Date
pub fn selection(&self) -> &CalendarSelection
Sourcepub fn is_selected(&self, date: Date) -> bool
pub fn is_selected(&self, date: Date) -> bool
Whether a date belongs to the current selection, including range interiors.
pub fn minimum(&self) -> Date
pub fn maximum(&self) -> Date
pub fn first_weekday(&self) -> Weekday
Sourcepub fn weekdays(&self) -> [Weekday; 7]
pub fn weekdays(&self) -> [Weekday; 7]
Weekday order for each chronological row returned by Self::days.
pub fn is_disabled(&self) -> bool
pub fn is_date_disabled(&self, date: Date) -> bool
Sourcepub fn days(&self) -> [Date; 42]
pub fn days(&self) -> [Date; 42]
All six weeks in chronological order, starting on Self::first_weekday.
Adjacent dates outside configured bounds
remain visible and disabled, including years 0 and 9999 at the outer edges.
Sourcepub fn focus_handle(&self) -> &FocusHandle
pub fn focus_handle(&self) -> &FocusHandle
Focus handle of the current cursor. Read it when moving focus into the calendar; month navigation may change which grid slot owns that date.
pub fn can_previous_month(&self) -> bool
pub fn can_next_month(&self) -> bool
Sourcepub fn previous_month(
&mut self,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn previous_month( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, )
Displays the preceding month while retaining focus on an external navigation button. If a day owns focus, it follows the new cursor.
Sourcepub fn next_month(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
pub fn next_month(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
Displays the following month with the same focus policy as
Self::previous_month. End-of-month dates clamp to the new month.
Sourcepub fn display_month(
&mut self,
month: Date,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn display_month( &mut self, month: Date, window: &mut Window, cx: &mut Context<'_, Self>, )
Displays the year and month of month, preserving the selection and
cursor’s day of month when possible. The cursor is clamped to the new
month’s length and the calendar bounds. An external month selector keeps
focus; a focused day follows the new cursor. Disabled calendars stay put.
Sourcepub fn set_selection(
&mut self,
selection: CalendarSelection,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> bool
pub fn set_selection( &mut self, selection: CalendarSelection, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool
Replaces the selection mode and value without emitting an event. The first selected date becomes the cursor and visible month. Empty values preserve navigation. Invalid, disabled, or out-of-bounds endpoints/dates return false unchanged. Programmatic changes remain allowed while the calendar is disabled.
Sourcepub fn set_disabled(
&mut self,
disabled: bool,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_disabled( &mut self, disabled: bool, window: &mut Window, cx: &mut Context<'_, Self>, )
Disables activation, navigation, and normal Tab entry. An already focused day retains its focus binding until Tab moves away.
Trait Implementations§
impl EventEmitter<CalendarEvent> for CalendarState
Auto Trait Implementations§
impl !RefUnwindSafe for CalendarState
impl !Send for CalendarState
impl !Sync for CalendarState
impl !UnwindSafe for CalendarState
impl Forget for CalendarState
impl Freeze for CalendarStatewhere
*const u8 is !null: Freeze,
PhantomData<Date>: Freeze,
*const dyn Fn(Date) -> bool is !null: Freeze,
PhantomData<dyn Fn(Date) -> bool>: Freeze,
NonZero<u32>: Freeze,
*const ArcInner<RwLock<RawRwLock, FocusMap>> is !null: Freeze,
PhantomData<ArcInner<RwLock<RawRwLock, FocusMap>>>: Freeze,
PhantomData<Subscription>: Freeze,
impl Move for CalendarState
impl Unpin for CalendarState
impl UnsafeUnpin for CalendarStatewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<Date>: UnsafeUnpin,
*const dyn Fn(Date) -> bool is !null: UnsafeUnpin,
PhantomData<dyn Fn(Date) -> bool>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, FocusMap>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<RawRwLock, FocusMap>>>: UnsafeUnpin,
PhantomData<Subscription>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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