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
- Next
Month - Next
Week - PrevDay
- Prev
Month - Prev
Week
Enums§
- Calendar
Event - 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 —
enteron 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::keysfor layering over it or taking a chord away. - days_
in_ month - Length of a month, or
0for a month outside1..=12— which noDatecan hold, so only an unchecked caller can see it. - init
- Install the bindings —
bindings, bound. Call once, alongsidecrate::input::init. - is_leap
- month_
grid - The block a month is drawn in: 42 real dates, beginning on the
startweekday on or before the 1st. - weekday_
labels - Two-letter weekday headings, in the order a week starting on
startruns.