module ui_appsource
The app services of pkg::alloy::ui (REFOCUS.md, R6e, question 9A): screens and history, numbers moving, dates in the locale, forms, requests, storage, file dialogs and drops, on the core's widgets and ui_controls'.
import pkg::alloy::ui;
import pkg::alloy::ui_app;
fn main() -> i32 {
return app(&WindowConfig { .title = &"Notes", .app = &"notes" }, (ui) => {
const notes = ui.persisted(&"notes", String::empty(), Write::text(), Read::text());
return ui.add(Text { .text = copy notes.get(&ui) });
});
}
Each keeps its state as an extension of the Ui (Extension), installed
as it is first used, so a program not using one carries none of its
code.
## How it was built
**R6f as built** (2026-10-26; REFOCUS.md, the portal and
drops under ui_app): Files calls the window's install_files as it
first gives the window something, so the portal's file chooser, the
shell's dialogs, NSOpenPanel and the drop targets are linked only into
programs asking for a dialog or laying out a DropArea; on Linux the
settings portal's wish for less motion comes with them (or with
pkg::alloy::ui_access), else reads as off.
**R6e as built** (2026-10-26): moved out of ui, whose notes of F11c,
F11d, F11e, F12c, F12d, F12e and F13 tell how each was first built,
with their notes here: screens.alloy (Navigator, ui.screens, the
window's history, screens pushed and popped moving), animations.alloy
(ui.animated), dates.alloy (Calendar, DatePicker, TimePicker,
ui.today(), ui.locale() with CLDR's tables), forms.alloy,
network.alloy (ui.send, ui.load), persisted.alloy (ui.store(),
ui.persisted), files.alloy (ui.open_files, save_file,
save_bytes, DropArea). Hooks became extensions: Navigation (Back,
Alt+Left, Event::Navigated, the window's history as it is shown),
Animations, Dates, Forms (a field's focus left), Requests (an
owner going, the network's deadline, busy nodes, the page's inbox),
KeptState (the store written after each event and as the window
closes), Files (dialogs' results, drags and drops). The network's
tasks run as the core's Service, started by the first request in the
scope app gives its workers. on_drop on Column, Row and Stack
became the DropArea widget, and ReplayConfig.responses the
replay taking them.
**F11c as built** (2026-10-15; decisions/F11.md, "Screens", questions 5A and 6B), the part ui_app holds since R6e:
- Navigators:
Navigator<R>a handle on a signal ofRoutes<R>(the routes, a serial each telling a route replaced, the routesbacktook, kept for Forward, the paths and the screens' element);navigator,navigator_with,push,back,replace,reset,current,depth.ui.screens(nav, screen)is a transparent element keeping a screen a route: those whose serials stay are kept, those above freed with all they made, new ones made, all but the top hidden. A screen hidden under a new one keeps the element that had the focus in it; once laid out, a screen shown again gives that element the focus, a new one its first taking it (ui.focus_after). - Back:
nav.back, the mouse's Back button (natively; on the web the browser goes back by it, which comes as Navigated), Alt+Left or Command+[ on macOS before the focused element, each to the deepest navigator on screen (alive, its screens in no hidden view) with more than one screen; navigators areNavigableobjects inui.navigators, forgotten once gone. - History (question 6B): after each event the Ui gives the window
set_history(depth, path), the depth 1 and one more for each screen over a first among the navigators on screen, the path the deepest one's with paths.Event::Navigatedtakes the navigators back or forward until as deep, forward bringing back whatbacktook, the last step the entry's path's screen when it parses. The first navigator with paths starts at the path the page opened at (window.start_path()), over its first screen, unless it is the first's own.
**F11d as built** (2026-10-15; decisions/F11.md, "Dates and times", questions 8A, 9A and 10A):
- std::time's calendar (question 8A):
MonthandWeekdaytagged with their numbers,Date(a struct==compares, soEqualwith no marker) withof,try_of,from_days,today,days,weekday,add_days,add_months,compare,before,after, written as ISO 8601;TimeOfDaywritten14:30;local_offsetthrough a newal_sys_local_offsetin each system file, the page'sDateon the web. Calendar(dates.alloy): the month's title between two chevron buttons (markspreviousandnext, made as one first lays out), the weekdays' first two letters fromfirst_weekday, and six weeks of 36-pixel days, those of other months left blank. The chosen day is a filled circle, today a ring, the keyboard's day a rounded square; days outsideearliestandlatestmuted, thoseavailablerefuses muted and struck through. One Tab stop: Left and Right a day, Up and Down a week, Page Up and Down a month, with Shift a year, Home and End the week's ends, all kept within the range; the month follows the day and is announced (ui.announce, polite); Enter, Space or a click choose; the buttons turn the month, the day moving with it. A program choosing a day in another month shows that month. English names (question 9A):month_name,weekday_name,long_date("15 October 2026"),month_title("October 2026"), which F12e replaced by the locale's.ui.today()is the day calendars take as today,ui.set_todayfixes it for tests and goldens.DatePicker: a field like a Select's showingformat's text or the placeholder, as wide as the longest month's day, opening a Calendar of its options in a popup below it by a click, Enter, Space, Down or Expand; choosing a day closes it first, the day already chosen unheard.TimePicker(question 10A): aSelect<TimeOfDay>it makes from its options as it first lays out and renews after, the times fromearliesttolatestbystep_minutes; Select's input becamehandle(ui, input, closed),closedtelling the element holding it that its list closed.TimeOfDaysatisfiesEqualwith no marker.- Accessibility: the calendar is a
Griddescribed by its month, its daysGridCellparts labelled "Thursday 15 October 2026" with their row and column (window's newSemantics.cell),selected,disabledoutside the range or refused, todaycurrent; a DatePicker a button with the date as its value andexpanded, which every tree gives (question 19A); a TimePicker a combo box. - Size (question 16A): the counter grew by 14.3 KB natively (1,813,040 bytes) and 1.4 KB on the web (1,296,717): the grid roles in each tree, AT-SPI's Table and TableCell interfaces most of it natively; the widgets come only with a program using them.
- Tests: five in
ui/tests.alloy(a calendar's keys across months and years and its announcements; its pointer, buttons and range; its tree; a date picker by the pointer and the keys; a time picker's choices and type-ahead); goldenscalendar.png,calendar_dark.pnganddate_picker_open.png; std'scalendarandtime_zonetests;tests/atspireads a date picker's calendar through Table and picks a day,tests/automation(by hand on Windows) the same through Grid and SelectionItem. - Sample
booking.alloy: a visit booked from an inline calendar of the next three months (Mondays closed, a few days sold out) and a time from 10:00 to 18:00 by half hours, and the same as a form with a date picker, a time picker and a summary.
**F11e as built** (2026-10-15; decisions/F11.md, "Motion", questions 11A, 12A and 13A), the part ui_app holds since R6e:
ui.animated(value, motion) -> Animated: a signal of a course,getgiving where it is at the Ui's time and recording the read;set(question 21: the design'stois a keyword),jump,target. A new target adds a move of the difference beside those under way, each eased from its own start, so the value is continuous and its speed kept (four at most, then gathered into one); a repeated motion goes from where it is. Under reduced motion, unless essential,setjumps.
**F12c as built** (2026-10-16; decisions/F12.md, "Waiting in ui", questions 4A, 7A and 8C):
ui.send(request, then) -> Pending,cancel_request,progress;ui.load(request, read, LoadOptions) -> Resource<T>withstate,stage(aStagekey forswitch),latestandreload;Loading<T>,Failure(Format: "the server answered 503").network.alloy: each request is an exchange slot belonging to an owner (the element's whose handler sent it), whose going cancels it; what came back runs as a handler at the next update,thennever once cancelled. A resource's request is a binding: run again when a signal it read changes, it cancels the exchange under way and starts the next afterdelay(the first at once), None waiting for nothing; the last Done is kept aslatestwhile the next loads (keep). A failure the user asked for (send,reload) is announced assertively.- Where requests run: natively on eight network tasks in
app's scope beside the four workers (since question 20B started by the first request: "Sizes after F12"), serving the same loop (a job takes the network's state,Workers.network); a task makes aControlper exchange, listed by the Ui's id so the UI thread cancels it and reads its progress,readrunning on the task, and the result goes back through the background work's channel and waker. Closing the window cancels what is under way and refuses what is queued. Since question 18A (2026-10-16) the app'sNetworkholds astd::http::Clientits tasks send through, so an app's requests share kept connections, disposed with the workers asappends. On the webstd::http::startoverfetch(std'shttp.web.js), its callback putting the result in an inbox on the heap and waking the loop throughWaker::Page. In a replay,ReplayConfig.responses(ScriptedResponse::answered,failed) answer by URL at their script time, the progress going evenly until then, a request none answers failing with Unsupported;replayrunsreadat once. A Ui on its own sends at once (Unsupported in the interpreter). - Progress: while a shown binding reads an exchange's progress (a
send's throughui.progress, a resource's through its state), a timer looks at it every 100 ms (arm_networkbefore the deadline), setting what changed. ProgressBar(value 0 to 1, or None: a third of the track crossing it each second, pulsing under reduced motion), a progress bar to screen readers with its value in percent.busy: an element whose binding read a resource waiting, or the nearest above it with a role, the window when none (an effect now knows its element,Effect.node).- Hooks for an owner going, the deadline, the tree sent, the page's
wake and the window closing, set as the first request goes;
gpu::ResourceisBindingResource(question 19);ui.alloyimportsstd::result as std_result,gpuhaving its ownResult. - std:
JsonReader(std::json),std::http::start,cancelandprogressof anExchangeon the web. - Size (question 20): the counter is 1,831,968 bytes natively
(1,830,080 before, +1.9 KB) and its wasm 1,307,087 (1,305,177, +1.9
KB), built as
bench.shbuilds it. The shows sample is 2.53 MB natively (TLS and std::http with it) and 1.73 MB of wasm. - Tests: five in
ui/tests.alloy(a resource waiting, failing, loading again and keeping its last value; a request asked again after its delay as a search is typed, one request going; progress every 100 ms and owners cancelling; busy and the progress bar in the tree; a Ui on its own), goldensloading,load_failedandprogressin light and dark andloaded;tests/networkagainst the shows server (shows, a hold, a 3 MB ticket with its progress read on the way, a 503, a request cancelled) under weston, under qemu and in node's page through node's fetch;tests/accessandtests/atspiread a progress bar and busy. Under the headless weston frames presented one after another stall for seconds, sotests/networkdraws nothing that changes. - Samples
shows_server.alloy(shows as JSON, holds running out after two minutes, a 3 MB ticket over two seconds, the web build's page,?delay=and?fail=) andshows.alloy(a search loading as one types, a spinner, the reason and Try again, holds counting down to the server's moment, a download with a progress bar and Cancel).
**F12d as built** (2026-10-16; decisions/F12.md, "Storage", question 9A):
WindowConfig.app(window): the name the app's data is kept under, else the title (app_name), also sent as Wayland'sapp_id.ui.store() -> &var KeptStore(persisted.alloy): std::storage's store "app" under the app's name, opened when first asked for, aKeptStoresince the Ui cannot be disposed (question 21); a Ui made on its own has no name and keeps it in memory. After each event, Redraws too, thestoredhook writes what changed: at once when the last write began a second ago or more, else once a timer of the Ui's own says it has; natively on a worker (unsaved, thenwriteon the worker,wroteback on the UI thread), in place with no workers. As the window closes, and as a replay ends,store_endingwrites what is left. The worker's write and the last one take turns throughNetwork.kept, a mutex over how many changes the file holds, so the older never lands over the newer (since question 23B a flag: see "Sizes after F12"). On the web nothing is hooked: each set reaches localStorage at once.ui.persisted(key, initial, write, read) -> Signal<T>: the valuereadtakes from the store, elseinitial; an effect of the signal's owner writes it back as it changes, its first run only reading.- Tests: three in
ui/tests.alloy(saved after the handler, a second apart at most, as the window closes and as a replay ends, the next run starting from it; whatreadrefuses givinginitialbeside the program's own keys; a Ui on its own in memory);tests/storagecounts its runs across two runs under weston, natively and under qemu, each with a data directory of its own, and in node's page over the fake page's localStorage kept in a file (ALLOY_PAGE_STORAGE), then refusing writes (ALLOY_PAGE=full);scripts/test.shgives every program run a data and cache directory of the test's own. - Size: the counter is 1,874,896 bytes natively (1,871,456 before, +3.4
KB) and its wasm 1,335,883 (1,333,439, +2.4 KB), built as
bench.shbuilds it: the app's name kept and sent asapp_id, the hooks' calls and the Ui's and Network's new fields' glue (question 23); window's hello +0.9 KB natively, +0.3 KB of wasm, mostlyapp_id. A counter whose count is persisted is 18.7 KB larger natively and 55 KB of wasm (std::json's exact floats, std::fs and the store). - Sample
preferences.alloy: the dark theme, a name, a basket of four items and five recent searches, each persisted, a line saying where they are kept, and "Forget everything" (question 22).
**F12e as built** (2026-10-16; decisions/F12.md, "Dates in the world", questions 10A-14A; std::time's zones and std::locale's notes have the rest):
- The Ui's locale (question 14A):
ui.locale()is the oneui.set_locale(::Some(locale))set, elseLocale::system(), read only when a date widget or the app asks, so a program showing no date links none of std::locale's tables;kept_localekeeps the system's once read.set_localelays everything out again; since question 27B (2026-10-16) the locale is a signal of the Ui's own, made with it, so bindings readingui.locale()run again too (a test inui/tests.alloy;showtimes.alloy's rows read it). CalendarandDatePicker:first_weekdayis anOption, None the locale's. The calendar writes its title (format_dateof month and year: "October 2026", "octobre 2026", "2026年10月"), the weekdays' short names (Width::Short, "Mon", "lun.", "月", question 30B; at first CLDR's shorterWidth::Shortest, "Mo"; the narrow ones where one is wider than a day, as Arabic's), the days' numbers in the locale's digits and the spoken dates ("Thursday, 15 October 2026") in the locale it last laid out in, keeping its layouts until the locale, the first weekday or the fonts change (Ui.fonts_changed, counted as a window's canvas replaces the bundled fonts and as fonts arrive on the web). In a locale written right to left (Locale.right_to_left(), question 28A, 2026-10-16) the week runs from the right, the month before's button is on the right, each chevron pointing away, and Left and Right go the way the week shows; the cells keep their logical columns in the trees (a test inui/tests.alloy, goldencalendar_ar).DatePicker.formatis anOption, None the locale's medium date ("15 Oct 2026", "Oct 22, 2026", "22 oct. 2026", question 24B, built 2026-10-16 after the long date first); its width is the widest of the year's months' 28th.TimePickerwrites its times on the locale's clock ("14:30", "2:30 PM", throughformat_momenton UTC, question 29) and makes its Select's choices again when the locale changes; type-ahead follows what is shown ("3" goes to 3:00 PM in en-US).- The English
month_name,weekday_name,long_dateandmonth_titleare gone;samples/booking.alloywrites its summary in the locale. - Tests pin
en-GBwhere they pin today, so F11's goldens and access trees stay but for the comma CLDR puts after the weekday in a spoken date ("Thursday, 22 October 2026" intests/atspiandtests/automation); goldenscalendar_frandcalendar_en_us; a test inui/tests.alloyswitching the pickers and the calendar between en-GB, en-US and French. - Benchmark
dates_format(bench/dates.alloy): 10,000 moments with names in French on Paris's clocks, 75 ms (budget 120, question 25). - Size: the counter is 1,875,504 bytes natively (+608 since F12d, 96 of them the Ui's locale) and its wasm 1,336,363 (+480); hello world is unchanged. A program formatting dates with names carries the tables: booking grows by 241 KB natively and 250 KB of wasm (question 26).
- Sample
showtimes.alloy: shows in Paris, New York and Tokyo fromshowtimes.json(RFC 3339 times, read by#read_file), each written on the venue's clocks and the user's with the zones' names, prices in the venue's currency; a Select of locales (the system's, en-US, en-GB, fr, de, ja, ar) changes every date, price and the calendar of the days with a show, and a field goes to a day typed in ISO 8601.
**F13 as built** (2026-10-17; decisions/F13.md, decided as recommended, 1A-5A, 6B, 7A-10A; questions 11-13 then decided A):
- Forms (
forms.alloy):ui.form()is a handle on three signals of the owner making it: the fields' slots with what a submit that passes runs (FormFields, peeked, never read in a binding),triedand thefailureof the whole. A field's slot keeps its label, hint, whether it is required, the signals of its text and itsFieldState(left, a server's refusal), the element showing it and its parsing and rules behind aCheckingobject (Checked<T>, aSource<T>typed by aParser<T>or picked into a signal), so only giving a value is generic;Field<T>is the form and an index.Rule<T>andParser<T>are named function types (the language's 1A), lambdas and named functions taking their place; a typed field'sFieldOptionsleaves its type arguments out (2A).Checked<bool>'s ownunsetandwanted(specializations) make a required box Check one that must be true. - Nothing of a verdict is kept:
verdict,error,validanderrorsparse and check again, so a binding showing an error follows every signal its rules read (a password's repetition follows the password). An error shows once its field was left changed (the text field's focus, through the newfield_focushook a text field calls as it gains or loses the focus, set by the first form), the form was submitted or a server refused it, and from then on as it changes; a picked field's error shows once picked. A field counts while its element exists in no hidden view. submit: the errors in Tab order (each field where the first element taking the focus in its element comes,tab_order), the first focused with the ring and scrolled into view, one assertive announcement ("2 fields need attention: City, Street."), elseon_submit's function.field.refuseshows at once, announces "Card number: ..." and focuses the field when it is the first in error; its next edit clears it.form.refusesetsfailureuntil the next submit, announced.- Showing fields:
ui.text_fieldbinds a TextField (text, error,required, the label for screen readers, the hint as its newdescription,on_change, Enter submitting on one line);ui.inputbinds any widget, recording its element;ui.labelleda column of the label (13 px semibold, " (optional)" muted when not required, none over a Checkbox), the hint, the element and the error revealed under it in the theme's danger color, as the checkout had them;ui.form_summarya panel from the first failed submit while errors or a failure remain, made again (switch) as they change: "There is a problem", the failure, a plain button a field focusing it; to screen readers a group named by its title (SummaryPanel). - Rules (
Rules::lengthin grapheme clusters through pkg::alloy::text's newgrapheme_count, the text's ends' spaces aside;email, WHATWG's grammar with a dot in the domain;shape;between<T: Number>;.said) and parsers (Parse::integerin ASCII or another script's digits with no tables,number,dateandtimethrough std::locale's newparse_number,parse_dateandparse_timein the Ui's locale). Messages are English (english_*), unlessui.set_form_messagesgave others; they take the Ui (question 11), reading its locale only for an example or a number. - Widgets:
TextField.textdefaults to empty and gainsdescriptionandrequired; Select, ChoiceList, Radios, Checkbox, DatePicker and TimePicker gainerrorandrequired: a field's border in the danger color at 1.5 pixels (2 with the focus ring), a checkbox's box and the radios' circles in it, andinvalid,requiredand the message as the description to screen readers. Window'sSemantics.required: UI Automation'sIsRequiredForFormandrequired=trueinAriaProperties, AT-SPI'sREQUIREDwith itsStateChanged,aria-required, NSAccessibility'sisAccessibilityRequired. - Size: the counter is 1,907,392 bytes natively (1,907,088 before
F13, +304) and 1,357,334 of wasm (1,357,062, +272), built
as
bench.shbuilds it:requiredin each tree and the semantics' glue, the hook's field and call in the text field (not in the counter), the Ui'sformssignal handle. A first measure had the forms' state behind an object (+352 bytes of glue) and the focus hook infocus_node(+384): the state is now a signal of the root's and the hook the text field's. - Tests: fifteen in
ui/tests.alloy(when errors show, Tab order and the announcement, Enter submitting, a hidden field, a rule reading another field, refusals, picked fields required, the trees, messages replaced,validin a binding, the rules' table, a replay's announcement, the parsers in French and American English,between, a parsed field); goldensform_errors,form_errors_dark,form_summaryandpickers_error;tests/access(aria-required),tests/atspi(REQUIRED),tests/automation(IsRequiredForForm, by hand on Windows). Benchmarkui_form: a keystroke in the first of 50 labelled fields after a submit, the last field's rule reading it, 0.008 ms (budget 0.1): its bindings and layout touch only the two fields. - Samples:
form,todo,dialogs,screens,choices,preferences,booking,clockandshowtimesvalidate, each saying what in its opening comment; newsignup.alloy. The tickets' checkout is a form (F13c): its fields' rules (the card's check digit, the expiry parsed into a month and a year not past) are functions the tickets' tests call, a declined card isfield.refuseon the card number, andform.alive(new) tells a payment's answer whether the screen is still there; goldenscheckoutanddeclinedmade again. No sample disables its submit button (4A).Field.formis exported, for a button submitting a field's form.
replayopen_filessave_filesave_bytesDropAreaLoadingFailureformatStageLoadOptionsResourcePendingScriptedResponseScriptedResponse::answeredScriptedResponse::failedloadstatestagelatestreloadsendsendcancel_requestprogressstorepersistedCalendarDatePickerTimePickertodayset_todaylocaleset_localeRuleParserFieldOptionsVerdictWantedFormFieldFormErrorRulesParseFormMessagesformtextparsedpickedon_submitsubmitvalidaliveerrorsrefusefailureresetverdictvaluetry_valueerrortexteditpickrefusetext_fieldinputlabelledform_summaryset_form_messagesRules::lengthRules::emailRules::shapesaidRules::betweenParse::integerParse::numberParse::dateParse::timeNavigatorPathsnavigatornavigator_withpushbackon_leavingpopreplaceresetcurrentdepthscreensAnimatedanimatedgetsetjumptarget
fn replaysource
exp fn replay(
config: &WindowConfig,
options: ReplayConfig,
responses: Vector<ScriptedResponse>,
view: |=| (&var Ui) -> Element,
events: &[Event]
) -> Replayed
Replays the app as replay does, every request answered from the
responses, none by the network.
fn open_filessource
exp fn open_files(self ui: &var Ui, dialog: FileDialog, then: |=| (&var Ui, Vector<ChosenFile>))
Shows a dialog choosing files to open, then calls then with them,
unless it was cancelled. On the web each file comes with its bytes.
fn save_filesource
exp fn save_file(self ui: &var Ui, dialog: FileDialog, then: |=| (&var Ui, ChosenFile))
Shows a dialog choosing where to save, then calls then with the
file, unless it was cancelled; save_bytes writes it.
fn save_bytessource
exp fn save_bytes(self ui: &var Ui, file: &ChosenFile, bytes: &[u8]) -> bool
Writes the bytes into a file save_file gave (Window::save_bytes);
whether it was written, or given to the page to write.
type DropAreasource
exp type DropArea : Widget = struct
Its children laid out as a stack's, taking files or text dropped on it,
which on_drop is given at their point in its coordinates; while
something dragged over the window would drop on it, it shows so.
Fields
exp children: &[Element] = &[]exp on_drop: |=| (&var Ui, &Drop)exp padding: Padding = Padding {}exp align: Alignment = Alignment::Startexp background: Ink = Ink::Noneexp border: Ink = Ink::Noneexp radius: f32 = 0.0exp sizing: Sizing = Sizing {}
type Loadingsource
exp type Loading<T> = enum
What a resource load keeps holds now.
Variants
Waiting: Progressthe exchange under way, or none asked for
Done: TFailed: Failure
type Failuresource
exp type Failure : Format = enum
Why a resource or a request failed.
Variants
Network: HttpErrornothing usable came back
Status: Responsethe server answered, not with 2xx
Unreadable: Stringthe answer came, but
readrefused it: why
Functions
fn formatsource
exp fn format(self failure: &Failure, out: &var String)
The reason, as a sentence goes on after "failed: ".
type Stagesource
exp type Stage = enum
A Loading's variant alone: a key for switch.
Variants
WaitingDoneFailed
type LoadOptionssource
exp type LoadOptions = struct
Fields
exp delay: Duration = Duration::from_nanoseconds(0)wait this long after the request last changed: a search asked for as one stops typing
exp keep: bool = truekeep the last Done value readable while the next loads
exp owner: Option<Owner> = ::Nonewhat the resource belongs to, going with it: None, what is made now
type Resourcesource
exp type Resource<T> = struct
Data a request gives, read into the program's type, in a signal
(load).
Functions
type Pendingsource
exp type Pending = struct
A request send sent, until what came back is handled.
type ScriptedResponsesource
exp type ScriptedResponse = struct
A response replay gives a request for the URL, at the script's time;
each answers one request, those for one URL in order. Until then the
exchange's progress goes evenly from nothing to the body's length.
Fields
exp url: Stringexp at: Durationexp answer: std_result::Result<Response, HttpError>
Functions
fn ScriptedResponse::answeredsource
exp fn ScriptedResponse::answered(
url: &[u8],
at: Duration,
status: u16,
body: &[u8]
) -> ScriptedResponse
A response of the status and the body, at the time.
fn ScriptedResponse::failedsource
exp fn ScriptedResponse::failed(url: &[u8], at: Duration, error: HttpError) -> ScriptedResponse
The request failing at the time.
fn loadsource
exp fn load<T>(
self ui: &var Ui,
request: |=| (&Ui) -> Option<Request>,
read: |=| (&Response) -> std_result::Result<T, String>,
options: LoadOptions
) -> Resource<T>
The data the request gives, read by read, kept in a signal. The
request function is a binding, run again when a signal it read
changes, which cancels the exchange under way and starts the new one
(after delay; the first starts at once); None leaves the resource
waiting for nothing. Natively read runs with the exchange, off the UI
thread. The exchange is cancelled when the owner goes.
const shows = ui.load(
(ui) => ::Some(Request::get(&f"{API}/shows?q={encoded(&search.get(&ui).view())}".view())),
(response) => read_shows(&response),
LoadOptions { .delay = Duration::from_milliseconds(300) },
);
ui.switch((ui) => shows.stage(&ui), (ui, stage) => match (stage) { ... }, Keep::None);
fn statesource
exp fn state<T>(self r: &Resource<T>, ui: &Ui) -> &Loading<T>
What the resource holds now; read in a binding, which runs again when it changes.
fn stagesource
exp fn stage<T>(self r: &Resource<T>, ui: &Ui) -> Stage
Whether it waits, is done or failed: a key for switch, which changes
only between those.
fn latestsource
exp fn latest<T>(self r: &Resource<T>, ui: &Ui) -> Option<&T>
The last Done value, kept while the next loads unless keep is false.
fn reloadsource
exp fn reload<T>(self r: &Resource<T>, ui: &var Ui)
Asks for the request again now, the exchange under way cancelled: "Try again", or pulling to refresh. A failure then is announced.
fn sendsource
exp fn send(
self ui: &var Ui,
request: Request,
then: |=| (&var Ui, std_result::Result<Response, HttpError>)
) -> Pending
Sends the request; then runs as a handler with what came back. The
exchange belongs to the owner of the element whose handler sent it and
is cancelled when the owner goes (then then never runs). A failure,
the request's or the server's, is announced.
fn sendsource
exp fn send(
self ui: &var Ui,
request: Request,
then: |=| (&var Ui, std_result::Result<Response, HttpError>),
options: HandlerOptions
) -> Pending
send with the options: a request belonging to their owner, as a
payment whose answer counts after its screen went.
fn cancel_requestsource
exp fn cancel_request(self ui: &var Ui, pending: Pending)
Cancels the request: then never runs. Nothing once it finished.
fn progresssource
exp fn progress(self ui: &Ui, pending: Pending) -> Option<Progress>
How far the request has gone; None once it finished. Read in a binding, which runs again as more arrives, at most every 100 ms.
fn storesource
exp fn store(self ui: &var Ui) -> &var KeptStore
The app's store, named "app" under the app's name (WindowConfig.app,
else its title), opened the first time it is asked for (std::storage).
What a handler sets in it is written back once the event is handled,
at most once a second, natively on a worker, and as the app ends; on
the web each set reaches the page's localStorage at once. A Ui made on
its own keeps it in memory.
fn persistedsource
exp fn persisted<T>(
self ui: &var Ui,
key: &[u8],
initial: T,
write: |=| (&T) -> Json,
read: |=| (&Json) -> Option<T>
) -> Signal<T>
A signal holding what the app's store keeps under the key, read by
read as the signal is made, and written back by write each time it
changes. initial is its value when nothing is saved under the key or
read refuses what is.
const dark = ui.persisted(&"dark", false, (on) => Json::bool(on), (j) => j.as_bool());
type Calendarsource
exp type Calendar : Widget = struct
A month as a grid of its days in weeks from first_weekday (the Ui's
locale's unless set), the month and year above it in the locale's names
between buttons going to the months before and after.
One Tab stop: Left and Right move a day, Up and Down a week, Page Up
and Page Down a month (with Shift a year), Home and End to the week's
ends, the month following the focused day; Enter, Space or a click
choose. The chosen day is filled in the primary color, today has a
ring, days outside earliest and latest are muted and those
available refuses struck through, neither chosen. To a screen
reader a grid of days described by its month, announced as it changes.
Fields
exp date: Option<Date> = ::Nonethe chosen day
exp earliest: Option<Date> = ::Noneexp latest: Option<Date> = ::Noneexp available: |=| (&Date) -> bool = (d) => trueexp first_weekday: Option<Weekday> = ::Nonethe locale's
exp accessible: String = String::empty()exp on_change: |=| (&var Ui, Date) = (ui, d) {}exp enabled: bool = trueexp sizing: Sizing = Sizing {}
type DatePickersource
exp type DatePicker : Widget + Popup = struct
A field showing the chosen day as format writes it (the Ui's
locale's medium date by default, "15 Oct 2026" in en-GB) or the
placeholder, and a chevron, opening a Calendar of the same options in a
popup below it by a click, Space, Enter or Down; choosing a day or
Escape closes it. To a screen reader a button whose value is the day
shown, expanded while the calendar is open.
Fields
exp date: Option<Date> = ::Noneexp earliest: Option<Date> = ::Noneexp latest: Option<Date> = ::Noneexp available: |=| (&Date) -> bool = (d) => trueexp first_weekday: Option<Weekday> = ::Nonethe locale's
exp placeholder: String = String::empty()exp accessible: String = String::empty()exp format: Option<|=| (&Date) -> String> = ::Nonethe locale's
exp on_change: |=| (&var Ui, Date) = (ui, d) {}exp clearable: bool = falsea "Clear" under its calendar, going back to no day (
on_clear)exp on_clear: |=| (&var Ui) = (ui) {}exp enabled: bool = trueexp error: String = String::empty()as a Select's
exp required: bool = falseexp sizing: Sizing = Sizing {}
type TimePickersource
exp type TimePicker : Widget + Popup = struct
A Select of the times from earliest to latest by step_minutes,
written on the Ui's locale's clock (14:30, 2:30 PM), with its keys
and type-ahead: typing "14" goes to 14:00. To a screen reader a combo
box.
Fields
exp time: Option<TimeOfDay> = ::Noneexp earliest: TimeOfDay = TimeOfDay { .hour = 0, .minute = 0 }exp latest: TimeOfDay = TimeOfDay { .hour = 23, .minute = 59 }exp step_minutes: u32 = 30exp placeholder: String = String::empty()exp accessible: String = String::empty()exp on_change: |=| (&var Ui, TimeOfDay) = (ui, t) {}exp enabled: bool = trueexp error: String = String::empty()as a Select's
exp required: bool = falseexp sizing: Sizing = Sizing {}
fn todaysource
exp fn today(self ui: &Ui) -> Date
The day calendars take as today: the system's, unless set.
fn set_todaysource
exp fn set_today(self ui: &var Ui, day: Option<Date>)
Sets the day calendars take as today, for tests and goldens; None gives the system's again.
fn localesource
exp fn locale(self ui: &Ui) -> Locale
The locale calendars, pickers and the app's own dates follow: the one set, else the system's (question 14A). A binding reading it runs again when it changes (question 27B).
fn set_localesource
exp fn set_locale(self ui: &var Ui, locale: Option<Locale>)
Sets the app's locale, None giving the system's again; everything is laid out again in it, and the bindings that read it run again.
type Rulesource
exp type Rule<T> = |=| (&Ui, &T) -> Option<String>;
A check a field states: what is wrong with its value, or None. It may read the Ui (its locale, today) and other fields, and a binding showing the field's error follows what it reads.
Functions
type Parsersource
exp type Parser<T> = |=| (&Ui, &[u8]) -> std_result::Result<T, String>;
Reads a typed field's text into its value, or says what is wrong.
type FieldOptionssource
exp type FieldOptions<T> = struct
What a field is.
Fields
exp label: Stringthe label
labelledshows, the summary's line, the trees'exp hint: String = String::empty()shown under the label, and said after the error
exp required: bool = falsemust hold something: checked before the rules, and said to screen readers; an empty field not required is valid, gives no value and runs no rules
exp rules: &[Rule<T>] = &[]checked in order once it holds something, the first message found being its error
type Verdictsource
exp type Verdict<T> = enum
What a field holds now.
Variants
Emptynothing typed but spaces, or nothing picked
Valid: TInvalid: String
type Wantedsource
exp type Wanted = enum
What a required field asks for while empty, which its message says.
Variants
Textsomething typed
Pickone of its choices
Checka box checked
type Formsource
exp type Form = struct
A form: its fields, whether a submit was tried, a failure of the whole. A copyable handle, valid until its owner goes, as signals are.
Functions
exp fn text( self form: &Form, ui: &var Ui, text: String, options: FieldOptions<String> ) -> Field<String>exp fn parsed<T>( self form: &Form, ui: &var Ui, text: String, parse: Parser<T>, options: FieldOptions<T> ) -> Field<T>exp fn picked<T>( self form: &Form, ui: &var Ui, value: Option<T>, options: FieldOptions<T> ) -> Field<T>exp fn on_submit(self form: &Form, ui: &var Ui, then: |=| (&var Ui))exp fn submit(self form: &Form, ui: &var Ui)exp fn valid(self form: &Form, ui: &Ui) -> boolexp fn alive(self form: &Form, ui: &Ui) -> boolexp fn errors(self form: &Form, ui: &Ui) -> Vector<FormError>exp fn refuse(self form: &Form, ui: &var Ui, message: String)exp fn failure(self form: &Form, ui: &Ui) -> &Stringexp fn reset(self form: &Form, ui: &var Ui)
type Fieldsource
exp type Field<T> = struct
A field of a form, giving a T: a copyable handle, valid until the owner that made it goes.
Fields
exp form: Form
Functions
exp fn verdict<T>(self field: &Field<T>, ui: &Ui) -> Verdict<T>exp fn value<T>(self field: &Field<T>, ui: &Ui) -> Texp fn try_value<T>(self field: &Field<T>, ui: &Ui) -> Option<T>exp fn error<T>( self field: &Field<T>, ui: &Ui ) -> Stringexp fn text<T>(self field: &Field<T>, ui: &Ui) -> &Stringexp fn edit<T>(self field: &Field<T>, ui: &var Ui, text: String)exp fn pick<T>(self field: &Field<T>, ui: &var Ui, value: Option<T>)exp fn refuse<T>(self field: &Field<T>, ui: &var Ui, message: String)
type FormErrorsource
exp type FormError = struct
A field in error, as errors gives them.
Fields
exp label: Stringexp message: Stringexp element: Elementshowing the field
type Rulessource
exp type Rules = struct
The built-in rules, each with an English message in the Ui's locale
that said replaces.
Functions
type Parsesource
exp type Parse = struct
The built-in parsers, reading what the Ui's locale writes and ISO 8601.
Functions
type FormMessagessource
exp type FormMessages = struct
What forms say, each a function of the Ui (its locale) and what the message needs; the defaults are the English ones.
Fields
exp required: |=| (&Ui, Wanted) -> String = english_requiredexp length: |=| (&Ui, u64, u64, u64) -> String = english_lengthleast, most, now
exp email: |=| (&Ui) -> String = english_emailexp shape: |=| (&Ui, &[u8]) -> String = english_shapethe example
exp integer: |=| (&Ui) -> String = english_integerexp number: |=| (&Ui) -> String = english_numberexp between: |=| (&Ui, f64, f64) -> String = english_betweenexp date: |=| (&Ui, &Date) -> String = english_datean example day
exp time: |=| (&Ui, &TimeOfDay) -> String = english_timeexp optional: |=| (&Ui) -> String = english_optional"(optional)"
exp summary: |=| (&Ui, u64) -> String = english_summary"There is a problem" for 0, else "2 fields need attention"
fn formsource
exp fn form(self ui: &var Ui) -> Form
A new form, belonging to what is being made as a signal does.
fn textsource
exp fn text(
self form: &Form,
ui: &var Ui,
text: String,
options: FieldOptions<String>
) -> Field<String>
A field of text kept as typed.
fn parsedsource
exp fn parsed<T>(
self form: &Form,
ui: &var Ui,
text: String,
parse: Parser<T>,
options: FieldOptions<T>
) -> Field<T>
A field of text read into a T by parse, whose message is the field's
error when it fails.
fn pickedsource
exp fn picked<T>(
self form: &Form,
ui: &var Ui,
value: Option<T>,
options: FieldOptions<T>
) -> Field<T>
A field of a value picked rather than typed: a Select's, a
DatePicker's, a Checkbox's (a required Field<bool> must be true).
fn on_submitsource
exp fn on_submit(self form: &Form, ui: &var Ui, then: |=| (&var Ui))
What a submit that passes runs, as a handler; set once the fields it reads are made.
fn submitsource
exp fn submit(self form: &Form, ui: &var Ui)
Checks every field shown (an element text_field or input made for
it exists, in no hidden view). With some wrong, their errors show, the
first in Tab order takes the focus, and screen readers are told at once
("2 fields need attention: Card number, Expiry."); else on_submit's
function runs.
fn validsource
exp fn valid(self form: &Form, ui: &Ui) -> bool
Whether every field shown is valid; read in a binding, it follows them.
fn alivesource
exp fn alive(self form: &Form, ui: &Ui) -> bool
The fields shown in error, in Tab order, whether their errors show yet or not. Whether the form is still there: false once its owner went, as when a server answers after its screen closed.
fn errorssource
exp fn errors(self form: &Form, ui: &Ui) -> Vector<FormError>
fn refusesource
exp fn refuse(self form: &Form, ui: &var Ui, message: String)
The whole form refused, as by a server: the message is failure until
the next submit, and screen readers say it at once.
fn failuresource
exp fn failure(self form: &Form, ui: &Ui) -> &String
What refuse said, empty when nothing was refused since the last
submit; read in a binding.
fn resetsource
exp fn reset(self form: &Form, ui: &var Ui)
Nothing tried, left or refused any more, the texts and values kept: after a submit that passed on a form that stays, its texts cleared.
fn verdictsource
exp fn verdict<T>(self field: &Field<T>, ui: &Ui) -> Verdict<T>
What the field holds now, its error shown or not; read in a binding, it follows the field and what its rules read.
fn valuesource
exp fn value<T>(self field: &Field<T>, ui: &Ui) -> T
The field's value: after a submit that passed. Faults unless valid.
fn try_valuesource
exp fn try_value<T>(self field: &Field<T>, ui: &Ui) -> Option<T>
The field's value while valid.
fn errorsource
exp fn error<T>(
self field: &Field<T>,
ui: &Ui
) -> String
The message to show now: empty while valid, and until the field was left changed, the form submitted or a server refused it.
fn textsource
exp fn text<T>(self field: &Field<T>, ui: &Ui) -> &String
What is typed in the field.
fn editsource
exp fn edit<T>(self field: &Field<T>, ui: &var Ui, text: String)
Puts the text in the field: a text field's on_change. A server's
refusal goes with it.
fn picksource
exp fn pick<T>(self field: &Field<T>, ui: &var Ui, value: Option<T>)
Picks the value, or none: a Select's or a DatePicker's on_change.
The error shows from then on.
fn refusesource
exp fn refuse<T>(self field: &Field<T>, ui: &var Ui, message: String)
The server's verdict on what the field was sent with: shown at once, said to screen readers at once, the field focused when it is the first in error; its next change takes it away.
fn text_fieldsource
exp fn text_field<T>(self ui: &var Ui, field: Field<T>, look: TextField) -> Element
A TextField showing the field: its text, its error once shown,
required, the label for screen readers unless look gives one, the
hint said after the error, on_change editing the field and, on one
line, Enter submitting the form; look gives the rest. A binding,
recorded as the field's element.
fn inputsource
exp fn input<T, W: Widget>(self ui: &var Ui, field: Field<T>, options: |=| (&Ui) -> W) -> Element
Another widget showing the field, its options bound as bind binds
them and the wiring the program's own (selected, error, required,
on_change picking); its element recorded as the field's.
fn labelledsource
exp fn labelled<T>(self ui: &var Ui, field: Field<T>, input: Element) -> Element
The field's label above its element, "(optional)" after it when not required, its hint under the label and its error under the element in the theme's danger color, coming and going as it changes. A Checkbox keeps its own label: only the hint and the error are added.
fn form_summarysource
exp fn form_summary(self ui: &var Ui, form: Form) -> Element
An element showing nothing until a submit fails: then a panel, "There is a problem", the form's failure and a line for each field in error, a plain button focusing it, following the errors until none is left.
fn set_form_messagessource
exp fn set_form_messages(self ui: &var Ui, messages: FormMessages)
What forms say from now on, in the program's own words.
fn Rules::lengthsource
exp fn Rules::length(least: u64, most: u64) -> Rule<String>
The text, its spaces at either end aside, from least to most
characters long, counted as a person counts them (grapheme clusters):
"Use at least 10 characters (now 7)."
fn Rules::emailsource
exp fn Rules::email() -> Rule<String>
A valid email address (WHATWG's, as browsers check one) whose domain has a dot: "Enter an email address, like [email protected]."
fn Rules::shapesource
exp fn Rules::shape(shape: &[u8], like: &[u8]) -> Rule<String>
The text written in the shape, 9 standing for a digit, A for a letter
and * for either, anything else for itself, like an example for the
message: Rules::shape(&"99/99", &"12/29"), "Write it like 12/29."
fn saidsource
exp fn said<T>(self rule: &Rule<T>, message: &[u8]) -> Rule<T>
The rule, its message replaced: `Rules::length(1, 40).said(&"Keep the name to 40 characters.")`.
fn Rules::betweensource
exp fn Rules::between<T: Number>(
least: T,
most: T
) -> Rule<T>
The number from least to most: "Enter a number from 1 to 10."
fn Parse::integersource
exp fn Parse::integer() -> Parser<i64>
A whole number, in ASCII digits or another script's, its sign before it: "Enter a whole number."
fn Parse::numbersource
exp fn Parse::number() -> Parser<f64>
A number as the Ui's locale writes it, its groups or none (1 234,5 in
French, 1,234.5 in English): "Enter a number, like 2.5."
fn Parse::datesource
exp fn Parse::date() -> Parser<Date>
A day in the Ui's locale's short date (21/11/2026 in British English)
or ISO 8601: "Enter a date, like 21/11/2026." with today.
fn Parse::timesource
exp fn Parse::time() -> Parser<TimeOfDay>
A time of day on either clock, 14:30 or 2:30 pm: "Enter a time,
like 14:30." on the locale's own.
type Pathssource
exp type Paths<R> = struct
How a navigator's routes show in the page's address, and are read
from it: on the web the address follows the top screen
(index.html#/events/42), and a page opened or reloaded at an address
starts at that screen; elsewhere they are not used.
Fields
exp path: |=| (&R) -> Stringexp parse: |=| (&[u8]) -> Option<R>
fn pushsource
exp fn push<R>(self nav: &Navigator<R>, ui: &var Ui, route: R)
Shows the route's screen over the current one, which is kept hidden.
fn backsource
exp fn back<R>(self nav: &Navigator<R>, ui: &var Ui) -> bool
Frees the top screen, showing the one under it as it was left, once
on_leaving agrees; false at the first screen, which stays, or when it
does not. The header's Back, the mouse's, Alt+Left and the browser's
all come here.
fn on_leavingsource
exp fn on_leaving<R>(self nav: &Navigator<R>, ui: &var Ui, asks: |=| (&var Ui, R) -> bool)
Asks the function before going back from the top screen, with its
route: true lets it go; false keeps it, as for a form or a cart left
half done, the function asking the person (a dialog whose "Leave" then
calls pop).
fn popsource
exp fn pop<R>(self nav: &Navigator<R>, ui: &var Ui) -> bool
Frees the top screen as back does, without asking on_leaving.
fn replacesource
exp fn replace<R>(self nav: &Navigator<R>, ui: &var Ui, route: R)
Shows the route's screen in place of the top one, which is freed.
fn resetsource
exp fn reset<R>(self nav: &Navigator<R>, ui: &var Ui, route: R)
Shows the route's screen alone, freeing every other.
fn currentsource
exp fn current<R>(self nav: &Navigator<R>, ui: &Ui) -> &R
The top screen's route; in a binding, recorded so the binding runs again when it changes.
fn depthsource
exp fn depth<R>(self nav: &Navigator<R>, ui: &Ui) -> u64
How many screens there are, 1 at the first; in a binding, recorded.
fn screenssource
exp fn screens<R>(
self ui: &var Ui,
nav: Navigator<R>,
screen: |=| (&var Ui, &R) -> Element
) -> Element
An element showing the navigator's top screen, made by screen from
its route when pushed and freed when taken off, on the theme's
background; the screens under it are kept hidden, as switch keeps
views. A screen shown gives the focus to its first element taking it,
or, shown again, to the one that had it. Back comes from back, the mouse's Back button, Alt+Left
(Command+[ on macOS) and on the web the browser's Back and Forward,
to the deepest navigator on screen that can go back.
type Animatedsource
exp type Animated = struct
A number moving to its target over its motion, read in bindings as a signal is: a binding reading it runs again each frame while it moves. A copyable handle, valid until its owner goes.
Functions
fn animatedsource
exp fn animated(self ui: &var Ui, value: f32, motion: Motion) -> Animated
A number at the value, moving over the motion when given a target, belonging to what is being made as a signal does.
fn getsource
exp fn get(self a: &Animated, ui: &Ui) -> f32
Where the number is this frame; in a binding, recorded so the binding runs again as it moves.
fn setsource
exp fn set(self a: &Animated, ui: &var Ui, target: f32)
Moves the number to the target from where it is, its speed kept;
under reduced motion, unless essential, it jumps there. (The design's
to is a keyword: decisions/F11.md, question 21.)
fn jumpsource
exp fn jump(self a: &Animated, ui: &var Ui, value: f32)
Puts the number at the value at once.
fn targetsource
exp fn target(self a: &Animated, ui: &Ui) -> f32
Where the number is going, or is.