GPUI Box GitHub

Components / datetime

DateInput view

A text field over a host-owned calendar, with that calendar in a popover.

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

use gpui_kit::datetime::DateInput;

Reviewed in date-time touch-dates.

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

Chain onto the value.

name(name: impl Into<SharedString>) -> Self
value(day: Day) -> Self
presentation(presentation: popover::PickerPresentation) -> Self
required(required: bool) -> Self
invalid(invalid: bool) -> Self
Commands

Need a Context, so they need a view.

set_name(name: impl Into<SharedString>, cx: &mut Context<Self>)
set_presentation(presentation: popover::PickerPresentation, cx: &mut Context<Self>)
set_required(required: bool, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
set_invalid(invalid: bool, cx: &mut Context<Self>)
set_value(day: Option<Day>, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
open(cx: &mut Context<Self>)
close(cx: &mut Context<Self>)
toggle(cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

is_disabled() -> bool
field() -> &Entity<TextInput>
calendar() -> &Entity<Calendar>
current() -> Option<Day>
parsed_day(cx: &App) -> Option<Day>
message() -> Option<&SharedString>
is_open() -> bool
shown_text(cx: &App) -> SharedString
is_invalid() -> bool
Reports

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

  • Changed
  • Unparsable
  • Opened
  • Closed
  • Submit
Example · date-time
fn date_time(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure(window, cx);
    let theme = cx.theme().clone();
    let dates = cx.global::<SceneDates>();
    let (field, refused, clock, twelve) = (
        dates.field.clone(),
        dates.refused.clone(),
        dates.clock.clone(),
        dates.twelve.clone(),
    );
    stack(&theme)
        .child(div().w(px(280.0)).child(field))
        .child(div().w(px(280.0)).child(refused))
        .child(
            row(&theme)
                .gap(px(theme.space(Space::Lg)))
                .child(clock)
                .child(twelve),
        )
        .child(
            crate::foundation::text(
                &theme,
                TypeScale::Body,
                "What the field could not read is still in it, and the refusal is the \
                     adapter's own sentence.",
            )
            .max_w(px(560.0))
            .text_tone(&theme, TextTone::Muted),
        )
        .into_any_element()
}

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