module pkg::alloy::uisource
A retained, fine-grained reactive UI over pkg::alloy::draw (PLAN.md, stage F5): values the UI shows live in signals, elements are made once from option structs, and a binding remakes an element's options when a signal it read changes, so only that element is laid out or painted again.
fn counter(ui: &var Ui) -> Element {
const count = ui.signal(0);
return ui.add(Column {
.gap = 8.0,
.padding = Padding::all(16.0),
.children = &[
ui.bind((ui) => Text::from(f"Clicked {count.get(&ui)} times")),
ui.add(Button::text(&"Add one", (ui) => count.update(&var ui, (n) => n += 1))),
],
});
}
fn main() -> i32 {
return app(&WindowConfig::titled(&"Counter"), counter);
}
Coordinates are logical pixels from an element's top left, y down.
## How it was built
Notes kept from each stage as it was finished, the sizes and numbers of their day; what changed since is in REVIEW.md and the history.
**F5a as built** (2026-10-13):
ui, the packagepkg::alloy::ui:ui.alloythe API (Ui,Signal<T>,Element,Widgetand its defaults,Arrange,Look,Input, the option types,app, andreplay, which runs an app headless on the CPU device over events for tests),store.alloy(signals, effects, owners,showandeach),tree.alloy,layout.alloy(withColumn,Row,Stack),painting.alloy,events.alloy,widgets.alloy(Text,Button),running.alloy.- A signal's value sits behind an object downcast per instantiation; a
read inside a binding goes into a
Mutex-held list, sincegethas only&Ui, and subscribes the binding stamped with its run, so a rerun forgets what it no longer reads without unsubscribing. Effects run owners nearer the root first;showandeachkeep their own state in signals nothing reads. eachtooku64keys at first,std::hash::Keyandwindow'sKeyclashing in the module importing both; since 2026-10-13 it takes anyK: hash::Key, std's module importedas hash(section 6.4's aliases, which reach its names only qualified). A row reads its item through its own signal and changes it through the list's.- An element's children are
&[Element]in its options, adopted byadd;showandeachmake transparent elements laid out as part of their parent. Canvas nodes are added under the parent's as the tree is painted, so a row moved byeachkeeps its place in drawing order (only overlapping rows would show it). window's mouse button enum is nowPointerButton,Buttonbeing the widget;drawgainedcanvas.contains(node).- Tests:
ui/tests.alloy(signals and reruns, layout as numbers,showandeachwith what they free, clicks),tests/widgets.alloygoldens intests/golden/uithroughreplay. Samplescounter.alloy,toggles.alloy. The counter idles at no CPU under weston.
**F5b as built** (2026-10-13):
- Focus: Tab and Shift+Tab move it in tree order among the elements
taking it, a press gives it without the ring, the keyboard with it;
InputgainsKey,Text,PreeditandFocus, which go to the focused element and bubble;ui.focus,ui.has_focus, andui.refresh(change), by which a widget handling input says its own state changed. Widgetgainsfocusable,cursor,caret(the input method's area) andclips: a clipping element paints into a canvas node under one clipped to its bounds, its children beside it.TextField(fields.alloy, fromsamples/editor.alloy: one line scrolling to the caret, or several wrapping; placeholder,on_change,on_submit),Checkbox(its check mark a coverage mask made with the canvas, inLook.marks),Slider;Theme::dark().windowgainsCursorandset_cursor(Wayland's cursor-shape with the pointer's entering serial, Win32'sWM_SETCURSOR, the page's CSS); the app shows the hovered element's cursor and gives the focused field's caret to the input method.- Not built: the waker and background work, question 4 (built after F5c, "Background work as built").
- Tests: keyboard, fields, compositions, checkboxes and sliders in
ui/tests.alloy; goldensinputs,inputs_dark,editing. Samplestodo.alloy,form.alloy.
**F5c as built** (2026-10-13):
Scroll(scrolling.alloy): its one child moved under a clip by the wheel (a notch 40 logical pixels, a touchpad's pixels as given) or by dragging its bar; at its ends the wheel goes on to the scrolls around it; the keyboard's focus scrolls the scrolls holding the focused element to show it.Widgetgainsoverlay, what a clipping element draws over its children (the bar), in a canvas node after theirs.ui.list(count, row, options):counta binding, rows made byrowfrom their index for the view and a screen's worth either side, each in an owner freed once out of that range; rows measured as made, the rest standing at the average measured (orestimate;fixedrows are not measured); the view keeps its place as a row and an offset within it. The list asks for rows from its layout through a signal, soupdate_allruns bindings and layout again, up to four times, until nothing is marked.Wrap,Grid(Track::Fixed,Content,Fraction; its columns aVector<Track>: options a binding renews may hold no references to temporaries, which children's&[Element]escape only becauseaddreads them at once), andImage(ui.image(width, height, pixels)keeps RGBA pixels, made a picture on the canvas when it is there;Fit::Contain,Cover,Fill).Input::Scrollto the element under the pointer, bubbling;ui.scroll_atdrives it in tests and benchmarks.tests/support/png'sImageisBitmap,Imagebeing the widget.- Tests: wraps, grids, scrolls, revealing the focused element, the list
in
ui/tests.alloy; goldensgrid_wrap,images,list,scrolled. Samplesgallery.alloy,rows.alloy(10,000 rows). - Benchmarks (
bench/ui.alloy, on the CPU; budgets set from these): 1,000 bound texts made and laid out in 4.5 ms; one change among 10,000 bound texts 0.2 ms; the 10,000-row list scrolled a row 0.03 ms. The counter is 1.39 MB native and 1.08 MB on the web, the bundled font most of it. Frames are the canvas's benchmarks'; scrolling a row a frame on a GPU waits for the person running the samples. - Memory (2026-10-13, after F5c): an element's bytes measured from the
resident set's growth over 10,000 texts, each Ui first showing one so
its fonts and device are not counted, and now also with the canvas's
part, drawn offscreen on the CPU device (
ui.draw_offscreen). From 6,390 bytes a drawn text (1,480 not drawn, 2,000 bound) to 1,440 (1,030, 1,120), the frames as fast and every golden image the same: - the canvas no longer keeps each node's instances encoded (48 floats a glyph) from frame to frame, only its bounds, a text's its layout's box with half its size around; a frame encodes the nodes meeting its damaged rectangles as it gathers them, and a node's world transform and clip are worked out on the way down instead of kept; - aTextmakes its paint when laid out and drops its layout at once, and painting takes that paint (Widget::take_paint), so no text keeps a layout; - kept vectors give back their room (Vector::shrink, std; layouts and paints), and std's vectors grow by half rather than doubling, which keeps the copies a growth fills within half the elements (the compiler builds itself as fast); -drawgainedPaint::shrink. An element is still past the plan's "well under 1 KB" drawn: the two node structs (the Ui's 144 bytes, the canvas's about 210) and a glyph's 36 bytes in the canvas are most of it. - Images freed (2026-10-13):
ui.set_image(id, width, height, pixels)shows other pixels in every element showing the image andui.free_image(id)gives it back, anImageIdcarrying a generation so an id freed names nothing;draw'scanvas.release_picturegives back a large picture's texture or its area of an atlas page, the next picture fitting taking it and a page holding none starting again. Sample:gallery.alloy's "Move the disc".
**Background work as built** (2026-10-13, question 4):
window:Event::Wokenandwindow.waker(), aWakercopied to other tasks whosewake()gives the loop aWoken(wakes close together may come as one): on Wayland aneventfdpolled beside the compositor's socket, on Windows aWM_APP + 1posted to the window, on the web and headless nothing.ui.background(work): inapp, natively, four worker tasks in ascopearound the window's loop take the work through astd::sync::Channel, send what each gives back through another and wake the loop, whoseWokenmoves those into the Ui to run before the next update; closing the window closes the work's channel, andappreturns once the workers end the work they are doing. On the web, inreplayand in a Ui made on its own the work runs at once and what it gives at the next update.ui.quit()closes the app's window.- std:
Channel::try_receive; and the runtime's futex wake took a count of every waiter as -1, soChannel::closewoke one receiver waiting on Linux (tests/run/sync.alloynow waits on four). - The work owns what it captures: decided as capture bounds on function
types (spec section 5.4),
backgroundtaking|=| () -> |=| (&var Ui). Every callback the Ui keeps (options'on_pressandon_change,bind,show,each,list,app's view,window::run's handler) is|=|, so none outlives what it would borrow;Signal::update's change, called at once, is|&|. - Tests:
ui/tests.alloy(work with no workers),tests/background(eight pieces of work on the workers, under weston and in node's page). Samplebackground.alloy(counting primes below 100 million, a billion and ten billion, 0.2 s, 1.8 s and about 20 s here, with a button and a field to use meanwhile).
**Fonts arriving** (2026-10-14; decisions/F10.md, question
6A): on Event::FontsArrived (the web, a fetched font arrived) app
lays out and paints every element again (invalidate_all), so text
shown in boxes until then takes the font unasked; tested in
ui/tests.alloy.
**F11a as built** (2026-10-15; decisions/F11.md, "Layers"):
- Time (question 7A,
timers.alloy):ui.now()is the window's clock, set from each event's time (Redrawcarries it); `ui.after(delay, then)gives aTimer` (an index and a generation, so a cancelled or run timer names nothing) whosethenruns as a handler,ui.cancelforgets one. Timers sit in a heap of due times, belong to the owner making them and go with it; after each updateuiaskswindow.wake_atfor the earliest, or for none.replayscripts time byRedraw(at)events. - Layers (
layers.alloy):ui.open(overlay, view) -> Layer,close(nothing if closed),is_open,source()(the element whose handler runs, an anchor; a fault outside handlers). A layer is a host node after the content's root, its own canvas node, holding the scrim (modal, the theme's newscrim, black at 40% light and 60% dark), and a panel (the theme's surface,radius, a border and the theme's newshadow) around the view's element. The host lays the view out within the window less 16 pixels and places it (Place::Center,Below,Above,After4 pixels from the anchor and flipped when there is no room,Ata point,Corner), kept inside the window; an anchored layer moves with its anchor and closes once it is freed or out of view. A layer belongs to the owner of the element whose handler opened it, else the app; its view's elements belong to it. Widgets freed during a handler wait in a graveyard until the event ends, so a handler may close the layer holding its button. - Pointer and keys: hits go through the layers, topmost first, a modal
one ending the search and its scrim taking presses; a press outside
the topmost non-modal layer with
outsidecloses it and goes no further. Opening a layer that takes the keyboard focuses its first element taking focus (a modal one keeping the focus off what is below), closing it gives the focus back. Tab goes round a modal layer's elements and closes menus. Escape goes to the focused element, then closes a tooltip, the focus's layer, else the topmost layer withescape.on_closeruns whichever way it closes. - Size: menus, tooltips and toasts are reached only through
Hooksfunction values a program sets by using them, and the toasts' state is behind an object; the counter grew by 32 KB natively and 28 KB on the web all the same (question 16), from 159 KB before the hooks. - Accessibility: each layer's panel is a node after the content's,
DialogorAlertandmodal, aMenuofMenuItems (expandedon one with a submenu, its shortcut as the description), a toast layer a group; a tooltip's text is its child's description, andAction::Dismisscloses a layer. The roles each platform gives are in pkg::alloy::window's notes. - Tests: eight in
ui/tests.alloy(a dialog's focus, Tab, Escape and scrim; placement and flipping; a layer going with its row; menu keys and submenus; context menus by press, drag and release and by Shift+F10; a tooltip's time, keys and description; toasts' order, pausing and waiting; a dialog in the access tree); goldensdialog.png,dialog_dark.png,menu.png,tooltip.pngandtoasts.pngintests/golden/ui;tests/atspiandtests/automationopen an alert and show a toast. Benchmarkui_dialog: a dialog opened and closed over the 10,000-row list, 0.021 ms; a program opening no layer pays one empty vector's check. - Sample
dialogs.alloy: orders with a "⋯" menu and a context menu, a rename dialog, a delete alert with a toast offering Undo, tooltips, and a popover of filters with the dark theme.
**F11c as built** (2026-10-15; decisions/F11.md, "Screens", questions 5A and 6B):
- Hidden views (
screens.alloy): a node ishiddenwith all under it: layout's flattening, hit tests, Tab's order and the accessibility tree pass over it, a layer anchored in it closes, and painting hides its canvas node (draw's newcanvas.set_hidden, keeping what it drew) and goes no further. The view's owner is hidden too: a binding under it marked meanwhile waits on that owner, still queued, and runs as it shows (set_owner_hidden;flushlooks for a hidden owner only while one is). Hiding a view takes the focus, the hover and the press from it. ui.switch(key, view, keep): a transparent element holding the views made by key (K: hash::Key, which a program's enum satisfies with no marker, question 18), the one shown before kept hidden (Keep::All) or freed (Keep::None).- Size (question 16A): the counter grew by 5.9 KB natively (1,798,704
bytes) and 6.9 KB on the web (1,295,272): the hidden checks in
layout, painting, hit tests, focus and the tree, the owners' in
flush, the navigators' checks and the history after each event, and the window's new roles and history. - Tests: seven in
ui/tests.alloy(switch keeping a view and its waiting binding,Keep::None; tabs by the keys, the pointer and a screen reader; a navigator keeping, freeing (bycensus) and giving the focus back; nested navigators and the history's depth; a start path; an app's Back button and Navigated, throughReplay.history); goldenstabs.pngandtabs_dark.png;tests/atspiandtests/automationselect a tab. An app replayed interpreted took gigabytes to draw text (a page with a field past 7 GB), the interpreter keeping a record of every allocation and frame ever made; it keeps the live ones only since, that page's test peaking at 290 MB, and that test's screens draw their text. - Sample
screens.alloy: forty events, an event's page with tabs (Details, Seats, Reviews and a review to write), the basket; back by the header's button, the mouse, the keys and the browser; on the web the address follows (#/events/12) and a reload stays.
**F11e as built** (2026-10-15; decisions/F11.md, "Motion", questions 11A, 12A and 13A):
- Frames (
motion.alloy): a Redraw runsui.frame(): what moves is marked (elements easing or settling painted again, the bindings reading a moving number queued, rooms revealing laid out), the bindings run and layout and painting follow, then the canvas nodes of what comes and goes are moved; while anything moves the app asks for the next frame after each, and for none once it rests. Motion's state is behind an object and its frame, owner and placing hooks are set only once a program moves something; the counter pays for the hover and press easing,Look's new fields,settlingand the checks. Motion(duration,Easingwith CSS's cubic-bezier solved by Newton's method, delay,Repeatonce, a number of times, forever or back and forth,essential) and the theme'smotiondurations (short 100 ms, medium 200, long 300).ui.transition(element, Transition): the element is held by aMovingelement (its grow copied, clipping only to reveal) whose canvas node visuals (transitions.alloy) move between two poses (opacity, offset, scale about the center, how much of the room shows) after layout and painting, fromcanvas.set_opacity(new indraw, multiplying alpha as each primitive is drawn, question 12A) and transforms. It comes in once the first frame was drawn, from where a visual already moving it has it. As its owner goes,free_ownerfirst lets the transitioned elements among its own keep their canvas nodes (their elements letting go of theirs), which the visual moves back and then removes; the elements go at once, out of the tree and the input. A revealed one leaves a room of its size in its place, in an owner of its own, whicheachkeeps after the row that preceded it andshowamong its children, shrinking with it;eachandshownow free what goes before taking their children. Withmoves, an element placed anew (its node's newmovingflag, checked as painting moves it) goes from where it was drawn, unless a room is opening or closing that frame.- Built in: a dialog's or alert's host fades with its scrim and its
panel grows from 0.96 (medium), a popup, menu or list fades and drops
4 pixels (up when above, short), a tooltip fades, each backwards as
it closes; toasts slide up 16 pixels and close up as one goes, their
corner fading out with the last; a pushed screen slides in from the
window's width over the last, kept shown until covered, and one taken
off slides out over the one under (long), each screen held by a
Groundpainting the theme's background over all it takes, so the one moving covers the other (2026-10-16: a screen painting nothing showed the one under between its elements; goldensscreen_going_back, dark, andscreen_fading, reduced motion's fade);switchcrossfades (medium), a kept view shown until faded out, given no ground: its views fade together, and often sit on a card's surface.Lookgainshoverandpresseasing over the short duration (anEaseper element whose state changed, from its amounts then),since(each node's newchanged, milliseconds on the clock, set as made and by a renew that changes something) andreduced;emphasispaints with the amounts.Widget::settling(since): a widget saying so is painted again next frame. The checkbox's fill and check fade, a radio's dot grows, the slider's thumb goes to a value not dragged to and the tabs' underline slides from the tab before, each for 400 ms at most (SETTLE, settling having no theme to read).Spinner: eight dots, the brightest going round once a second, pulsing every two seconds under reduced motion; a label to screen readers, there being no progress role yet.ui.scroll_to(element)moves the scrolls around it over the medium duration (reveal_offsets, shared with focus'sreveal). - Reduced motion (question 13A):
ui.reduced_motion(), the app'sset_reduced_motion(Option<bool>)else the window's, read at each event. Then slides, scales, reveals and moves are left out, fades kept at the short duration, values and scrolls jump, the spinner pulses. - Accessibility: nothing new; what leaves is out of the tree at once.
- Size (question 16A): the counter is 1,866,320 bytes natively
(1,852,016 before F11e, +14 KB) and its wasm 1,328,924 (1,322,765,
+6 KB), built as
bench.shbuilds it; the native budget, which F11c-d had already passed, raised to 1.9 MB as 16A raised wasm's. Benchmarksui_moving(100 cards coming in, a frame 0.09 ms without drawing) andui_animated(20 bound numbers, 0.02 ms). - Tests: eleven in
ui/tests.alloy(curves, a retargeted number, easing states, transitions coming and going, rooms and moves, reduced motion, layers,switch, the navigator,scroll_toand settling, the app's frames), a frame driven byRedraw(at)as replays do; every replay ends withRedraw(2 s)so goldens show things at rest, and goldensdialog_enteringandscreen_pushingcatch a frame midway. Under the headless weston and lavapipe, presents back to back stall about 2.7 s each, sotests/atspi's toast takes an action to stay while read and its run is given 60 s. - Sample
motion.alloy: six cards dealt one after another (a delay a card) into a wrap, sorted and shuffled by tabs and moving there, removed closing up; a basket total counting; details revealing; a spinner; a smooth scroll to the end; "Reduce motion". The earlier samples move without a change to their code.
**F12a as built** (2026-10-15; decisions/F12.md, "Timers", questions 1A and 2A):
ui.every(period, then)(timers.alloy): a slot with a period, due again a period after it was due and past the runs missed, so a long gap runs it once; cancelling it inside its own run ends it. A period of 0 faults.ui.at(moment, then): a second heap of due moments on the wall clock beside the window clock's, both read at each event (ui.wallset withui.time, before the first view is made too), the entry due longest ago running first (since question 17B the window clock's timers run first, then the wall's). While one waits, the window's deadline is at most 5 seconds ahead (next_due), so after a sleep or the system's time set it runs at most that late.ui.clock(step) -> Signal<i64>: one signal per step, the Ui's own (owner 0), the wall clock at the start of its step. At each event, before the timers run, each clock's signal is set to where the wall clock is, a clock moved having its tick set again; before the window is given its deadline, a clock a shown binding reads (one whose last run read it, not in a hidden view:read_shown) gets a wall timer at its next step, which only wakes the loop, and one no binding reads loses it, so nothing wakes. Both run throughHooksset as the first clock is made.- Replays:
replay(config, ReplayConfig, view, events), the config taking the scale andwall, the wall clock at script time 0 going on with the script's time (the App'swall); window'sReplaycountswakes. - The web: the page shown again (
visibilitychange) gives anEvent::Timerwhether the deadline came or not, so what came due while hidden runs at once. std::time::sleep_until(moment)for programs with no window: sleeps of at most 5 seconds until the wall clock reaches the moment, no new OS call.- Size: the counter is 1,829,792 bytes natively (1,826,512 before
F12a, +3.2 KB) and its wasm 1,305,487 (1,302,508, +2.9 KB), built as
bench.shbuilds it; the clocks' 0.8 KB is behind the hooks, the rest the wall heap, the repeating slots and reading the wall clock (question 17). - Tests: four in
ui/tests.alloy(every's fixed rate and a gap, cancelling itself;atwith the wall clock set back and forward and the 5-second wait; a clock's ticks, a jump and no tick unread; a replay's wall clock, counting down to anat, and an unread clock asking no wake); goldencountdown(a clock and a countdown in its last minute, red, 12.5 s into a replay);tests/timerscounts a 100 ms timer over a second ended byat, under weston, under qemu, in node's page hidden and shown halfway, and on Windows by hand. - Sample
clock.alloy: a clock in the corner on the second, a countdown to a time typed in, red in its last minute and ended byat, a stopwatch with laps counted byevery, a note saved a second after typing stops (aftercancelled and set again).
**Sizes after F12** (2026-10-17; decisions/F12.md, questions 17B, 20B and 23B: a program using no timers, requests or storage grows by nothing):
- Timers: the window clock's heap runs first, then the wall's through
the
run_wallhook, andnext_dueasksnext_wall, both set by the first wall timer (at, a clock's tick); a repeating timer runs and is set due again throughrepeat, set by the firstevery. - Requests: one task in
app's scope waits for the first request and runs what it set (Network.service,serve_requests): a scope of the eight network tasks and the app'sstd::http::Client, a local there each request borrows as the task runs it (a request is a|=| (&Network, &Client) -> |=| (&var Ui)), so an app sending nothing links neither the client nor Mbed TLS, which the client inNetworkhad pulled into every native app (question 18A, +96 KB, now gone). - Storage: the store opens under
Ui.app, the window'sapp_name()taken as the app mounts its view, none in a Ui on its own. Writes go one at a time; a worker's setsNetwork.store_writing(anAtomicthe workers share with the loop) and clears it once written, and the last write as the app ends waits for it, so the older never lands over the newer. - These first passed raw
c_pointerhandles between ui's own code (the window, the client, the store's flag); since 2026-10-17 they are the borrows, owned name and shared atomic above, closer to the spec (section 6.3 givesc_pointerfor state crossing C), for 4 KB. The page's inbox stays one (page_inbox): it is state the browser calls back aftermainreturns, reached by the callbackstd::http::starthands to the page, which section 6.3 keeps withc_pointer::keep. - Size, release builds as
bench.shbuilds them: the counter is 1,839,440 bytes natively (1,835,376 with the handles, 1,931,728 before these changes, 1,835,664 before question 18A) and 1,311,894 of wasm (1,311,213 with the handles, 1,312,590 before): the wall heap and repeat code are gone, the starting task and an out-of-lineChannel::receive(two callers now) taking most of it back, then the requests' own channel type, the flag and the name; what stays is the timers' heaps, the requests' channel and exchanges,app_idand the accessibility roles.
**Showcase answers as built** (2026-10-17; decisions/showcase.md,
the questions samples/tickets raised, decided 2026-10-16):
- Hover (question 1A):
Widget::wants_hover(), false by default; laying out an element wanting it sets the hovering hook, asChoiceList,Radios,TabsandCalendarnow say they do, so a program's own widget getsInput::Hoveron a screen with none of them. - Bound containers (question 2A):
ui.bind_options(element, options)binds the options of an elementaddmade, the function run now and as what it read changes, its result renewing the element through its widget'srenewwhile the node keeps its children (options holding children panic, asbind's do). - Rounded clips (question 3A):
Widget::clip_radii()(square by default) gives a clipping element's corners, which painting sets on its canvas node's clip, sodrawtests each pixel of its paint and its children against the rounded rectangle;Column,Row,Stack,WrapandGridtakeclip_radii: Option<Radii>, clipping when set. Hit tests stay rectangular. Goldenclipped(a picture across a card's top, one filling a card rounded at two corners). - Pixels (question 4A): painting snaps each element's edges to device
pixels as browsers snap boxes: each edge rounded where it lies on the
window at its scale, the size the distance between them, so siblings
meeting still meet and nothing starts between two pixel rows (the
lighter row along the top of the tickets' posters is gone). Layout,
hit tests and the accessibility tree keep fractions; a node keeps
where it is shown (
shown_at,shown_size, logical) and itsresidue, how far its top left lies past its pixel, which is all its children's snapping needs, so a node is snapped again only when it moves or resizes, or its parent's residue or the scale changes (a scroll by whole pixels snaps nothing under it). A widget painted at another size is painted again, but not one whose paint came with its layout (Text's, throughtake_paint), whose glyphs keep their quarter-pixel positions. Transitions place and scale from the shown rectangle. 60 goldens moved by a pixel here and there (ui46,ticketsall 14), looked at: borders and fields sharper, text the same. The counter grows by 400 bytes natively and 290 of wasm, to 1,892,160 and 1,350,172 asbench.shbuilds it (with absolute paths, whose fault locations the earlier measures here, with relative ones, left out), 172 bytes past its wasm budget (showcase.md, question 16). Test inui/tests.alloy.
UNBOUNDEDREGULARSEMIBOLDBOLDExtentExtent::zeroLimitsLimits::looseLimits::tightconstrainloosenedinsidePaddingPadding::allPadding::symmetricSizingLayoutDirectionAlignmentJustifyThemeTheme::lightTheme::darkInkInk::rgbInk::rgbacolorElementOwnerTimerSignalChangeWidgetlayouteventchildrensizinginteractivefocusablecursorcaretclipsclip_radiioverlaytake_paintsemanticspartssettlingwants_hovermirrors_childrenPartPartRequestInputLookfrom_startMarksArrangecountlay_outplacedirectionsizingthemefontstext_styleUiUi::createnodenode_varsignalgetsetupdateupdate_whereaddbindbind_optionsshowKeepswitcheachlistimageset_imagefree_imagethemeset_thememountupdate_allbackgroundset_clipboardrequest_pasteon_close_requestedquitnowaftereveryatclockHandlerOptionsroot_owneraftereveryatcancelOverlayOverlay::dialogOverlay::alertOverlay::popupLayerRolePlaceCornerLayeropencloseis_opensourceExtensioneventclocktimersdeadlineupdatingupdatedframepaintedplacedowner_goingpointerhoveredpressedreleasedkeyescapedfocuseddismisseddescribingtext_mapTextLookhandledshow_inclosingreplayedinstallextensionextension_varinstall_fontslanguageset_languagedirectionset_directiondirecteddirection_ofannouncefocusdraw_offscreenscroll_atclick_athas_focusrefreshhandling_sizehandling_rtlmodifiersframe_ofexistscensusMotionEasingRepeatDurationsTransitiontransitionreduced_motionset_reduced_motionscroll_toTextTextAlignText::fromText::fromText::headingButtonButtonVariantButton::textButton::primaryButton::plainCheckboxCheckbox::ofSliderTextFieldTextField::ofColumnRowStackWrapTrackGridScrollImageIdFitImageListOptionsGroupSpacerspacerappHudHud::createeventdrawwith_workerstextureReplayConfigDrawnReplayedreplayWorkersServiceWorkers::run
const UNBOUNDEDsource
exp const UNBOUNDED: f32 = 1000000000.0;
A length no limit reaches: a maximum that does not constrain.
const REGULARsource
exp const REGULAR: u32 = text::REGULAR;
Text weights, from pkg::alloy::text.
const SEMIBOLDsource
exp const SEMIBOLD: u32 = text::SEMIBOLD;
const BOLDsource
exp const BOLD: u32 = text::BOLD;
type Extentsource
exp type Extent = struct
Fields
exp width: f32exp height: f32
Functions
fn Extent::zerosource
exp fn Extent::zero() -> Extent
type Limitssource
exp type Limits = struct
The sizes an element may take: its parent's constraints.
Fields
exp min_width: f32 = 0.0exp max_width: f32 = UNBOUNDEDexp min_height: f32 = 0.0exp max_height: f32 = UNBOUNDED
Functions
fn Limits::loosesource
exp fn Limits::loose(width: f32, height: f32) -> Limits
Any size up to the extent.
fn Limits::tightsource
exp fn Limits::tight(width: f32, height: f32) -> Limits
Exactly the extent.
fn constrainsource
exp fn constrain(self limits: &Limits, extent: Extent) -> Extent
The extent brought within the limits.
fn loosenedsource
exp fn loosened(self limits: &Limits) -> Limits
The limits with no minimum.
fn insidesource
exp fn inside(self limits: &Limits, padding: &Padding) -> Limits
The limits less the padding on each side.
type Paddingsource
exp type Padding = struct
Room inside an element's edges: start on the side it reads from, the
left left to right and the right right to left, end on the other.
Fields
exp start: f32 = 0.0exp top: f32 = 0.0exp end: f32 = 0.0exp bottom: f32 = 0.0
Functions
fn Padding::allsource
exp fn Padding::all(length: f32) -> Padding
fn Padding::symmetricsource
exp fn Padding::symmetric(horizontal: f32, vertical: f32) -> Padding
type Sizingsource
exp type Sizing = struct
The size an element asks for, whatever lays it out: with no width or
height it takes the size of what it holds; grow shares the room a
row or column has left among its children in proportion.
Fields
exp width: Option<f32> = ::Noneexp height: Option<f32> = ::Noneexp min_width: f32 = 0.0exp min_height: f32 = 0.0exp max_width: f32 = UNBOUNDEDexp max_height: f32 = UNBOUNDEDexp grow: f32 = 0.0
type LayoutDirectionsource
exp type LayoutDirection = enum
Which way an element reads (decisions/F14.md, F14a): from the left or from the right, its children placed from its start and its own drawing following.
Variants
LeftToRightRightToLeft
type Alignmentsource
exp type Alignment = enum
Where children go across a row or column, or within a stack: Start and End on the element's own sides, the right and the left right to left.
Variants
StartCenterEndStretch
type Justifysource
exp type Justify = enum
Where children go along a row or column with room left.
Variants
StartCenterEndBetween
type Themesource
exp type Theme = struct
Colors by role, and the scales widgets take their lengths from.
Fields
exp background: Colorunder everything
exp surface: Colorcards, fields
exp text: Colorexp muted: Colortext of lesser importance
exp primary: Colorexp on_primary: Colortext over primary
exp neutral: Colorsecondary buttons
exp border: Colorexp danger: Color = Color::rgb(0.8, 0.15, 0.15)what is wrong: a field in error's border, a failure's text
exp scrim: Color = Color::rgba(0.0, 0.0, 0.0, 0.4)over what a modal layer covers
exp shadow: Shadow = Shadow::soft( 0.0, 8.0, 24.0, Color::rgba(0.0, 0.0, 0.0, 0.18) )a layer's panel's
exp hover: f32how much hovering lightens or darkens, 0 to 1
exp press: f32exp motion: Durations = Durations { .short = Duration::from_milliseconds(100), .medium = Duration::from_milliseconds(200), .long = Duration::from_milliseconds(300) }how long built-in motion takes: hovering and fades, popups, dialogs and toasts, screens
exp focus: Colorexp radius: f32exp spacing: f32exp text_size: f32exp heading_size: f32
Functions
fn Theme::lightsource
exp fn Theme::light() -> Theme
fn Theme::darksource
exp fn Theme::dark() -> Theme
type Inksource
exp type Ink = enum
A color by its role in the theme, looked up when drawn, so switching
the theme changes it; or one given (Exact). None is the widget's
own: the theme's text color for text, nothing for a background or a
border.
Variants
NoneTextMutedPrimaryOnPrimaryNeutralSurfaceBackgroundBorderFocusDangerExact: Color
Functions
fn Ink::rgbsource
exp fn Ink::rgb(r: f32, g: f32, b: f32) -> Ink
fn Ink::rgbasource
exp fn Ink::rgba(r: f32, g: f32, b: f32, a: f32) -> Ink
fn colorsource
exp fn color(self ink: &Ink, theme: &Theme) -> Option<Color>
The ink's color in the theme, None for None.
type Elementsource
exp type Element = struct
An element of a Ui: a copyable handle, valid until its owner goes.
Fields
exp index: u32exp generation: u32
type Ownersource
exp type Owner = struct
What a view made, freed together as it goes (a screen, a row of
each), or the app's root: a copyable handle, naming nothing once it
went. Timers and requests may be given one (HandlerOptions).
Fields
exp index: u32exp generation: u32
type Timersource
exp type Timer = struct
A function after, every or at runs: a copyable handle, naming
nothing once it ran (but repeating), was cancelled or its owner went.
Fields
exp index: u32exp generation: u32
type Signalsource
exp type Signal<T> = struct
A value the UI shows, in a Ui's store: a copyable handle, valid until its owner goes. Reading it in a binding makes the binding run again when it changes.
Fields
exp index: u32exp generation: u32
Functions
exp fn get<T>(self signal: &Signal<T>, ui: &Ui) -> &Texp fn set<T>(self signal: &Signal<T>, ui: &var Ui, value: T)exp fn update<T>(self signal: &Signal<T>, ui: &var Ui, change: |&| (&var T))exp fn update_where<T>( self items: &Signal<Vector<T>>, ui: &var Ui, picks: |&| (&T) -> bool, change: |&| (&var T) )exp fn peek<T>(self signal: &Signal<T>, ui: &Ui) -> &Texp fn peek_var<T>(self signal: &Signal<T>, ui: &var Ui) -> &var T
type Changesource
exp type Change = enum
What a binding's new options change of an element.
Variants
NothingPaintLayout
interface Widgetsource
exp interface Widget
What an element is: an option struct declaring Widget, laid out,
painted and given input through these functions. Only paint and
renew have no default.
Required functions
fn layout(self: &var, arrange: &var Arrange, limits: Limits) -> Extent;Its size within the limits, its children laid out and placed through
arrange; by default the smallest size holding its children, each at its top left.fn paint(self: &, look: &Look, paint: &var Paint);What it draws, in its own coordinates, its size in
look; its children draw over it.fn event(self: &var, ui: &var Ui, input: &Input) -> bool;Input sent to it, or bubbling up from a child; whether it handled it, which stops the bubbling.
fn renew(self: &var, next: Self) -> Change;Takes the options a binding gave again, keeping its own state.
fn children(self: &) -> &[Element];The elements it holds, which
addadopts.fn sizing(self: &) -> Sizing;fn interactive(self: &) -> bool;Whether the pointer finds it, which hovering and pressing repaint.
fn focusable(self: &) -> bool;Whether it takes the keyboard's focus, by Tab or a press.
fn cursor(self: &) -> Cursor;How the pointer looks over it.
fn caret(self: &) -> Option<Rect>;Where text is typed into it while focused, in its coordinates, for the input method to show its candidates by.
fn clips(self: &) -> bool;Whether its children and its own paint are kept within its bounds.
fn clip_radii(self: &) -> Radii;The corners' radii of the rounded rectangle a clipping element keeps them within, each pixel tested; by default none, square corners.
fn overlay(self: &, look: &Look, paint: &var Paint);What a clipping element draws over its children, as a scroll's bar.
fn take_paint(self: &var) -> Option<Paint>;A paint made ahead, as when laying out, which painting takes in place of calling
paint.fn semantics(self: &) -> Semantics;What it is to a screen reader (PLAN.md, F6); by default nothing, its children standing for it.
fn parts(self: &) -> Vector<Part>;The items it draws itself, each a node of the accessibility tree under its own: an option, a radio; by default none. What a screen reader asks of one comes as Input::Part.
fn settling(self: &, since: Duration) -> bool;Whether its drawing still moves,
sinceits options last changed (look.since): while true it is painted again next frame. By default false.fn wants_hover(self: &) -> bool;Whether it follows the pointer over what it draws (a list's rows), getting Input::Hover as it moves with no button held; by default false. Laying it out sets the hook giving those.
fn mirrors_children(self: &) -> bool;Whether the x its layout places a child at is from its start edge, which the Ui turns into one from the left in an element read right to left; by default true. One placing in window coordinates, as a layer's host, says false and mirrors what it means itself.
Implemented by
exp type DropArea : Widget = structexp type Calendar : Widget = structexp type DatePicker : Widget + Popup = structexp type TimePicker : Widget + Popup = structexp type Text : Widget = structexp type Button : Widget = structexp type Checkbox : Widget = structexp type Slider : Widget = structexp type TextField : Widget = structexp type Column : Widget = structexp type Row : Widget = structexp type Stack : Widget = structexp type Wrap : Widget = structexp type Grid : Widget = structexp type Scroll : Widget = structexp type Image : Widget = structexp type Group : Widget = structexp type Spacer : Widget = structexp type MenuButton : Widget = structexp type Select<T: Equal> : Widget + Popup = structexp type ChoiceList<T: Equal> : Widget = structexp type Radios<T: Equal> : Widget = structexp type Tabs<T: Equal> : Widget = structexp type Spinner : Widget = structexp type ProgressBar : Widget = structexp type Tooltip : Widget = struct
fn layoutsource
exp fn layout(self widget: &var Widget, arrange: &var Arrange, limits: Limits) -> Extent
fn eventsource
exp fn event(self widget: &var Widget, ui: &var Ui, input: &Input) -> bool
fn childrensource
exp fn children(self widget: &Widget) -> &[Element]
fn sizingsource
exp fn sizing(self widget: &Widget) -> Sizing
fn interactivesource
exp fn interactive(self widget: &Widget) -> bool
fn focusablesource
exp fn focusable(self widget: &Widget) -> bool
fn cursorsource
exp fn cursor(self widget: &Widget) -> Cursor
fn caretsource
exp fn caret(self widget: &Widget) -> Option<Rect>
fn clipssource
exp fn clips(self widget: &Widget) -> bool
fn clip_radiisource
exp fn clip_radii(self widget: &Widget) -> Radii
fn overlaysource
exp fn overlay(self widget: &Widget, look: &Look, paint: &var Paint)
fn take_paintsource
exp fn take_paint(self widget: &var Widget) -> Option<Paint>
fn semanticssource
exp fn semantics(self widget: &Widget) -> Semantics
fn partssource
exp fn parts(self widget: &Widget) -> Vector<Part>
fn settlingsource
exp fn settling(self widget: &Widget, since: Duration) -> bool
fn wants_hoversource
exp fn wants_hover(self widget: &Widget) -> bool
fn mirrors_childrensource
exp fn mirrors_children(self widget: &Widget) -> bool
type Partsource
exp type Part = struct
An item an element draws itself, to a screen reader.
Fields
exp semantics: Semanticsexp bounds: Rectin the element's coordinates
exp focused: bool = falseholds the keyboard's focus while the element has it
type PartRequestsource
exp type PartRequest = struct
What a screen reader asks of one of an element's parts, by its index among them: Click, Select, Focus or ScrollIntoView.
Fields
exp part: u32exp action: Action
type Inputsource
exp type Input = enum
Input an element is given, at a point in its own coordinates.
Variants
Press: PointRelease: PointClick: Pointa press and a release on the element
Moved: Pointthe pointer moved while the element captured it by a press
Key: KeyEventto the focused element, then up its ancestors
Text: StringPreedit: PreeditFocus: boolthe element took the focus, or lost it
Scroll: Pointthe wheel or a touchpad, in logical pixels, to the element under the pointer, then up its ancestors
Action: Actionwhat a screen reader asks of the element that no other input gives: setting a value or a selection (a click comes as Click, stepping as arrow keys, focusing and scrolling into view through the Ui)
Paste: Stringthe clipboard's text, to the element that asked for it with
ui.request_paste()Part: PartRequestwhat a screen reader asks of one of its parts
Hover: Pointthe pointer moved over the element with no button held, once an element wanting it (
Widget::wants_hover) was laid out
type Looksource
exp type Look = struct
What an element paints with: its size, the theme and its state.
Fields
exp size: Extentexp theme: &Themeexp hovered: boolexp pressed: boolexp hover: f32how hovered and pressed it is, from 0 to 1, easing over the theme's short duration as the pointer comes and goes
exp press: f32exp since: Durationthe time since its options last changed, or since it was made: what a widget moving its own drawing goes by (
Widget::settling)exp focused: boolexp focus_ring: boolfocused from the keyboard, which shows the focus ring
exp marks: &Marksexp images: &[StoredImage]exp reduced: boolthe motion asked for is less
exp direction: LayoutDirection = LayoutDirection::LeftToRightwhich way the element reads: its own drawing at its start, the right right to left
Functions
fn from_startsource
exp fn from_start(self look: &Look, x: f32, width: f32) -> f32
The x of something width wide at x from the element's start edge:
x itself left to right, from the right edge right to left.
type Markssource
exp type Marks = struct
Small pictures widgets paint, made with the canvas.
Fields
exp check: Option<Picture>a check mark's coverage
exp chevron: Option<Picture> = ::Nonea downward chevron's, made as a Select first lays out
exp previous: Option<Picture> = ::Nonechevrons to the left and to the right, made as a calendar first lays out
exp next: Option<Picture> = ::None
type Arrangesource
exp type Arrange = struct
The children of an element being laid out, the elements show and
each make standing in place of those.
Fields
exp ui: &var Ui
Functions
exp fn count(self arrange: &Arrange) -> u64exp fn lay_out(self arrange: &var Arrange, child: u64, limits: Limits) -> Extentexp fn place(self arrange: &var Arrange, child: u64, at: Point)exp fn direction(self arrange: &Arrange) -> LayoutDirectionexp fn sizing(self arrange: &Arrange, child: u64) -> Sizingexp fn theme(self arrange: &Arrange) -> &Themeexp fn fonts(self arrange: &var Arrange) -> &var text::Fontsexp fn text_style(self arrange: &var Arrange, size: f32) -> text::TextStyle
fn countsource
exp fn count(self arrange: &Arrange) -> u64
How many children there are.
fn lay_outsource
exp fn lay_out(self arrange: &var Arrange, child: u64, limits: Limits) -> Extent
Lays a child out within the limits, its sizing applied, giving its size.
fn placesource
exp fn place(self arrange: &var Arrange, child: u64, at: Point)
Puts a child's top left at the point, its x from the element's start edge: the left, or the right right to left.
fn directionsource
exp fn direction(self arrange: &Arrange) -> LayoutDirection
Which way the element being laid out reads.
fn sizingsource
exp fn sizing(self arrange: &Arrange, child: u64) -> Sizing
fn themesource
exp fn theme(self arrange: &Arrange) -> &Theme
fn fontssource
exp fn fonts(self arrange: &var Arrange) -> &var text::Fonts
fn text_stylesource
exp fn text_style(self arrange: &var Arrange, size: f32) -> text::TextStyle
The theme's font at the size, a paragraph with no letter reading as the element does (decisions/F14.md, question 11A, as an element with dir=auto).
type Uisource
exp type Ui = struct
Elements are named by their index in nodes, signals, effects and
owners by theirs in their own vectors; a freed slot goes on its free
list for the next one made.
Fields
exp signals: Vector<SignalSlot> = Vector<SignalSlot>::empty()exp nodes: Vector<Node> = Vector<Node>::empty()exp effects: Vector<Effect> = Vector<Effect>::empty()exp owners: Vector<OwnerSlot> = Vector<OwnerSlot>::empty()exp owner: u32 = 0what is made now belongs to
exp root: Option<u32> = ::Noneexp theme: Theme = Theme::light()exp fonts_changed: u32 = 0counts changes to the fonts text is laid out with, for widgets keeping layouts (a calendar's names)
exp scene: Option<Scene> = ::Noneexp viewport: Extent = Extent::zero()exp scale: f32 = 1.0exp pointer: Option<Point> = ::Noneexp hovered: Option<u32> = ::Noneexp focused: Option<u32> = ::Noneexp focus_ring: bool = falseexp marks: Marks = Marks { .check = ::None }exp handling: Option<u32> = ::Nonethe element given input now
exp workers: Option<&Workers> = ::Nonethe app's worker tasks, when it has them, and the work
backgroundqueued for themexp jobs: Vector<|=| (&Workers) -> |=| ( &var Ui )> = Vector<|=| (&Workers) -> |=| (&var Ui)>::empty()exp finished: Vector<|=| (&var Ui)> = Vector<|=| (&var Ui)>::empty()what finished work gives, run before the next update
exp replaying: bool = falserun by
replay, which scripts what the window givesexp access_on: bool = falsewhether a screen reader reads, once one asked (pkg::alloy::ui_access), and whether an element was laid out or painted since the tree was last sent
exp access_stale: bool = trueexp time: Duration = Duration::from_nanoseconds(0)the window's clock and the wall clock as the event handled now came, the timers waiting for each, a heap by time for each (timers.alloy), and the clocks
clockmadeexp wall: i64 = 0exp layers: Vector<LayerSlot> = Vector<LayerSlot>::empty()the layers open, in the order they opened (layers.alloy), what their elements' handlers freed while running, kept to the event's end, and the press a popup opened
exp announced: Vector<Announcement> = Vector<Announcement>::empty()what screen readers are to say, given the window after the event
exp focus_after: Option<ScreenFocus> = ::Noneexp start_path: String = String::empty()the path the page was opened at, for the first navigator with paths
exp language_set: Signal<Option<String>> = Signal<Option<String>> { .index = 0, .generation = 0 }exp drawn: bool = falseexp moving: bool = falseexp waker: Waker = Waker::Nonethe window's waker, which the page's callbacks wake the loop by, and the name the app's data is kept under, the window's, taken as the app starts
exp app: String = String::empty()
Functions
exp fn open_files(self ui: &var Ui, dialog: FileDialog, then: |=| (&var Ui, Vector<ChosenFile>))exp fn save_file(self ui: &var Ui, dialog: FileDialog, then: |=| (&var Ui, ChosenFile))exp fn save_bytes(self ui: &var Ui, file: &ChosenFile, bytes: &[u8]) -> boolexp fn load<T>( self ui: &var Ui, request: |=| (&Ui) -> Option<Request>, read: |=| (&Response) -> std_result::Result<T, String>, options: LoadOptions ) -> Resource<T>exp fn send( self ui: &var Ui, request: Request, then: |=| (&var Ui, std_result::Result<Response, HttpError>) ) -> Pendingexp fn send( self ui: &var Ui, request: Request, then: |=| (&var Ui, std_result::Result<Response, HttpError>), options: HandlerOptions ) -> Pendingexp fn cancel_request(self ui: &var Ui, pending: Pending)exp fn progress(self ui: &Ui, pending: Pending) -> Option<Progress>exp fn store(self ui: &var Ui) -> &var KeptStoreexp fn persisted<T>( self ui: &var Ui, key: &[u8], initial: T, write: |=| (&T) -> Json, read: |=| (&Json) -> Option<T> ) -> Signal<T>exp fn today(self ui: &Ui) -> Dateexp fn set_today(self ui: &var Ui, day: Option<Date>)exp fn locale(self ui: &Ui) -> Localeexp fn set_locale(self ui: &var Ui, locale: Option<Locale>)exp fn form(self ui: &var Ui) -> Formexp fn text_field<T>(self ui: &var Ui, field: Field<T>, look: TextField) -> Elementexp fn input<T, W: Widget>(self ui: &var Ui, field: Field<T>, options: |=| (&Ui) -> W) -> Elementexp fn labelled<T>(self ui: &var Ui, field: Field<T>, input: Element) -> Elementexp fn form_summary(self ui: &var Ui, form: Form) -> Elementexp fn set_form_messages(self ui: &var Ui, messages: FormMessages)exp fn navigator<R>(self ui: &var Ui, first: R) -> Navigator<R>exp fn navigator_with<R>(self ui: &var Ui, first: R, paths: Paths<R>) -> Navigator<R>exp fn screens<R>( self ui: &var Ui, nav: Navigator<R>, screen: |=| (&var Ui, &R) -> Element ) -> Elementexp fn animated(self ui: &var Ui, value: f32, motion: Motion) -> Animatedexp fn Ui::create() -> Uiexp fn node(self ui: &Ui, index: u32) -> &Nodeexp fn node_var(self ui: &var Ui, index: u32) -> &var Nodeexp fn signal<T>(self ui: &var Ui, value: T) -> Signal<T>exp fn add<W: Widget>(self ui: &var Ui, options: W) -> Elementexp fn bind<W: Widget>(self ui: &var Ui, options: |=| (&Ui) -> W) -> Elementexp fn bind_options<W: Widget>( self ui: &var Ui, element: Element, options: |=| (&Ui) -> W ) -> Elementexp fn show( self ui: &var Ui, condition: |=| (&Ui) -> bool, view: |=| (&var Ui) -> Element ) -> Elementexp fn switch<K: hash::Key>( self ui: &var Ui, key: |=| (&Ui) -> K, view: |=| (&var Ui, K) -> Element, keep: Keep ) -> Elementexp fn each<T, K: hash::Key>( self ui: &var Ui, items: Signal<Vector<T>>, key: |=| (&T) -> K, row: |=| (&var Ui, Signal<T>) -> Element ) -> Elementexp fn list( self ui: &var Ui, count: |=| (&Ui) -> u64, row: |=| (&var Ui, u64) -> Element, options: ListOptions ) -> Elementexp fn image(self ui: &var Ui, width: u32, height: u32, pixels: Vector<u8>) -> ImageIdexp fn set_image(self ui: &var Ui, image: ImageId, width: u32, height: u32, pixels: Vector<u8>)exp fn free_image(self ui: &var Ui, image: ImageId)exp fn theme(self ui: &Ui) -> &Themeexp fn set_theme(self ui: &var Ui, theme: Theme)exp fn mount(self ui: &var Ui, root: Element, width: f32, height: f32)exp fn update_all(self ui: &var Ui)exp fn background(self ui: &var Ui, work: |=| () -> |=| (&var Ui))exp fn set_clipboard(self ui: &var Ui, text: String)exp fn request_paste(self ui: &var Ui)exp fn on_close_requested(self ui: &var Ui, asks: |=| (&var Ui) -> bool)exp fn quit(self ui: &var Ui)exp fn now(self ui: &Ui) -> Durationexp fn after(self ui: &var Ui, delay: Duration, then: |=| (&var Ui)) -> Timerexp fn every(self ui: &var Ui, period: Duration, then: |=| (&var Ui)) -> Timerexp fn at(self ui: &var Ui, moment: i64, then: |=| (&var Ui)) -> Timerexp fn clock(self ui: &var Ui, step: Duration) -> Signal<i64>exp fn root_owner(self ui: &Ui) -> Ownerexp fn after( self ui: &var Ui, delay: Duration, then: |=| (&var Ui), options: HandlerOptions ) -> Timerexp fn every( self ui: &var Ui, period: Duration, then: |=| (&var Ui), options: HandlerOptions ) -> Timerexp fn at(self ui: &var Ui, moment: i64, then: |=| (&var Ui), options: HandlerOptions) -> Timerexp fn cancel(self ui: &var Ui, timer: Timer)exp fn open(self ui: &var Ui, overlay: Overlay, view: |=| (&var Ui, Layer) -> Element) -> Layerexp fn close(self ui: &var Ui, layer: Layer)exp fn is_open(self ui: &Ui, layer: Layer) -> boolexp fn source(self ui: &Ui) -> Elementexp fn install(self ui: &var Ui, extension: *var Extension)exp fn extension<E: Extension>(self ui: &Ui) -> Option<&E>exp fn extension_var<E: Extension>(self ui: &var Ui) -> Option<&var E>exp fn install_fonts(self ui: &var Ui, install: (&var text::Fonts))exp fn language(self ui: &Ui) -> Stringexp fn set_language(self ui: &var Ui, language: Option<String>)exp fn direction(self ui: &Ui) -> LayoutDirectionexp fn set_direction(self ui: &var Ui, direction: Option<LayoutDirection>)exp fn directed(self ui: &var Ui, element: Element, direction: LayoutDirection) -> Elementexp fn direction_of(self ui: &Ui, element: Element) -> LayoutDirectionexp fn announce(self ui: &var Ui, text: String, assertive: bool)exp fn focus(self ui: &var Ui, element: Element)exp fn draw_offscreen(self ui: &var Ui, width: u32, height: u32)exp fn scroll_at(self ui: &var Ui, delta: Point, at: Point)exp fn click_at(self ui: &var Ui, at: Point)exp fn has_focus(self ui: &Ui, element: Element) -> boolexp fn refresh(self ui: &var Ui, change: Change)exp fn handling_size(self ui: &Ui) -> Extentexp fn handling_rtl(self ui: &Ui) -> boolexp fn modifiers(self ui: &Ui) -> Modifiersexp fn frame_of(self ui: &Ui, element: Element) -> Rectexp fn exists(self ui: &Ui, element: Element) -> boolexp fn census(self ui: &Ui) -> [u64 : 3]exp fn transition(self ui: &var Ui, element: Element, transition: Transition) -> Elementexp fn reduced_motion(self ui: &Ui) -> boolexp fn set_reduced_motion(self ui: &var Ui, reduced: Option<bool>)exp fn scroll_to(self ui: &var Ui, element: Element)exp fn spacer(self ui: &var Ui) -> Elementexp fn pointer_moved(self ui: &var Ui, at: Point)exp fn pointer_button(self ui: &var Ui, pressed: bool, at: Point)exp fn context_press(self ui: &var Ui, at: Point)exp fn context_release(self ui: &var Ui, at: Point)exp fn key_event(self ui: &var Ui, key: &KeyEvent)exp fn text_event(self ui: &var Ui, text: &String)exp fn preedit_event(self ui: &var Ui, preedit: &Preedit)exp fn uncapture(self ui: &var Ui)exp fn focus_node(self ui: &var Ui, target: Option<u32>, ring: bool)exp fn tab_order(self ui: &Ui) -> Vector<u32>exp fn takes_focus(self ui: &Ui, index: u32) -> boolexp fn move_focus(self ui: &var Ui, forward: bool)exp fn collect_focusable(self ui: &Ui, index: u32, out: &var Vector<u32>)exp fn hit_at(self ui: &Ui, at: Point, kind: Hit) -> Option<u32>exp fn origin_of(self ui: &Ui, index: u32) -> Pointexp fn input_area(self ui: &Ui) -> Option<Rect>exp fn dispatch(self ui: &var Ui, target: u32, input: Input) -> boolexp fn extensions_dismissed(self ui: &var Ui, index: u32)exp fn extensions_describing(self ui: &var Ui)exp fn extensions_closing(self ui: &var Ui)exp fn spoken_language(self ui: &Ui) -> &Stringexp fn reading_flow(self ui: &Ui) -> LayoutDirectionexp fn open_layer( self ui: &var Ui, overlay: Overlay, view: |=| (&var Ui, Layer) -> Element ) -> Layerexp fn owner_of(self ui: &Ui, index: u32) -> u32exp fn within(self ui: &Ui, index: u32, ancestor: u32) -> boolexp fn layer_index(self ui: &Ui, layer: Layer) -> Option<u64>exp fn layer_of(self ui: &Ui, index: u32) -> Option<u64>exp fn close_at(self ui: &var Ui, k: u64)exp fn panel_frame(self ui: &Ui, k: u64) -> Rectexp fn press_opened(self ui: &var Ui, layer: Layer)exp fn use_motion(self ui: &var Ui)exp fn frame(self ui: &var Ui)exp fn animating(self ui: &Ui) -> boolexp fn reveal(self ui: &var Ui, index: u32)exp fn scroll_offset(self ui: &Ui, index: u32) -> f32exp fn changed_signal(self ui: &var Ui, index: u32)exp fn new_effect(self ui: &var Ui) -> u32exp fn set_effect(self ui: &var Ui, effect: u32, node: Option<u32>, run: |=| (&var Ui))exp fn tracked<R>(self ui: &var Ui, effect: u32, f: &|&| (&Ui) -> R) -> Rexp fn run_effect(self ui: &var Ui, effect: u32)exp fn flush(self ui: &var Ui)exp fn read_shown(self ui: &Ui, index: u32) -> boolexp fn signal_alive(self ui: &Ui, index: u32, generation: u32) -> boolexp fn new_owner(self ui: &var Ui, parent: u32) -> u32exp fn free_owner(self ui: &var Ui, owner: u32)exp fn owner_index(self ui: &Ui, owner: Owner) -> u32exp fn owner_given(self ui: &Ui, owner: Option<Owner>) -> u32exp fn owned<R>(self ui: &var Ui, owner: u32, f: &|&| (&var Ui) -> R) -> Rexp fn new_timer(self ui: &var Ui, at: u64, period: u64, then: |=| (&var Ui)) -> Timerexp fn drop_timer(self ui: &var Ui, timer: Timer) -> boolexp fn run_timers(self ui: &var Ui)exp fn next_due(self ui: &var Ui) -> Option<Duration>exp fn fit(self ui: &Ui, pose: Pose, motion: Motion) -> Option<Fitted>exp fn move_element( self ui: &var Ui, element: Element, from: Pose, goal: Pose, motion: Motion, finish: Finish )exp fn keep_going(self ui: &var Ui, index: u32, pose: Pose, motion: Motion)exp fn new_node(self ui: &var Ui, widget: *var Widget, transparent: bool) -> u32exp fn element(self ui: &Ui, index: u32) -> Elementexp fn adopt(self ui: &var Ui, parent: u32, child: Element)exp fn mark_layout(self ui: &var Ui, index: u32)exp fn mark_paint(self ui: &var Ui, index: u32)exp fn apply(self ui: &var Ui, index: u32, change: Change)exp fn node_sizing(self ui: &Ui, index: u32) -> Sizingexp fn invalidate_all(self ui: &var Ui)exp fn fonts(self ui: &var Ui) -> &var text::Fontsexp fn set_view_hidden(self ui: &var Ui, view: View, hidden: bool)exp fn menu(self ui: &var Ui, place: Place, items: Vector<MenuItem>) -> Layerexp fn toast(self ui: &var Ui, toast: Toast)
fn Ui::createsource
exp fn Ui::create() -> Ui
A Ui with nothing in it, in the light theme, drawing nowhere until
app gives it a scene.
fn nodesource
exp fn node(self ui: &Ui, index: u32) -> &Node
The node of the element at the index.
fn node_varsource
exp fn node_var(self ui: &var Ui, index: u32) -> &var Node
fn signalsource
exp fn signal<T>(self ui: &var Ui, value: T) -> Signal<T>
A new signal holding the value, belonging to what is being made.
fn getsource
exp fn get<T>(self signal: &Signal<T>, ui: &Ui) -> &T
The value; in a binding, recorded so the binding runs again when it changes.
fn setsource
exp fn set<T>(self signal: &Signal<T>, ui: &var Ui, value: T)
Replaces the value; the bindings that read it run again once the handler returns.
fn updatesource
exp fn update<T>(self signal: &Signal<T>, ui: &var Ui, change: |&| (&var T))
Changes the value in place; the bindings that read it run again once the handler returns.
fn update_wheresource
exp fn update_where<T>(
self items: &Signal<Vector<T>>,
ui: &var Ui,
picks: |&| (&T) -> bool,
change: |&| (&var T)
)
Changes in place the items picks picks, as update does: the item
of a row each made, by its id.
fn addsource
exp fn add<W: Widget>(self ui: &var Ui, options: W) -> Element
A new element with the options, which stay as given; the elements they hold become its children.
fn bindsource
exp fn bind<W: Widget>(self ui: &var Ui, options: |=| (&Ui) -> W) -> Element
A new element whose options the function gives, now and again each
time a signal it read changes; the options may hold no children (an
element holding some is bound by bind_options).
fn bind_optionssource
exp fn bind_options<W: Widget>(
self ui: &var Ui,
element: Element,
options: |=| (&Ui) -> W
) -> Element
Binds the options of an element add made, holding children: the
function gives them now and again each time a signal it read changes,
the element keeping its children and its own state; its options hold
no children. The element must be of the options' type.
const card = ui.add(Card { .children = &[poster, title] });
ui.bind_options(card, (ui) => Card { .accessible = f"{event.get(&ui).title}" });
fn showsource
exp fn show(
self ui: &var Ui,
condition: |=| (&Ui) -> bool,
view: |=| (&var Ui) -> Element
) -> Element
An element holding the view while the condition holds, made when it starts to and freed, with all it made, when it stops.
type Keepsource
exp type Keep = enum
What switch does with a view no longer shown.
Variants
Allkept hidden, as it was left, until shown again
Nonefreed with all it made, made again from nothing when shown
fn switchsource
exp fn switch<K: hash::Key>(
self ui: &var Ui,
key: |=| (&Ui) -> K,
view: |=| (&var Ui, K) -> Element,
keep: Keep
) -> Element
An element showing the view for the key key gives, made when the key
first comes; when it changes, the view shown before is kept hidden
(Keep::All) or freed (Keep::None). A hidden view is not laid out,
drawn, hit, focused nor read by screen readers; its signals and its
widgets' own state stay as they were, and its bindings whose signals
changed run once it shows again.
fn eachsource
exp fn each<T, K: hash::Key>(
self ui: &var Ui,
items: Signal<Vector<T>>,
key: |=| (&T) -> K,
row: |=| (&var Ui, Signal<T>) -> Element
) -> Element
An element holding a row for each item of the vector, in order, made
by row from a signal of its own holding the item. Items are told
apart by the key key gives: a row whose key stays keeps its elements
and has its signal set when the vector changes, and a row whose key
goes is freed with all it made.
fn listsource
exp fn list(
self ui: &var Ui,
count: |=| (&Ui) -> u64,
row: |=| (&var Ui, u64) -> Element,
options: ListOptions
) -> Element
A scrolled list of count rows, of which only those in view, and a
screen's worth around them, are made: by row from the row's index,
each freed with all it made once far out of view. Rows are measured as
they are made; the list keeps its place on a row, so a row measured
taller than its estimate moves nothing in view.
fn imagesource
exp fn image(self ui: &var Ui, width: u32, height: u32, pixels: Vector<u8>) -> ImageId
Keeps the RGBA pixels, row after row, as a picture image elements show.
fn set_imagesource
exp fn set_image(self ui: &var Ui, image: ImageId, width: u32, height: u32, pixels: Vector<u8>)
Shows other pixels in place of the image's, in every element showing it, giving back the picture they replace.
fn free_imagesource
exp fn free_image(self ui: &var Ui, image: ImageId)
Gives back the image's pixels and picture; elements showing it show nothing, and its id names nothing from now on.
fn themesource
exp fn theme(self ui: &Ui) -> &Theme
The theme the widgets paint in.
fn set_themesource
exp fn set_theme(self ui: &var Ui, theme: Theme)
Paints and lays everything out again in the theme.
fn mountsource
exp fn mount(self ui: &var Ui, root: Element, width: f32, height: f32)
Makes the element the root, laid out at the size given in logical pixels.
fn update_allsource
exp fn update_all(self ui: &var Ui)
Runs the bindings marked, then lays out what changed; what an event changed shows after this.
fn backgroundsource
exp fn background(self ui: &var Ui, work: |=| () -> |=| (&var Ui))
Runs the work on one of the app's worker tasks, away from the UI thread, then the function the work gives on the UI thread, as a handler: the window goes on drawing and taking input meanwhile. The work owns what it captures, as its type says, and leaves the Ui and its signals to the function it gives:
ui.background(|move files| () -> |=| (&var Ui) {
const pictures = decode_all(&files);
return |move pictures| (ui: &var Ui) => shown.set(&var ui, move pictures);
});
With no workers (a page, replay, a Ui made on its own) the work
runs at once and its function at the next update.
fn set_clipboardsource
exp fn set_clipboard(self ui: &var Ui, text: String)
Puts the text on the clipboard, once the event is handled.
fn request_pastesource
exp fn request_paste(self ui: &var Ui)
Asks for the clipboard's text, which comes to the element handling input now as Input::Paste.
fn on_close_requestedsource
exp fn on_close_requested(self ui: &var Ui, asks: |=| (&var Ui) -> bool)
Asks the function when the person closes the window (or, on the web,
leaves or reloads the page): true closes it, false keeps it open, as
for a cart held or a form half done, the function asking the person
(a dialog whose "Close" then calls quit). On the web the browser
asks too, in its own words, when the function refuses.
fn quitsource
exp fn quit(self ui: &var Ui)
Closes the app's window once the event is handled, which ends app.
fn nowsource
exp fn now(self ui: &Ui) -> Duration
The time on the window's clock when the event being handled came,
monotonic from when the window opened; in replay, as the events'
Redraws set it.
fn aftersource
exp fn after(self ui: &var Ui, delay: Duration, then: |=| (&var Ui)) -> Timer
Runs then as a handler once the delay has passed on the window's
clock, unless cancelled first or its owner goes, the timer belonging to
what is being made as a signal does.
fn everysource
exp fn every(self ui: &var Ui, period: Duration, then: |=| (&var Ui)) -> Timer
Runs then every period from now on the window's clock, as a handler,
until cancelled or its owner goes. Fixed rate: each run is due a
period after the last was due, and runs missed while the loop was
busy or the machine slept are skipped, not run in a burst.
fn atsource
exp fn at(self ui: &var Ui, moment: i64, then: |=| (&var Ui)) -> Timer
Runs then as a handler once the wall clock reaches the moment
(nanoseconds since 1970 UTC, as std::time::wall_clock() gives),
unless cancelled first or its owner goes: for deadlines another machine
sets. It is at most 5 seconds late after the machine slept or the
system's time was set.
fn clocksource
exp fn clock(self ui: &var Ui, step: Duration) -> Signal<i64>
A signal of the wall clock (nanoseconds since 1970 UTC) at the start of the step it is in, changing on each multiple of the step: each second, each minute. Every call with one step gives the same signal, the Ui's own, which ticks only while some binding shown reads it.
type HandlerOptionssource
exp type HandlerOptions = struct
What a timer or a request belongs to, going with it.
Fields
exp owner: Option<Owner> = ::NoneNone: what is being made now, or the element whose handler runs;
ui.root_owner()keeps it until the app ends or it is cancelled
fn root_ownersource
exp fn root_owner(self ui: &Ui) -> Owner
The app's root: what belongs to it stays until the app ends.
fn aftersource
exp fn after(
self ui: &var Ui,
delay: Duration,
then: |=| (&var Ui),
options: HandlerOptions
) -> Timer
after with the options: a timer belonging to their owner.
fn everysource
exp fn every(
self ui: &var Ui,
period: Duration,
then: |=| (&var Ui),
options: HandlerOptions
) -> Timer
every with the options.
fn atsource
exp fn at(self ui: &var Ui, moment: i64, then: |=| (&var Ui), options: HandlerOptions) -> Timer
at with the options: a deadline outliving the screen setting it, as
seats held until a moment the server gave.
fn cancelsource
exp fn cancel(self ui: &var Ui, timer: Timer)
Forgets the timer; nothing when it ran or went already.
type Overlaysource
exp type Overlay = struct
How a layer opens over the window's content.
Fields
exp place: Place = Place::Centerexp modal: bool = falsea scrim under it; the pointer and the keyboard reach nothing below, and Tab goes round within it
exp escape: bool = trueEscape closes it
exp outside: bool = truea press outside it closes it, and goes no further
exp role: LayerRole = LayerRole::Plainwhat a screen reader calls it
exp label: String = String::empty()what a screen reader says of it
exp panel: bool = truedrawn on the theme's surface, rounded, with a shadow
exp on_close: |=| (&var Ui) = (ui) {}closed by Escape, a press outside, or ui.close
exp keyboard: bool = truetakes the focus as it opens: not a tooltip's or the toasts'
exp passive: bool = falsetakes no pointer and goes at any press: a tooltip's
exp tabbed: bool = falseTab goes to what has the focus first: a Select's list
Functions
fn Overlay::dialogsource
exp fn Overlay::dialog(label: &[u8]) -> Overlay
A modal dialog, centered, which a press outside does not close.
fn Overlay::alertsource
exp fn Overlay::alert(label: &[u8]) -> Overlay
A dialog asking for an answer: "Delete the order?"
fn Overlay::popupsource
exp fn Overlay::popup(anchor: Element) -> Overlay
A popup below the element, closed by a press outside.
type LayerRolesource
exp type LayerRole = enum
What a layer is to a screen reader.
Variants
PlainDialogAlertMenuTooltip
type Placesource
exp type Place = enum
Where a layer goes in the window.
Variants
Centerdialogs
Below: Elementunder the element, start edges aligned (left, or right right to left); above it when there is no room below
Above: Elementover the element; below it when there is no room above
After: Elementbeside it at its end, else its start: submenus
At: Pointwhere the pointer was, from the window's top left, reaching toward the end: a context menu
Corner: Cornerthe toasts
type Cornersource
exp type Corner = enum
Variants
TopStartTopEndBottomStartBottomEnd
type Layersource
exp type Layer = struct
A layer open: a copyable handle, naming nothing once it closed.
fn opensource
exp fn open(self ui: &var Ui, overlay: Overlay, view: |=| (&var Ui, Layer) -> Element) -> Layer
Opens a layer over the content showing what the view makes, given the layer to close it with; it belongs to the owner of the element whose handler opens it (a row's goes with the row), or to the app, and what its view made goes when it closes. A layer taking the keyboard focuses its first element taking the focus, or the one its view focused, and gives the focus back as it closes.
fn closesource
exp fn close(self ui: &var Ui, layer: Layer)
Closes the layer, calling its on_close; nothing when it closed
already.
fn is_opensource
exp fn is_open(self ui: &Ui, layer: Layer) -> bool
Whether the layer is still open.
fn sourcesource
exp fn source(self ui: &Ui) -> Element
The element whose handler runs now: what a menu or popup is placed by.
interface Extensionsource
exp interface Extension
What a part of the Ui that a program reaches only by using it keeps and
does: its state in a struct of its own, installed as it is first used
(install) and found by its type (extension), the Ui calling it at
these points of its work, each of which does nothing by default. The
core's layers, wall-clock timers and motion are extensions, as are what
pkg::alloy::ui_controls and ui_app add; a program using none carries
none of their code.
type Counted : Extension = struct { events: u64 = 0 };
fn handled(self c: &var Counted, ui: &var Ui) => c.events += 1;
fn counted(self ui: &var Ui) -> &var Counted {
if (ui.extension<Counted>() is ::None) {
ui.install(new Counted {});
}
if (ui.extension_var<Counted>() is ::Some |&var c|) {
return &var c;
}
panic "no count";
}
Required functions
fn event(self: &var, ui: &var Ui, event: &Event);A window event came, after the timers it brought due ran.
fn clock(self: &var, ui: &var Ui);The clocks were read as an event came, before any timer runs.
fn timers(self: &var, ui: &var Ui);The window clock's timers due ran: the extension's own run now.
fn deadline(self: &var, ui: &var Ui) -> Option<u64>;When the window is to wake for it next, in nanoseconds on its clock; asked before the Ui's timers are, so it may set some.
fn updating(self: &var, ui: &var Ui);An update begins, before the bindings run.
fn updated(self: &var, ui: &var Ui);The bindings ran, and what changed was laid out.
fn frame(self: &var, ui: &var Ui);A frame begins, before its update: what moves this frame marked.
fn painted(self: &var, ui: &var Ui) -> bool;The frame was painted: what moves shown on the canvas; whether something still moves, for which the app draws the next frame.
fn placed(self: &var, ui: &var Ui, index: u32);An element marked
movingwas placed anew.fn owner_going(self: &var, ui: &var Ui, owner: u32);An owner goes, before what it made is freed.
fn pointer(self: &var, ui: &var Ui, at: Option<Point>);The pointer moved to the point, or left the window (None).
fn hovered(self: &var, ui: &var Ui, index: u32);The pointer came onto the element.
fn pressed(self: &var, ui: &var Ui, at: Point) -> bool;A button pressed at the point, before any element has it: true takes it, and it goes no further.
fn released(self: &var, ui: &var Ui, at: Point, under: Option<u32>);A button released at the point, over the element there, after the element it pressed had it.
fn key(self: &var, ui: &var Ui, key: &KeyEvent) -> bool;A key, before the focused element has it: true takes it.
fn escaped(self: &var, ui: &var Ui) -> bool;Escape, which no element took: true when the extension took it.
fn focused(self: &var, ui: &var Ui, from: Option<u32>, onto: Option<u32>, ring: bool);The focus moved from one element to another, either of them none;
ringwhen by the keyboard.fn dismissed(self: &var, ui: &var Ui, index: u32);A screen reader asked to dismiss the element.
fn describing(self: &var, ui: &var Ui);The accessibility tree is about to be sent.
fn text_map( self: &var, ui: &var Ui, laid: &text::Layout, origin: Point, look: TextLook ) -> Option<TextMap>;A text a screen reader reads, laid out while one does (
access_on) and drawn atoriginin its element: the map it reads it by (pkg::alloy::ui_access); none by default.fn handled(self: &var, ui: &var Ui);An event was handled, and the Ui updated.
fn show_in(self: &var, ui: &var Ui, window: &var Window);After an event, what the extension gives the window.
fn closing(self: &var, ui: &var Ui);The app closes its window, or a replay ends.
fn replayed(self: &var, ui: &var Ui, replayed: &var Replayed);A replay ended: what the extension adds to what it gives.
fn eventsource
exp fn event(self e: &var Extension, ui: &var Ui, event: &Event)
fn clocksource
exp fn clock(self e: &var Extension, ui: &var Ui)
fn timerssource
exp fn timers(self e: &var Extension, ui: &var Ui)
fn deadlinesource
exp fn deadline(self e: &var Extension, ui: &var Ui) -> Option<u64>
fn updatingsource
exp fn updating(self e: &var Extension, ui: &var Ui)
fn updatedsource
exp fn updated(self e: &var Extension, ui: &var Ui)
fn framesource
exp fn frame(self e: &var Extension, ui: &var Ui)
fn paintedsource
exp fn painted(self e: &var Extension, ui: &var Ui) -> bool
fn placedsource
exp fn placed(self e: &var Extension, ui: &var Ui, index: u32)
fn owner_goingsource
exp fn owner_going(self e: &var Extension, ui: &var Ui, owner: u32)
fn pointersource
exp fn pointer(self e: &var Extension, ui: &var Ui, at: Option<Point>)
fn hoveredsource
exp fn hovered(self e: &var Extension, ui: &var Ui, index: u32)
fn pressedsource
exp fn pressed(self e: &var Extension, ui: &var Ui, at: Point) -> bool
fn releasedsource
exp fn released(self e: &var Extension, ui: &var Ui, at: Point, under: Option<u32>)
fn keysource
exp fn key(self e: &var Extension, ui: &var Ui, key: &KeyEvent) -> bool
fn escapedsource
exp fn escaped(self e: &var Extension, ui: &var Ui) -> bool
fn focusedsource
exp fn focused(
self e: &var Extension,
ui: &var Ui,
from: Option<u32>,
onto: Option<u32>,
ring: bool
)
fn dismissedsource
exp fn dismissed(self e: &var Extension, ui: &var Ui, index: u32)
fn describingsource
exp fn describing(self e: &var Extension, ui: &var Ui)
fn text_mapsource
exp fn text_map(
self e: &var Extension,
ui: &var Ui,
laid: &text::Layout,
origin: Point,
look: TextLook
) -> Option<TextMap>
type TextLooksource
exp type TextLook = struct
How a text a screen reader reads is drawn (Extension::text_map): its size in logical pixels, weight and color, and whether it is a heading or cannot be edited.
Fields
exp size: f32exp weight: u32exp color: Colorexp heading: bool = falseexp read_only: bool = false
fn handledsource
exp fn handled(self e: &var Extension, ui: &var Ui)
fn show_insource
exp fn show_in(self e: &var Extension, ui: &var Ui, window: &var Window)
fn closingsource
exp fn closing(self e: &var Extension, ui: &var Ui)
fn replayedsource
exp fn replayed(self e: &var Extension, ui: &var Ui, replayed: &var Replayed)
fn installsource
exp fn install(self ui: &var Ui, extension: *var Extension)
Adds the extension, which the Ui calls from now on.
fn extensionsource
exp fn extension<E: Extension>(self ui: &Ui) -> Option<&E>
The extension of the type, if one was installed.
fn extension_varsource
exp fn extension_var<E: Extension>(self ui: &var Ui) -> Option<&var E>
fn install_fontssource
exp fn install_fonts(self ui: &var Ui, install: (&var text::Fonts))
Installs what a package adds to text, as pkg::alloy::text_scripts' and
text_fonts' install_into, on every fonts the Ui lays text out with:
its own, and each scene's canvas's as it comes; what was laid out is
laid out again.
fn languagesource
exp fn language(self ui: &Ui) -> String
The language the Ui's content is in, a BCP 47 tag: the one
set_language gave, else the first of the system's preferred
languages the app is written in (WindowConfig.languages), else the
app's first. A binding reading it runs again when it changes.
fn set_languagesource
exp fn set_language(self ui: &var Ui, language: Option<String>)
Sets the app's language, None giving the system's choice again; the direction follows it unless set, and everything is laid out again.
fn directionsource
exp fn direction(self ui: &Ui) -> LayoutDirection
Which way the Ui reads: the one set_direction gave, else its
language's. A binding reading it runs again when it changes.
fn set_directionsource
exp fn set_direction(self ui: &var Ui, direction: Option<LayoutDirection>)
Sets which way the Ui reads, None giving its language's again; everything is laid out again.
fn directedsource
exp fn directed(self ui: &var Ui, element: Element, direction: LayoutDirection) -> Element
The element, and all it holds, reading in the direction whatever holds
it, as dir on an HTML element: a quotation in another language,
media controls keeping their sides.
fn direction_ofsource
exp fn direction_of(self ui: &Ui, element: Element) -> LayoutDirection
Which way the element read as last laid out.
fn announcesource
exp fn announce(self ui: &var Ui, text: String, assertive: bool)
Has screen readers say the text, politely or, when assertive, at
once, without the focus moving; once pkg::alloy::ui_access is
installed, before which nothing is said.
fn focussource
exp fn focus(self ui: &var Ui, element: Element)
Gives the element the keyboard's focus, when it takes it.
fn draw_offscreensource
exp fn draw_offscreen(self ui: &var Ui, width: u32, height: u32)
Paints what changed and draws a frame of the size, in physical pixels, on the CPU device with no window, for tests and benchmarks measuring all a Ui keeps.
fn scroll_atsource
exp fn scroll_at(self ui: &var Ui, delta: Point, at: Point)
Scrolls what is under the point by the delta, in logical pixels, as the wheel does: for tests and benchmarks driving a Ui directly.
fn click_atsource
exp fn click_at(self ui: &var Ui, at: Point)
Presses and releases the primary button at the point, in logical pixels, as the pointer does: for tests and benchmarks driving a Ui directly.
fn has_focussource
exp fn has_focus(self ui: &Ui, element: Element) -> bool
Whether the element has the keyboard's focus.
fn refreshsource
exp fn refresh(self ui: &var Ui, change: Change)
Lays out or paints again the element handling input now, whose own state the input changed.
fn handling_sizesource
exp fn handling_size(self ui: &Ui) -> Extent
The size of the element handling input now, as last laid out.
fn handling_rtlsource
exp fn handling_rtl(self ui: &Ui) -> bool
Whether the element handling input now reads right to left.
fn modifierssource
exp fn modifiers(self ui: &Ui) -> Modifiers
The modifier keys held now.
fn frame_ofsource
exp fn frame_of(self ui: &Ui, element: Element) -> Rect
Where the element is, from the root's top left, and its size, as last laid out.
fn existssource
exp fn exists(self ui: &Ui, element: Element) -> bool
Whether the element's owner is still there.
fn censussource
exp fn census(self ui: &Ui) -> [u64 : 3]
The number of elements, signals and bindings alive, for tests.
type Motionsource
exp type Motion = struct
How something moves: for how long, along which curve, after what
delay and how many times. Under reduced motion a value jumps and an
element only fades, unless essential.
Fields
exp duration: Duration = Duration::from_milliseconds(200)exp easing: Easing = Easing::Standardexp delay: Duration = Duration::from_milliseconds(0)exp repeat: Repeat = Repeat::Onceexp essential: bool = falsestill moves under reduced motion: a progress bar
Functions
type Easingsource
exp type Easing = enum
How far along a motion is at each moment of its duration.
Variants
LinearStandardcubic-bezier(0.2, 0, 0, 1): fast out, slow in
InOutInOutCubic: [f32 : 4]CSS's cubic-bezier(x1, y1, x2, y2)
type Repeatsource
exp type Repeat = enum
Variants
OnceTimes: u32ForeverAlternateback and forth, forever
type Durationssource
exp type Durations = struct
How long the built-in motion takes.
Fields
exp short: Durationhovering, pressing, fades, popups and menus
exp medium: Durationdialogs, toasts, views switched
exp long: Durationscreens
type Transitionsource
exp type Transition = struct
How an element comes, goes and moves: the state it comes from and goes to, from its place as laid out.
Fields
exp fade: bool = trueexp slide: Point = ORIGINwhere it comes from and goes to, from its place, x toward the end: the left right to left
exp scale: f32 = 1.0its size at the start: 0.96 grows to 1
exp reveal: bool = falseits room opens and closes (layout each frame)
exp moves: bool = falsea new place from layout is moved to, not jumped to
exp motion: Motion = Motion {}
fn transitionsource
exp fn transition(self ui: &var Ui, element: Element, transition: Transition) -> Element
The element, playing the transition when it first shows, once the app
has drawn its first frame, and backwards when its owner goes: what it
drew stays, taking no input and out of the accessibility tree, until
the transition ends; with reveal its room shrinks meanwhile. Gives
the element to place, which holds the one given.
fn reduced_motionsource
exp fn reduced_motion(self ui: &Ui) -> bool
Whether motion is reduced: as the app set it, else as the system asks.
fn set_reduced_motionsource
exp fn set_reduced_motion(self ui: &var Ui, reduced: Option<bool>)
Reduces motion, or not, whatever the system asks; None follows the system again.
fn scroll_tosource
exp fn scroll_to(self ui: &var Ui, element: Element)
Scrolls the scrolls around the element, smoothly, until it shows.
type Textsource
exp type Text : Widget = struct
Text in one style, wrapped at the width it is given.
Fields
exp text: Stringexp size: Option<f32> = ::NoneNone: the theme's
exp weight: u32 = REGULARexp color: Ink = Ink::NoneNone: the theme's text color
exp heading: bool = falseat the theme's heading size when no size is given
exp align: TextAlign = TextAlign::Startexp sizing: Sizing = Sizing {}exp drawn: Option<Paint> = ::Nonemade by layout, taken by painting
Functions
type TextAlignsource
exp type TextAlign = enum
Where text goes across its room, the box and each line: Start and End on its element's sides, the right right to left, whatever script the text is in (decisions/F14.md, question 4A).
Variants
StartCenterEnd
fn Text::fromsource
exp fn Text::from(text: String) -> Text
fn Text::fromsource
exp fn Text::from(text: &[u8]) -> Text
fn Text::headingsource
exp fn Text::heading(text: &[u8]) -> Text
A title: bold, at the theme's heading size.
type Buttonsource
exp type Button : Widget = struct
A button showing its label, calling on_press when clicked.
Fields
exp label: Stringexp accessible: String = String::empty()what a screen reader says, the label when empty
exp on_press: |=| (&var Ui) = (ui) {}exp variant: ButtonVariant = ButtonVariant::Neutralexp enabled: bool = trueexp padding: Padding = Padding::symmetric(14.0, 8.0)exp sizing: Sizing = Sizing {}exp laid: Option<*text::Layout> = ::None
Functions
exp fn Button::text(label: &[u8], on_press: |=| (&var Ui)) -> Buttonexp fn Button::primary(label: &[u8], on_press: |=| (&var Ui)) -> Buttonexp fn Button::plain(label: &[u8], on_press: |=| (&var Ui)) -> Buttonexp fn paint(self b: &Button, look: &Look, paint: &var Paint)exp fn renew(self b: &var Button, next: Button) -> Change
type ButtonVariantsource
exp type ButtonVariant = enum
Variants
NeutralPrimaryPlaintext only
fn Button::textsource
exp fn Button::text(label: &[u8], on_press: |=| (&var Ui)) -> Button
fn Button::primarysource
exp fn Button::primary(label: &[u8], on_press: |=| (&var Ui)) -> Button
The button standing for the main action, in the theme's primary color.
fn Button::plainsource
exp fn Button::plain(label: &[u8], on_press: |=| (&var Ui)) -> Button
A button showing its label alone.
type Checkboxsource
exp type Checkbox : Widget = struct
A box with a check mark and a label: a click, Space or Enter calls
on_change with the other state.
Fields
exp checked: boolexp label: String = String::empty()exp accessible: String = String::empty()exp on_change: |=| (&var Ui, bool) = (ui, checked) {}exp enabled: bool = trueexp error: String = String::empty()what is wrong, none when empty: the box in the theme's danger color, and to screen readers invalid, the message its description;
requireda form needs it checkedexp required: bool = falseexp sizing: Sizing = Sizing {}exp laid: Option<*text::Layout> = ::None
Functions
fn Checkbox::ofsource
exp fn Checkbox::of(
checked: bool,
label: &[u8],
on_change: |=| (&var Ui, bool)
) -> Checkbox
type Slidersource
exp type Slider : Widget = struct
A value between min and max, by step when not 0, which dragging
the thumb or the arrow keys change, calling on_change.
Fields
exp value: f32exp min: f32 = 0.0exp max: f32 = 1.0exp step: f32 = 0.0exp label: String = String::empty()shown before the track
exp accessible: String = String::empty()the label when empty
exp on_change: |=| (&var Ui, f32) = (ui, value) {}exp enabled: bool = trueexp sizing: Sizing = Sizing {}exp laid: Option<*text::Layout> = ::None
Functions
type TextFieldsource
exp type TextField : Widget = struct
Text to type into, on one line or several: on_change gets the text
after each edit, which the field shows at once; options giving other
text replace it, the caret kept where it can be.
Fields
exp text: String = String::empty()exp on_change: |=| (&var Ui, String) = (ui, text) {}exp on_submit: |=| (&var Ui) = (ui) {}Enter on one line
exp placeholder: String = String::empty()exp accessible: String = String::empty()the placeholder when empty
exp error: String = String::empty()what is wrong with the text, none when empty: a border in the theme's danger color, and to screen readers the field is invalid, the message its description
exp description: String = String::empty()what more a screen reader says of it, after the error: a hint
exp required: bool = falsea form needs it filled in, which screen readers say
exp multiline: bool = falseexp secret: bool = falsea password: shown as dots, one a character, the caret and the selection among them; never copied nor cut (pasting is); to screen readers a password field whose value is the dots, and the input method told so
exp enabled: bool = trueexp padding: Padding = Padding::symmetric(10.0, 7.0)exp sizing: Sizing = Sizing {}exp editing: Editing = Editing {}
Functions
fn TextField::ofsource
exp fn TextField::of(text: String, on_change: |=| (&var Ui, String)) -> TextField
type Columnsource
exp type Column : Widget = struct
Children one under the other.
Fields
exp children: &[Element] = &[]exp gap: f32 = 0.0exp padding: Padding = Padding {}exp align: Alignment = Alignment::Startexp justify: Justify = Justify::Startexp background: Ink = Ink::Noneexp border: Ink = Ink::Noneexp radius: f32 = 0.0exp clip_radii: Option<Radii> = ::Nonekeeps its paint and its children within its rounded rectangle
exp sizing: Sizing = Sizing {}a context menu's: the right button, the Menu key, Shift+F10, or Control and a click on macOS, at a point from the window's top left
Functions
type Rowsource
exp type Row : Widget = struct
Children side by side.
Fields
exp children: &[Element] = &[]exp gap: f32 = 0.0exp padding: Padding = Padding {}exp align: Alignment = Alignment::Startexp justify: Justify = Justify::Startexp background: Ink = Ink::Noneexp border: Ink = Ink::Noneexp radius: f32 = 0.0exp clip_radii: Option<Radii> = ::Nonekeeps its paint and its children within its rounded rectangle
exp sizing: Sizing = Sizing {}
Functions
type Stacksource
exp type Stack : Widget = struct
Children over each other, the later ones on top.
Fields
exp children: &[Element] = &[]exp padding: Padding = Padding {}exp align: Alignment = Alignment::Startexp background: Ink = Ink::Noneexp border: Ink = Ink::Noneexp radius: f32 = 0.0exp clip_radii: Option<Radii> = ::Nonekeeps its paint and its children within its rounded rectangle
exp sizing: Sizing = Sizing {}
Functions
type Wrapsource
exp type Wrap : Widget = struct
Children in rows that wrap at the width: chips, tags, thumbnails.
Fields
exp children: &[Element] = &[]exp gap: f32 = 0.0between children on a line
exp line_gap: f32 = 0.0between lines
exp align: Alignment = Alignment::Startwithin a line's height
exp padding: Padding = Padding {}exp background: Ink = Ink::Noneexp border: Ink = Ink::Noneexp radius: f32 = 0.0exp clip_radii: Option<Radii> = ::Nonekeeps its paint and its children within its rounded rectangle
exp sizing: Sizing = Sizing {}
Functions
type Tracksource
exp type Track = enum
A column's width: Fixed logical pixels, the widest of its children
(Content), or a share of what is left (Fraction).
Variants
Fixed: f32ContentFraction: f32
type Gridsource
exp type Grid : Widget = struct
Children in cells, row after row, as many to a row as there are columns; each row as tall as its tallest child.
Fields
exp children: &[Element] = &[]exp columns: Vector<Track> = Vector<Track>::empty()exp column_gap: f32 = 0.0exp row_gap: f32 = 0.0exp align: Alignment = Alignment::Startwithin a cell
exp padding: Padding = Padding {}exp background: Ink = Ink::Noneexp border: Ink = Ink::Noneexp radius: f32 = 0.0exp clip_radii: Option<Radii> = ::Nonekeeps its paint and its children within its rounded rectangle
exp sizing: Sizing = Sizing {}
Functions
type Scrollsource
exp type Scroll : Widget = struct
Its one child, scrolled within its bounds by the wheel, a touchpad, or dragging the bar that shows while the child does not fit.
Fields
exp children: &[Element] = &[]exp horizontal: bool = falsescrolled sideways instead
exp sizing: Sizing = Sizing {}exp length: f32 = 0.0the scroll's own
Functions
type ImageIdsource
exp type ImageId = struct
A picture the Ui keeps, made from pixels with ui.image.
Fields
exp index: u32exp generation: u32an id of an image freed names none
type Fitsource
exp type Fit = enum
How a picture fills an image element of another shape.
Variants
Containall of it, centered
Coverall of the element, clipped
Fillstretched
type Imagesource
exp type Image : Widget = struct
A picture: its pixels' size in logical pixels unless sized.
Fields
exp image: ImageIdexp accessible: String = String::empty()none: a screen reader passes over it
exp fit: Fit = Fit::Containexp mirrors: bool = falsedrawn the other way round in an element read right to left: a picture that points (an arrow, a reply), not a photo or a logo
exp sizing: Sizing = Sizing {}
Functions
type ListOptionssource
exp type ListOptions = struct
A list's rows: how many, and an estimate of a row's height, which
rows not yet shown stand at; fixed rows are all that height.
Fields
exp estimate: f32 = 32.0exp fixed: bool = falseexp gap: f32 = 0.0exp sizing: Sizing = Sizing {}
type Groupsource
exp type Group : Widget = struct
The element show and each hold their views in, laid out as part of
its parent.
Functions
type Spacersource
exp type Spacer : Widget = struct
Room taking what its row or column leaves, pushing what follows it to the far end.
Fields
exp sizing: Sizing = Sizing { .grow = 1.0 }
Functions
fn spacersource
exp fn spacer(self ui: &var Ui) -> Element
fn appsource
exp fn app(config: &WindowConfig, view: |=| (&var Ui) -> Element) -> i32
Opens a window showing the view the function makes, and runs until
the window closes; gives the exit status for main.
type Hudsource
exp type Hud = struct
A Ui in an engine's own loop (F15.md): drawn over the engine's frame on the engine's device, its input taken from the engine's window, which it gives the cursor, the input method's area and the clipboard. It owns no window, device, surface or loop:
var hud = Hud::create(&var device, surface.format, &window, view);
// each event, before the game's own handling
if (hud.event(&var window, &event)) {
return; // the HUD took it
}
// each frame, after the game's drawing into the frame
hud.draw(&var device, &var encoder, frame, &var window);
It covers the whole window, following its size and scale. Its
background work (ui.background) runs at once on the loop's thread,
as a page's does, unless it is given workers (with_workers).
Fields
exp ui: Ui
Functions
exp fn Hud::create( device: &var Device, format: TextureFormat, window: &Window, view: |=| (&var Ui) -> Element ) -> Hudexp fn event(self hud: &var Hud, window: &var Window, event: &Event) -> boolexp fn draw( self hud: &var Hud, device: &var Device, encoder: &var Encoder, frame: Texture, window: &var Window )exp fn with_workers(self hud: &var Hud, workers: &Workers)exp fn texture(self hud: &Hud) -> Option<Texture>
fn Hud::createsource
exp fn Hud::create(
device: &var Device,
format: TextureFormat,
window: &Window,
view: |=| (&var Ui) -> Element
) -> Hud
A HUD showing the view the function makes over the window, drawn into frames of the format, the engine's surface's, on its device.
fn eventsource
exp fn event(self hud: &var Hud, window: &var Window, event: &Event) -> bool
Handles one of the window's events as an app's Ui would, and says
whether the HUD took it, the game then leaving it: a pointer's move,
button or scroll over an element taking input or while one is
pressed, a key or text while an element edits text. A Redraw draws
nothing (draw does), and closing the window is the game's to decide.
fn drawsource
exp fn draw(
self hud: &var Hud,
device: &var Device,
encoder: &var Encoder,
frame: Texture,
window: &var Window
)
Brings the HUD to a frame and records its drawing into the encoder: what changed redrawn into the texture it keeps, which is then blended over the frame, premultiplied, after what the frame holds. The window is given the cursor, the input method's area and the clipboard, and a frame is asked for while something moves.
fn with_workerssource
exp fn with_workers(self hud: &var Hud, workers: &Workers)
Runs the HUD's background work from now on on the workers, which wake
the window as each job finishes; on the web, where a program has no
tasks, it still runs at once. The workers come from Workers::run
around the engine's loop:
fn main() -> i32 {
return Workers::run(&|&| (workers: &Workers) -> i32 {
const game = Game { .workers = &workers, ... };
return run(&config, move game, on_event);
});
}
// once the HUD is made
hud.with_workers(&game.workers);
fn texturesource
exp fn texture(self hud: &Hud) -> Option<Texture>
The texture the HUD keeps its drawing in, for an engine placing it itself; None before its first frame.
type ReplayConfigsource
exp type ReplayConfig = struct
How replay runs an app: at the scale, its wall clock at the moment
when the script's time is 0 and going on with the script's time.
Fields
exp scale: f32 = 1.0exp wall: i64 = 0nanoseconds since 1970 UTC
exp drawn: Drawn = Drawn::Allthe Redraws drawn on the CPU and presented; at the others the app lays out and paints its canvas but draws no pixels, most of a frame's time
exp languages: Vector<String> = Vector<String>::empty()the system's preferred languages, most wanted first, which the app's language is chosen from; none chooses the app's first
type Drawnsource
exp type Drawn = enum
Which Redraws a replay draws.
Variants
AllLastthose at the last Redraw's time among the events: the app at rest
At: Vector<Duration>those at these times
type Replayedsource
exp type Replayed = struct
What a replay gives: the frames presented and what the app told the window and screen readers.
Fields
exp frames: Vector<Frame>exp access: AccessTreethe accessibility tree as the app left it, sent once an Event::AccessRequested came among the events
exp announcements: Vector<Announcement>what screen readers were given to say
exp history: Vector<HistoryEntry>each entry the app put the page's history at
exp toasts: Vector<String>each toast's text as it showed
exp language: Stringthe language the app told the window, and whether it reads right to left
exp right_to_left: bool
fn replaysource
exp fn replay(
config: &WindowConfig,
replay: ReplayConfig,
view: |=| (&var Ui) -> Element,
events: &[Event]
) -> Replayed
Runs the app as app does, in a headless window drawn on the CPU,
over the events, for tests.
type Workerssource
exp type Workers : Shared = struct
What the app's worker tasks share with the loop: the work queued, the functions finished work gives, the window's waker, set once the window opens, and what a package serves beside them, set by the loop before it starts it, and its start.
Fields
exp jobs: Channel<|=| (&Workers) -> |=| (&var Ui)>exp done: Channel<|=| (&var Ui)>exp waker: Mutex<Waker>exp service: Option<*Service> = ::Noneexp starting: Channel<bool>
Functions
interface Servicesource
exp interface Service
What a package serves on a task of its own beside the app's workers, sharing its state with the loop: pkg::alloy::ui_app's requests, on their own tasks so that a slow download never holds a worker.
Required functions
fn serve(self: &, workers: &Workers);Serves until the app ends, once started.
fn end(self: &);The app is ending: what
servewaits on ends.
fn Workers::runsource
exp fn Workers::run<R>(body: &|&| (&Workers) -> R) -> R
Runs the body with an app's worker tasks beside it (four, and one
for a service), for a HUD in the engine's own loop (with_workers),
and gives what the body gives once the workers end: those running
work with it, a service with what it serves.