GPUI Box GitHub

Components / datetime

Calendar view

A month of days.

A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).

use gpui_kit::datetime::Calendar;

Reviewed in calendar.

Construct
new(ident: impl Into<Ident>, adapter: SharedDateAdapter, _window: &mut Window, cx: &mut Context<Self>) -> Self
Options

Chain onto the value.

selected(days: impl IntoIterator<Item = Day>) -> Self
multi(multi: bool) -> Self
month(month: MonthKey) -> Self
overlay(overlay: impl Fn(Day) -> Option<DayMark> + 'static) -> Self
range(range: DayRange) -> Self
Commands

Need a Context, so they need a view.

set_control_size(size: ControlSize, cx: &mut Context<Self>)
set_multi(multi: bool, cx: &mut Context<Self>)
reset_navigation(cx: &mut Context<Self>)
set_selection(days: Vec<Day>, cx: &mut Context<Self>)
set_overlay(overlay: impl Fn(Day) -> Option<DayMark> + 'static, cx: &mut Context<Self>)
set_range(range: Option<DayRange>, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
set_hovered_day(day: Option<Day>, cx: &mut Context<Self>)
shift(delta: i32, cx: &mut Context<Self>)
show_month(month: MonthKey, cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

is_disabled() -> bool
adapter() -> &SharedDateAdapter
selection() -> &[Day]
cursor() -> Option<Day>
hovered_day() -> Option<Day>
shown_month() -> Option<MonthKey>
Reports

The variants of the event it emits. It never applies the change itself.

  • Picked
  • MonthShown
  • Hovered
Example · calendar
fn calendar(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure(window, cx);
    let theme = cx.theme().clone();
    let dates = cx.global::<SceneDates>();
    let (month, unknown) = (dates.month.clone(), dates.unknown.clone());
    stack(&theme)
        .child(
            row(&theme)
                .items_start()
                .gap(px(theme.space(Space::Lg)))
                .child(month)
                .child(unknown),
        )
        .child(
            crate::foundation::text(
                &theme,
                TypeScale::Body,
                "Every weekday name, month name, and blocked reason above came from the \
                     host. The calendar on the right has no today, so it draws no ring and \
                     guesses no month.",
            )
            .max_w(px(560.0))
            .text_tone(&theme, TextTone::Muted),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/datetime/calendar.rs