pub struct DatePickerState { /* private fields */ }Expand description
Holds the current selection and display state for a date picker.
is_selectable_date and is_selectable_year are optional predicates.
None means every date or year is selectable. A date is selectable only
when it is inside the year range and both predicates allow it.
[CallbackWith] must be created during a component build, so these
setters have to be called from inside a #[tessera] component. Closures
passed to date_picker are turned into callbacks at that component
boundary.
Implementations§
Source§impl DatePickerState
impl DatePickerState
Sourcepub fn new(
initial_selected_date: Option<CalendarDate>,
initial_displayed_month: Option<YearMonth>,
year_range: RangeInclusive<i32>,
is_selectable_date: Option<CallbackWith<CalendarDate, bool>>,
is_selectable_year: Option<CallbackWith<i32, bool>>,
display_mode: DatePickerDisplayMode,
) -> Self
pub fn new( initial_selected_date: Option<CalendarDate>, initial_displayed_month: Option<YearMonth>, year_range: RangeInclusive<i32>, is_selectable_date: Option<CallbackWith<CalendarDate, bool>>, is_selectable_year: Option<CallbackWith<i32, bool>>, display_mode: DatePickerDisplayMode, ) -> Self
Creates a date picker state.
is_selectable_date and is_selectable_year are optional. None
allows every date or year. When a callback is supplied, it must already
have been created during a component build.
Sourcepub fn selected_date(&self) -> Option<CalendarDate>
pub fn selected_date(&self) -> Option<CalendarDate>
Returns the selected date, if any.
Sourcepub fn displayed_month(&self) -> YearMonth
pub fn displayed_month(&self) -> YearMonth
Returns the month currently displayed by the picker.
Sourcepub fn display_mode(&self) -> DatePickerDisplayMode
pub fn display_mode(&self) -> DatePickerDisplayMode
Returns the display mode.
Sourcepub fn year_range(&self) -> &RangeInclusive<i32> ⓘ
pub fn year_range(&self) -> &RangeInclusive<i32> ⓘ
Returns the year range allowed by this picker.
Sourcepub fn is_selectable_date(&self) -> Option<CallbackWith<CalendarDate, bool>>
pub fn is_selectable_date(&self) -> Option<CallbackWith<CalendarDate, bool>>
Returns the date predicate, if one is set.
None means every date is selectable, subject to the year range and
year predicate.
Sourcepub fn is_selectable_year(&self) -> Option<CallbackWith<i32, bool>>
pub fn is_selectable_year(&self) -> Option<CallbackWith<i32, bool>>
Returns the year predicate, if one is set.
None means every year is selectable, subject to the year range.
Sourcepub fn set_selected_date(&mut self, date: CalendarDate) -> bool
pub fn set_selected_date(&mut self, date: CalendarDate) -> bool
Sets the selected date if it is allowed.
Sourcepub fn clear_selected_date(&mut self)
pub fn clear_selected_date(&mut self)
Clears the selected date.
Sourcepub fn set_displayed_month(&mut self, month: YearMonth)
pub fn set_displayed_month(&mut self, month: YearMonth)
Updates the displayed month, clamped to the year range.
Sourcepub fn next_month(&mut self)
pub fn next_month(&mut self)
Moves the displayed month forward by one, staying within the year range.
Sourcepub fn previous_month(&mut self)
pub fn previous_month(&mut self)
Moves the displayed month backward by one, staying within the year range.
Sourcepub fn set_display_mode(&mut self, mode: DatePickerDisplayMode)
pub fn set_display_mode(&mut self, mode: DatePickerDisplayMode)
Updates the display mode.
Sourcepub fn toggle_display_mode(&mut self)
pub fn toggle_display_mode(&mut self)
Toggles between picker and input modes.
Sourcepub fn set_year_range(&mut self, year_range: RangeInclusive<i32>)
pub fn set_year_range(&mut self, year_range: RangeInclusive<i32>)
Updates the allowed year range.
Sourcepub fn set_is_selectable_date(
&mut self,
is_selectable_date: Option<CallbackWith<CalendarDate, bool>>,
)
pub fn set_is_selectable_date( &mut self, is_selectable_date: Option<CallbackWith<CalendarDate, bool>>, )
Updates the date predicate.
None means every date is selectable. A callback must be created during
a component build, so call this setter from inside a #[tessera]
component.
Sourcepub fn set_is_selectable_year(
&mut self,
is_selectable_year: Option<CallbackWith<i32, bool>>,
)
pub fn set_is_selectable_year( &mut self, is_selectable_year: Option<CallbackWith<i32, bool>>, )
Updates the year predicate.
None means every year is selectable. A callback must be created during
a component build, so call this setter from inside a #[tessera]
component.
Trait Implementations§
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§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>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§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.§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.