pub struct DatePickerState {
pub selected: Option<MaterialDate>,
pub displayed_month: MaterialDate,
pub mode: DatePickerMode,
pub entry_mode: DatePickerEntryMode,
pub input_text: String,
}Expand description
The date picker’s whole controlled state: what is selected, which month and sub-view the calendar shows, which entry mode the dialog is in, and the input field’s draft text.
Held by the app, never by a widget — see the module docs’ controlled
note. Every with_*/stepped_*/toggled_* method below returns a new
value rather than mutating, which is exactly the shape a widget’s
on_change callback reports and an app’s handler assigns.
Fields§
§selected: Option<MaterialDate>The picked date, or None if nothing is picked yet.
displayed_month: MaterialDateThe month the day grid shows, normalized to its 1st.
mode: DatePickerModeWhich calendar sub-view is showing.
entry_mode: DatePickerEntryModeWhich entry mode the dialog is in (ignored by a bare
calendar_date_picker, which is always a calendar).
input_text: StringThe input field’s current text. Kept in sync with Self::selected by
Self::with_selected, and free-form while the user types.
Implementations§
Source§impl DatePickerState
impl DatePickerState
Sourcepub fn new(initial: Option<MaterialDate>, today: MaterialDate) -> Self
pub fn new(initial: Option<MaterialDate>, today: MaterialDate) -> Self
A fresh state: initial selected (or nothing), showing that date’s
month — or today’s if nothing is selected — in the day sub-view and
the calendar entry mode.
Mirrors _M3ECalendarDatePickerState.initState’s
base = _selectedDate ?? _currentDate; _displayedMonth = getMonth(base).
Sourcepub fn with_selected(&self, date: MaterialDate) -> Self
pub fn with_selected(&self, date: MaterialDate) -> Self
This state with selected picked: the date recorded, the displayed
month moved onto it, and Self::input_text refreshed to its compact
form so a later switch into input mode shows the picked date (the
reference’s _updateValueForSelectedDate).
Sourcepub fn with_displayed_month(&self, month: MaterialDate) -> Self
pub fn with_displayed_month(&self, month: MaterialDate) -> Self
This state with the displayed month replaced (normalized to its 1st).
The selection is untouched — paging past the selected month keeps it
selected, exactly as the reference’s PageView does.
Sourcepub fn stepped_month(
&self,
delta: i32,
first: MaterialDate,
last: MaterialDate,
) -> Self
pub fn stepped_month( &self, delta: i32, first: MaterialDate, last: MaterialDate, ) -> Self
This state paged delta months, clamped so the displayed month never
leaves first..=last’s own months — the reference’s page-count bound
(page > 0 / page < _monthCount - 1).
Sourcepub fn can_step_month(
&self,
delta: i32,
first: MaterialDate,
last: MaterialDate,
) -> bool
pub fn can_step_month( &self, delta: i32, first: MaterialDate, last: MaterialDate, ) -> bool
Whether paging by delta would actually move — what the prev/next
affordances enable off.
Sourcepub fn with_mode(&self, mode: DatePickerMode) -> Self
pub fn with_mode(&self, mode: DatePickerMode) -> Self
This state showing calendar sub-view mode.
Sourcepub fn toggled_mode(&self) -> Self
pub fn toggled_mode(&self) -> Self
This state with the calendar sub-view toggled (day ⇄ year) — what the sub-header’s month/year label reports.
Sourcepub fn with_entry_mode(&self, entry_mode: DatePickerEntryMode) -> Self
pub fn with_entry_mode(&self, entry_mode: DatePickerEntryMode) -> Self
This state in entry mode entry_mode.
Sourcepub fn toggled_entry_mode(&self) -> Self
pub fn toggled_entry_mode(&self) -> Self
This state with the entry mode toggled (calendar ⇄ input), preserving
the selection and its formatted text — the reference’s
_handleEntryModeToggle, whose _formKey.currentState?.save() on the
way out of input mode exists for exactly this round trip.
A locked (*Only) entry mode reports itself unchanged.
Sourcepub fn with_input_text(&self, text: impl Into<String>) -> Self
pub fn with_input_text(&self, text: impl Into<String>) -> Self
This state with the input field’s draft text replaced. The selection is
not touched — a widget parses the text itself and calls
Self::with_selected separately once it resolves to a selectable
date, mirroring the reference’s split between onChanged
(field.didChange) and onDateSubmitted/onDateSaved.
Sourcepub fn year_candidate(
&self,
year: i32,
first: MaterialDate,
last: MaterialDate,
) -> MaterialDate
pub fn year_candidate( &self, year: i32, first: MaterialDate, last: MaterialDate, ) -> MaterialDate
The date a tap on year cell year would select, before any
selectability predicate: the current selection’s month/day carried onto
year (shortened where that month is shorter) and clamped into
first..=last — the reference’s _buildYearCell candidate.
Sourcepub fn with_year(
&self,
year: i32,
first: MaterialDate,
last: MaterialDate,
) -> Self
pub fn with_year( &self, year: i32, first: MaterialDate, last: MaterialDate, ) -> Self
This state after a tap on year cell year: back to the day sub-view,
showing (and selecting) Self::year_candidate — the reference’s
_handleYearChanged.
A caller with a selectability predicate checks
Self::year_candidate first and falls back to
self.with_displayed_month(..).with_mode(Day) when the candidate is
refused, which is what the reference’s if (isSelectable(clamped))
guard does.
Trait Implementations§
Source§impl Clone for DatePickerState
impl Clone for DatePickerState
Source§impl Debug for DatePickerState
impl Debug for DatePickerState
impl Eq for DatePickerState
Source§impl PartialEq for DatePickerState
impl PartialEq for DatePickerState
impl StructuralPartialEq for DatePickerState
Auto Trait Implementations§
impl Freeze for DatePickerState
impl RefUnwindSafe for DatePickerState
impl Send for DatePickerState
impl Sync for DatePickerState
impl Unpin for DatePickerState
impl UnsafeUnpin for DatePickerState
impl UnwindSafe for DatePickerState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.