Skip to main content

CalendarState

Struct CalendarState 

Source
pub struct CalendarState {
    pub year: i32,
    pub month: u32,
    pub selected_day: Option<u32>,
    /* private fields */
}
Expand description

State for the calendar date picker widget.

Fields§

§year: i32

Current display year.

§month: u32

Current display month (1–12).

§selected_day: Option<u32>

Currently selected day, if any (single-date mode).

Implementations§

Source§

impl CalendarState

Source

pub fn new() -> Self

Create a new CalendarState initialized to the current month.

Source

pub fn from_ym(year: i32, month: u32) -> Self

Create a CalendarState for a specific year and month.

Source

pub fn with_range(&mut self) -> &mut Self

Enable date-range selection (start/end via Shift-extend).

Single-date mode remains the default; call this to opt in. Returns &mut Self for chaining. Available since 0.21.0.

§Example
use slt::CalendarState;

let mut cal = CalendarState::from_ym(2024, 3);
cal.with_range();
Source

pub fn with_time(&mut self) -> &mut Self

Enable hour/minute selection, rendered as HH:MM below the grid.

Off by default — no time row is rendered unless enabled. Returns &mut Self for chaining. Available since 0.21.0.

§Example
use slt::CalendarState;

let mut cal = CalendarState::from_ym(2024, 3);
cal.with_time();
Source

pub fn mode(&self) -> CalendarSelect

The active selection mode (Single by default).

Available since 0.21.0.

§Example
use slt::{CalendarSelect, CalendarState};

let cal = CalendarState::from_ym(2024, 3);
assert_eq!(cal.mode(), CalendarSelect::Single);
Source

pub fn selected_date(&self) -> Option<(i32, u32, u32)>

Returns the selected date as (year, month, day), if any.

Source

pub fn selected_range(&self) -> Option<(CalDate, CalDate)>

The normalized selected range as (start, end) with start <= end.

Returns None in single-date mode or until an anchor has been set in range mode. Endpoints are absolute CalDates, so a range may span month or year boundaries. Available since 0.21.0.

§Example
use slt::CalendarState;

let mut cal = CalendarState::from_ym(2024, 3);
cal.with_range();
assert!(cal.selected_range().is_none());
Source

pub fn selected_time(&self) -> Option<(u8, u8)>

The selected (hour, minute) when time is enabled, else None.

Available since 0.21.0.

§Example
use slt::CalendarState;

let mut cal = CalendarState::from_ym(2024, 3);
assert!(cal.selected_time().is_none());
cal.with_time();
assert_eq!(cal.selected_time(), Some((0, 0)));
Source

pub fn prev_month(&mut self)

Navigate to the previous month.

Source

pub fn next_month(&mut self)

Navigate to the next month.

Trait Implementations§

Source§

impl Clone for CalendarState

Source§

fn clone(&self) -> CalendarState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CalendarState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CalendarState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.