Skip to main content

CalendarState

Struct CalendarState 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn focused_date(&self) -> Date

Source

pub fn selection(&self) -> &CalendarSelection

Source

pub fn is_selected(&self, date: Date) -> bool

Whether a date belongs to the current selection, including range interiors.

Source

pub fn month(&self) -> Date

The first day of the currently visible month.

Source

pub fn minimum(&self) -> Date

Source

pub fn maximum(&self) -> Date

Source

pub fn first_weekday(&self) -> Weekday

Source

pub fn weekdays(&self) -> [Weekday; 7]

Weekday order for each chronological row returned by Self::days.

Source

pub fn is_disabled(&self) -> bool

Source

pub fn is_date_disabled(&self, date: Date) -> bool

Source

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.

Source

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.

Source

pub fn can_previous_month(&self) -> bool

Source

pub fn can_next_month(&self) -> bool

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more