Skip to main content

DatePickerState

Struct DatePickerState 

Source
pub struct DatePickerState { /* private fields */ }
Expand description

A date picker’s state: selection, displayed month, view, mode and the keyboard cursor. Create it once per picker with cx.new and hand it to DatePicker.

Implementations§

Source§

impl DatePickerState

Source

pub fn new( labels: DatePickerLabels, today: NaiveDate, cx: &mut Context<'_, Self>, ) -> Self

A single-date picker showing today’s month, with nothing selected.

Source

pub fn range(self) -> Self

Select a range instead of a single date.

Source

pub fn selection(self, selection: impl Into<DateSelection>) -> Self

Start with selection, showing its (first) month.

Source

pub fn disabled_dates(self, matcher: impl Into<DateMatcher>) -> Self

Dates matching matcher cannot be selected.

Source

pub fn years(self, years: RangeInclusive<i32>) -> Self

The years the year grid and lists offer.

Source

pub fn first_day_of_week(self, day: Weekday) -> Self

The weekday each grid row starts on (default Sunday).

Source

pub fn view(self, view: DatePickerView) -> Self

Start in view (e.g. a specimen of the year grid).

Source

pub fn input_mode(self) -> Self

Start in text-input mode.

Source

pub fn with_inputs( self, start: Entity<InputState>, end: Option<Entity<InputState>>, cx: &mut Context<'_, Self>, ) -> Self

Edit typed dates in these Kit inputs (the second for a range’s end). The picker parses them with DatePickerLabels::parse_input.

Source

pub fn labels(&self) -> &DatePickerLabels

Source

pub fn focus_handle(&self) -> &FocusHandle

Source

pub fn value(&self) -> DateSelection

Source

pub fn today(&self) -> NaiveDate

Source

pub fn displayed_month(&self) -> (i32, u32)

The displayed (year, month).

Source

pub fn current_view(&self) -> DatePickerView

Source

pub fn mode(&self) -> DateInputMode

Source

pub fn cursor(&self) -> NaiveDate

The keyboard cursor’s date.

Source

pub fn is_range(&self) -> bool

Source

pub fn is_disabled(&self, date: NaiveDate) -> bool

Source

pub fn set_value( &mut self, selection: DateSelection, cx: &mut Context<'_, Self>, )

Replace the selection without emitting.

Source

pub fn select(&mut self, date: NaiveDate, cx: &mut Context<'_, Self>) -> bool

Select date as a person would: a single picker replaces its date; a range starts, completes (when date is not before the start) or restarts, as in gpui_base::CalendarState::select_date. Disabled dates are ignored. Returns whether the selection changed.

Source

pub fn clear(&mut self, cx: &mut Context<'_, Self>)

Clear the selection (keeping single or range).

Source

pub fn show_month(&mut self, year: i32, month: u32, cx: &mut Context<'_, Self>)

Show year/month, sliding from the current month. Months outside years show the nearest month inside them.

Source

pub fn next_month(&mut self, cx: &mut Context<'_, Self>)

Source

pub fn previous_month(&mut self, cx: &mut Context<'_, Self>)

Source

pub fn next_year(&mut self, cx: &mut Context<'_, Self>)

Source

pub fn previous_year(&mut self, cx: &mut Context<'_, Self>)

Source

pub fn set_view(&mut self, view: DatePickerView, cx: &mut Context<'_, Self>)

Switch the body between the day grid, the year grid/list and the docked month list.

Source

pub fn toggle_view(&mut self, view: DatePickerView, cx: &mut Context<'_, Self>)

Toggle view against the day grid.

Source

pub fn choose_year(&mut self, year: i32, cx: &mut Context<'_, Self>)

Choose a year from the year grid or list and return to the days.

Source

pub fn choose_month(&mut self, month: u32, cx: &mut Context<'_, Self>)

Choose a month from the docked list and return to the days.

Source

pub fn toggle_mode(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)

Switch between calendar and text input. Entering input mode writes the selection into the inputs; leaving it parses them.

Source

pub fn parse_inputs(&mut self, cx: &mut Context<'_, Self>)

Parse the text inputs into the selection. Invalid or disabled text marks its field invalid and leaves the selection unchanged.

Trait Implementations§

Source§

impl EventEmitter<DatePickerEvent> for DatePickerState

Source§

impl Render for DatePickerState

Source§

fn render( &mut self, _: &mut Window, _: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.

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> AutoreleaseSafe for T
where T: ?Sized,

Source§

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

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
§

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

§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

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

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