Skip to main content

Module date

Module date 

Source
Expand description

Calendar — a date picker: the closed face of a select over an anchored month grid.

An entity for the same reason crate::combobox::Combobox is one. It owns navigation state the app has no opinion about — which month is on screen, where the keyboard cursor sits — and reports the one thing the app does care about, through CalendarEvent. A select needs no such component, because a select has no state but the caller’s; a calendar does.

Date is bezel’s own, deliberately. chrono is already in the graph under gpui, so taking it would cost nothing to compile — and would make it a public dependency, so a consumer declaring its own chrono would end up with two incompatible ones. That is the split-graph failure bezel::gpui exists to prevent, and it buys nothing here: a picker needs no timezones, no parsing and no formatting. It needs the civil calendar, which is sixty lines and pure — everything above the horizontal rule below is testable without a window, and is tested.

ui::date::init(cx);   // once, at startup
let picker = cx.new(|cx| Calendar::new(today, cx));
cx.subscribe(&picker, |_, _, event, _| match event {
    CalendarEvent::Selected(date) => { /* the chosen day */ }
})
.detach();

Structs§

Calendar
Confirm
Date
A day in the proleptic Gregorian calendar.
Dismiss
NextDay
NextMonth
NextWeek
PrevDay
PrevMonth
PrevWeek

Enums§

CalendarEvent
What the picker reports. Emitted on choosing a day, never on merely moving the cursor over one.
Weekday

Constants§

GRID_CELLS
Cells in a month grid.
GRID_ROWS
Rows of a month grid — six, always.
KEY_CONTEXT
The key context the picker claims, closed as well as open — enter on a focused-but-closed picker opens it, the way a focused button presses.
MONTHS
English month names. There is no locale system here and there will not be one until something needs it: localizing means shipping ICU, and an app that needs it can draw its own grid from month_grid, which is the reusable half.

Functions§

bindings
The picker’s keymap, as data, so an app can have it without having to take it — see crate::keys for layering over it or taking a chord away.
days_in_month
Length of a month, or 0 for a month outside 1..=12 — which no Date can hold, so only an unchecked caller can see it.
init
Install the bindings — bindings, bound. Call once, alongside crate::input::init.
is_leap
month_grid
The block a month is drawn in: 42 real dates, beginning on the start weekday on or before the 1st.
weekday_labels
Two-letter weekday headings, in the order a week starting on start runs.