Skip to content

Time Picker

timepicker.Picker edits a time.Duration, either as a clock time (ClockFormat, e.g. 06:45) or decomposed into days, hours, minutes and seconds (DecomposedFormat). Choose the visible units with Days, Hours, Minutes and Seconds.

Time Picker

func view(wnd core.Window) core.View {
    alarm := core.AutoState[time.Duration](wnd).Init(func() time.Duration {
        return 6*time.Hour + 45*time.Minute
    })
    timeout := core.AutoState[time.Duration](wnd).Init(func() time.Duration {
        return 1*time.Hour + 30*time.Minute
    })

    return VStack(
        timepicker.Picker("Alarm", alarm).
            Format(timepicker.ClockFormat).
            Frame(Frame{}.FullWidth()),
        timepicker.Picker("Session timeout", timeout).
            Format(timepicker.DecomposedFormat).
            Days(false).Seconds(false).
            SupportingText("Hours and minutes").
            Frame(Frame{}.FullWidth()),
    ).Gap(L16).Frame(Frame{Width: L320})
}

Constructors

func Picker(label string, selectedState *core.State[time.Duration]) TPicker

Picker renders a time.Duration either in clock time format or in decomposed format.

Methods

MethodDescription
AccessibilityLabel(label string) ui.DecoredViewAccessibilityLabel sets a label used by screen readers for accessibility.
Border(border ui.Border) ui.DecoredViewBorder sets the border style of the time picker.
Days(showDays bool) TPickerDays toggles whether the picker allows selecting days.
Disabled(disabled bool) TPickerDisabled enables or disables user interaction with the time picker.
ErrorText(text string) TPickerErrorText sets the validation or error message displayed below the picker.
Format(format PickerFormat) TPickerFormat sets the display format for the duration value (clock or decomposed).
Frame(frame ui.Frame) ui.DecoredViewFrame sets the layout frame of the time picker, including size and positioning.
Hours(showHours bool) TPickerHours toggles whether the picker allows selecting hours.
Minutes(showMinutes bool) TPickerMinutes toggles whether the picker allows selecting minutes.
Padding(padding ui.Padding) ui.DecoredViewPadding sets the inner spacing around the time picker content.
Seconds(showSeconds bool) TPickerSeconds toggles whether the picker allows selecting seconds.
SupportingText(text string) TPickerSupportingText sets helper or secondary text displayed below the picker label.
Title(title string) TPickerTitle sets the title of the picker, typically shown in dialogs.
Visible(visible bool) ui.DecoredViewVisible controls the visibility of the time picker; setting false hides it.
WithFrame(fn func(ui.Frame) ui.Frame) ui.DecoredViewWithFrame applies a transformation function to the picker’s frame and returns the updated component.

Related