pickers
@profile(t2);
import ui from "ui";
import widgets from "widgets";
import pickers from "pickers";
component EventForm {
var title: string = "";
var day: ?pickers.Date = null;
var starts: ?pickers.Time = null;
var sizes: [4]i64 = [30, 30, 30, 30];
fn set_title(v: []const u8) { title = "{v}"; }
fn set_day(d: ?pickers.Date) { day = d; }
fn set_starts(t: ?pickers.Time) { starts = t; }
fn save() {
if (day == null || starts == null) { return; }
// day!.year, day!.month, day!.day, starts!.hour, starts!.minute
}
view {
widgets.Pane {
ui.Column { padding: 12; gap: 8; sizes: sizes[0..4];
widgets.TextInput { value: title; placeholder: "Title"; on_change: set_title; }
pickers.DateInput { value: day; min: pickers.today(); on_change: set_day; label: "Date"; }
pickers.TimeInput { value: starts; on_change: set_starts; label: "Starts"; }
widgets.Button { label: "Save"; variant: widgets.Variant.Accent; on_click: save; }
}
}
}
}
pub fn main() -> i32 {
let app = EventForm {};
ui.run(app, 360, 220, "New event") or { return 1; };
return 0;
}In Finland that form shows “9.11.2026” and “18.00”; in the US
“11/9/26” and “6:00 PM”; in Sweden “2026-11-09” and “18:00”. The fields
draw like a widgets.TextInput and follow the theme,
or take your colours with TextInput’s own props (Styling).
pickers is a module of its own, apart from widgets, because the
locale’s formats come from intl and its CLDR data (about 4
MB): a program pays for them when it imports pickers, not for every
widget.
Dates and times
let d: pickers.Date = pickers.date(2026, 11, 9)!; // null for 2026-02-30
let next: pickers.Date = d.add_days(7);
let later: pickers.Date = d.add_months(1); // Jan 31 + 1 month is Feb 28
d.weekday() // 1 Monday ... 7 Sunday
d.cmp(next) // -1, 0, 1
let at: time.DateTime = d.to_datetime(); // that day at 00:00
let t: pickers.Time = pickers.Time { hour: 18; minute: 30; };
pickers.today() // the system's local dateA Date is a day on the calendar, with no time and no time zone (an
event’s date is the same day wherever you read it); a Time is an hour
0-23 and a minute. A field with nothing in it has the value null.
Turning a date and a time into an instant in a zone is yours: time and
intl.zone.
DateInput
pickers.DateInput { value: day; on_change: set_day; }
pickers.DateInput { value: day; locale: "en-GB"; min: first; max: last; on_change: set_day; }| Prop | |
|---|---|
value: ?Date | The date shown; null shows the empty field (and placeholder) |
locale: string | A language tag, "fi", "en-US", "sv-FI"; "" (the default) is the active locale (locale.get), English when there is none |
min, max: ?Date | The first and last dates allowed |
today: ?Date | The day the calendar marks as today and short years count from; null: pickers.today() |
placeholder, label | The empty field’s hint; its accessible name |
disabled, error | No input; the red ring (your own check, an end before its start) |
error_text | Your own message for text that doesn’t read |
bg, fg, border_color | The box’s fill, the text’s colour, the border; unset (the default) the theme’s (Styling) |
hovered_bg, hovered_fg, hovered_border_color, focused_bg, focused_fg, focused_border_color | The same while the pointer is over it, while it has the focus (or its calendar is open) |
radius | Round corners, in pixels (0: square; 99: a pill) |
transition, transition_ease | Milliseconds the colours take to a state’s, and the curve |
Event: on_change(d: ?Date). States: focused, hovered, open.
Typing. The field reads what the user typed when they are done with
it: Return, Tab or a click elsewhere, Escape. on_change fires then, not
on each key, and the text becomes the locale’s format. The numbers are
read in the locale’s order (day-month-year in Finland, Germany and the
UK, month-day-year in the US, year-month-day in Sweden and Japan), with
any separators: “9.11.2026”, “9/11/2026”, “9 11 26”, “091126”,
“2026-11-09” (always), “2026年11月9日”. Two numbers are a day and a month
this year (“9.11” is 9 November). A two-digit year is the one within 80
years before and 20 after today (“26” is 2026, “70” 1970).
Text it can’t read fires nothing and keeps what was typed, with a message
under the field in red: “Not a date. Type it like 8.11.2026.” (an example
in the field’s own format); a date before min or after max says “Pick
a date from 1.11.2026 to 30.11.2026.”. The messages follow the program’s
language (locale.set; English, Finnish, Swedish, German and Japanese).
Emptying the field fires on_change(null).
Keys. Up and Down move a day. Alt+Down or F4 open the calendar, as does the button at the field’s right.
The calendar drops down under the field (above it near the bottom of
the window): the month and year with arrows to the previous and next
month, the weekday names starting on the locale’s first day of the week
(Monday in Finland, Sunday in the US and Japan), today ringed, the chosen
day filled, days outside min..max greyed. Click a day, or use the
keys: the arrows move a day or a week, Page Up and Page Down a month
(Shift: a year), Home and End the week’s first and last day, Return or
Space choose, Escape closes. A click outside closes it too.
TimeInput
pickers.TimeInput { value: starts; on_change: set_starts; }
pickers.TimeInput { value: starts; hour_cycle: pickers.HourCycle.H23; step: 15; on_change: set_starts; }| Prop | |
|---|---|
value: ?Time | The time shown |
locale | As DateInput’s |
hour_cycle | Locale (the default: 24-hour in Finland, 12-hour in the US), H12, H23 |
step | The minutes Up and Down move (5): to the next multiple, so 18:03 goes up to 18:05 |
placeholder, label, disabled, error, error_text | As DateInput’s |
bg, fg, border_color, their hovered_ and focused_ variants, radius, transition, transition_ease | As DateInput’s |
Event: on_change(t: ?Time). It reads “18.00”, “18:00”, “1800”, “18”,
“6pm”, “6:00 PM”, “6.00 ip.”, “午後6:00”, “18h00”: the numbers with or
without a separator, and am/pm in the locale’s words or plain am/pm.
Without am/pm the hour is 0-23 in every locale.
Styling
The fields take the styling props of
widgets.TextInput, with the same names,
defaults and meaning, so they sit on a card beside your other fields:
component EventCard {
var title: string = "";
var day: ?pickers.Date = null;
var starts: ?pickers.Time = null;
var sizes: [3]i64 = [30, 30, 30];
fn set_title(v: []const u8) { title = "{v}"; }
fn set_day(d: ?pickers.Date) { day = d; }
fn set_starts(t: ?pickers.Time) { starts = t; }
view {
widgets.Pane { bg: #E9E9EE;
ui.Column { padding: 12; gap: 8; sizes: sizes[0..3];
widgets.TextInput { value: title; placeholder: "Title"; on_change: set_title;
bg: #F4F4F7; fg: #1D1D22; border_color: #C9C9D1; focused_border_color: #3A6FD8; radius: 6; }
pickers.DateInput { value: day; on_change: set_day; placeholder: "Date";
bg: #F4F4F7; fg: #1D1D22; border_color: #C9C9D1; focused_border_color: #3A6FD8; radius: 6; }
pickers.TimeInput { value: starts; on_change: set_starts; placeholder: "Starts";
bg: #F4F4F7; fg: #1D1D22; border_color: #C9C9D1; focused_border_color: #3A6FD8; radius: 6; }
}
}
}
}- With every colour unset the field is the theme’s look. Set one and it
paints flat in your colours, the theme’s filling in the rest; the border
turns the theme’s focus colour while focused (unless you give
focused_border_color) and red on an error, as a TextInput’s does. - The placeholder is a soft version of the text colour:
fgwhen it is set, the theme’s ink when not. The calendar button at aDateInput’s right takes the text colour too. - The calendar drop-down keeps the theme’s look: it floats over the window, not on your card. The message under a field stays red.
Calendar
pickers.Calendar { value: day; on_pick: set_day_from_calendar; } // fn set_day_from_calendar(d: pickers.Date)The month grid on its own, CAL_W x CAL_H (254 x 278), for a page that
shows a month: the same props as DateInput but placeholder and the
messages, and the events on_pick(d: Date) and on_cancel() (Escape).
go_to(d) shows d’s month with the keys’ cursor on it; shown() is the
month shown, cursor() the day the keys are on.
cal.anchor(x, y, w, h) makes it a drop-down under that rectangle, for a
control of your own: show it with ui.show_dialog(cal) and close it
(ui.close_dialog()) in its on_pick and on_cancel, as DateInput
does.
Formats
let f: pickers.Formats = pickers.formats("fi");
f.format_date(d) // "9.11.2026"
f.parse_date("9.11", pickers.today()) // 9 November this year, or PickError.Unreadable / Empty
f.format_time(t) // "18.30"
f.parse_time("6:30 pm") // Time { hour: 18; minute: 30; }
f.month_title(2026, 11) // "marraskuu 2026"
f.weekday_name(1) // "ma"
f.first_weekday // 1 (Monday)What the fields use, for text of your own: formats(tag, cycle) with
"" for the active locale. order is the date’s field order ("dmy"),
h12 whether the clock is 12-hour.
Notes
- The fonts
widgetscarries have Latin letters only: Japanese, Chinese or Korean month and weekday names need a font with them (widgets.use_fonts). - Only the Gregorian calendar, as
intl.
Last modified: