ui_app

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):

**F5b as built** (2026-10-13):

**F5c as built** (2026-10-13):

**Background work as built** (2026-10-13, question 4):

**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"):

**F11c as built** (2026-10-15; decisions/F11.md, "Screens", questions 5A and 6B):

**F11e as built** (2026-10-15; decisions/F11.md, "Motion", questions 11A, 12A and 13A):

**F12a as built** (2026-10-15; decisions/F12.md, "Timers", questions 1A and 2A):

**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):

**Showcase answers as built** (2026-10-17; decisions/showcase.md, the questions samples/tickets raised, decided 2026-10-16):

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: f32
exp 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.0
exp max_width: f32 = UNBOUNDED
exp min_height: f32 = 0.0
exp 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.0
exp top: f32 = 0.0
exp end: f32 = 0.0
exp 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> = ::None
exp height: Option<f32> = ::None
exp min_width: f32 = 0.0
exp min_height: f32 = 0.0
exp max_width: f32 = UNBOUNDED
exp max_height: f32 = UNBOUNDED
exp 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

LeftToRight
RightToLeft

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

Start
Center
End
Stretch

type Justifysource

exp type Justify = enum

Where children go along a row or column with room left.

Variants

Start
Center
End
Between

type Themesource

exp type Theme = struct

Colors by role, and the scales widgets take their lengths from.

Fields

exp background: Color

under everything

exp surface: Color

cards, fields

exp text: Color
exp muted: Color

text of lesser importance

exp primary: Color
exp on_primary: Color

text over primary

exp neutral: Color

secondary buttons

exp border: Color
exp 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: f32

how much hovering lightens or darkens, 0 to 1

exp press: f32
exp 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: Color
exp radius: f32
exp spacing: f32
exp text_size: f32
exp 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

None
Text
Muted
Primary
OnPrimary
Neutral
Surface
Background
Border
Focus
Danger
Exact: 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: u32
exp 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: u32
exp 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: u32
exp 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: u32
exp generation: u32

Functions

type Changesource

exp type Change = enum

What a binding's new options change of an element.

Variants

Nothing
Paint
Layout

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 add adopts.

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, since its 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

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: Semantics
exp bounds: Rect

in the element's coordinates

exp focused: bool = false

holds 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: u32
exp action: Action

type Inputsource

exp type Input = enum

Input an element is given, at a point in its own coordinates.

Variants

Press: Point
Release: Point
Click: Point

a press and a release on the element

Moved: Point

the pointer moved while the element captured it by a press

Key: KeyEvent

to the focused element, then up its ancestors

Text: String
Preedit: Preedit
Focus: bool

the element took the focus, or lost it

Scroll: Point

the wheel or a touchpad, in logical pixels, to the element under the pointer, then up its ancestors

Action: Action

what 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: String

the clipboard's text, to the element that asked for it with ui.request_paste()

Part: PartRequest

what a screen reader asks of one of its parts

Hover: Point

the 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: Extent
exp theme: &Theme
exp hovered: bool
exp pressed: bool
exp hover: f32

how hovered and pressed it is, from 0 to 1, easing over the theme's short duration as the pointer comes and goes

exp press: f32
exp since: Duration

the time since its options last changed, or since it was made: what a widget moving its own drawing goes by (Widget::settling)

exp focused: bool
exp focus_ring: bool

focused from the keyboard, which shows the focus ring

exp marks: &Marks
exp images: &[StoredImage]
exp reduced: bool

the motion asked for is less

exp direction: LayoutDirection = LayoutDirection::LeftToRight

which 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> = ::None

a downward chevron's, made as a Select first lays out

exp previous: Option<Picture> = ::None

chevrons 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

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 = 0

what is made now belongs to

exp root: Option<u32> = ::None
exp theme: Theme = Theme::light()
exp fonts_changed: u32 = 0

counts changes to the fonts text is laid out with, for widgets keeping layouts (a calendar's names)

exp scene: Option<Scene> = ::None
exp viewport: Extent = Extent::zero()
exp scale: f32 = 1.0
exp pointer: Option<Point> = ::None
exp hovered: Option<u32> = ::None
exp focused: Option<u32> = ::None
exp focus_ring: bool = false
exp marks: Marks = Marks { .check = ::None }
exp handling: Option<u32> = ::None

the element given input now

exp workers: Option<&Workers> = ::None

the app's worker tasks, when it has them, and the work background queued for them

exp 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 = false

run by replay, which scripts what the window gives

exp access_on: bool = false

whether 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 = true
exp 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 clock made

exp wall: i64 = 0
exp 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> = ::None
exp 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 = false
exp moving: bool = false
exp waker: Waker = Waker::None

the 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

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

All

kept hidden, as it was left, until shown again

None

freed 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> = ::None

None: 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::Center
exp modal: bool = false

a scrim under it; the pointer and the keyboard reach nothing below, and Tab goes round within it

exp escape: bool = true

Escape closes it

exp outside: bool = true

a press outside it closes it, and goes no further

exp role: LayerRole = LayerRole::Plain

what a screen reader calls it

exp label: String = String::empty()

what a screen reader says of it

exp panel: bool = true

drawn 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 = true

takes the focus as it opens: not a tooltip's or the toasts'

exp passive: bool = false

takes no pointer and goes at any press: a tooltip's

exp tabbed: bool = false

Tab 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

Plain
Dialog
Alert
Menu
Tooltip

type Placesource

exp type Place = enum

Where a layer goes in the window.

Variants

Center

dialogs

Below: Element

under the element, start edges aligned (left, or right right to left); above it when there is no room below

Above: Element

over the element; below it when there is no room above

After: Element

beside it at its end, else its start: submenus

At: Point

where the pointer was, from the window's top left, reaching toward the end: a context menu

Corner: Corner

the toasts

type Cornersource

exp type Corner = enum

Variants

TopStart
TopEnd
BottomStart
BottomEnd

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 moving was 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; ring when 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 at origin in 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: f32
exp weight: u32
exp color: Color
exp heading: bool = false
exp 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::Standard
exp delay: Duration = Duration::from_milliseconds(0)
exp repeat: Repeat = Repeat::Once
exp essential: bool = false

still 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

Linear
Standard

cubic-bezier(0.2, 0, 0, 1): fast out, slow in

In
Out
InOut
Cubic: [f32 : 4]

CSS's cubic-bezier(x1, y1, x2, y2)

type Repeatsource

exp type Repeat = enum

Variants

Once
Times: u32
Forever
Alternate

back and forth, forever

type Durationssource

exp type Durations = struct

How long the built-in motion takes.

Fields

exp short: Duration

hovering, pressing, fades, popups and menus

exp medium: Duration

dialogs, toasts, views switched

exp long: Duration

screens

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 = true
exp slide: Point = ORIGIN

where it comes from and goes to, from its place, x toward the end: the left right to left

exp scale: f32 = 1.0

its size at the start: 0.96 grows to 1

exp reveal: bool = false

its room opens and closes (layout each frame)

exp moves: bool = false

a 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: String
exp size: Option<f32> = ::None

None: the theme's

exp weight: u32 = REGULAR
exp color: Ink = Ink::None

None: the theme's text color

exp heading: bool = false

at the theme's heading size when no size is given

exp align: TextAlign = TextAlign::Start
exp sizing: Sizing = Sizing {}
exp drawn: Option<Paint> = ::None

made 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

Start
Center
End

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: String
exp accessible: String = String::empty()

what a screen reader says, the label when empty

exp on_press: |=| (&var Ui) = (ui) {}
exp variant: ButtonVariant = ButtonVariant::Neutral
exp enabled: bool = true
exp padding: Padding = Padding::symmetric(14.0, 8.0)
exp sizing: Sizing = Sizing {}
exp laid: Option<*text::Layout> = ::None

Functions

type ButtonVariantsource

exp type ButtonVariant = enum

Variants

Neutral
Primary
Plain

text 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: bool
exp label: String = String::empty()
exp accessible: String = String::empty()
exp on_change: |=| (&var Ui, bool) = (ui, checked) {}
exp enabled: bool = true
exp 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; required a form needs it checked

exp required: bool = false
exp 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: f32
exp min: f32 = 0.0
exp max: f32 = 1.0
exp step: f32 = 0.0
exp 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 = true
exp 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 = false

a form needs it filled in, which screen readers say

exp multiline: bool = false
exp secret: bool = false

a 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 = true
exp 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.0
exp padding: Padding = Padding {}
exp align: Alignment = Alignment::Start
exp justify: Justify = Justify::Start
exp background: Ink = Ink::None
exp border: Ink = Ink::None
exp radius: f32 = 0.0
exp clip_radii: Option<Radii> = ::None

keeps its paint and its children within its rounded rectangle

exp sizing: Sizing = Sizing {}
exp on_context_menu: Option<|=| (&var Ui, Point)> = ::None

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.0
exp padding: Padding = Padding {}
exp align: Alignment = Alignment::Start
exp justify: Justify = Justify::Start
exp background: Ink = Ink::None
exp border: Ink = Ink::None
exp radius: f32 = 0.0
exp clip_radii: Option<Radii> = ::None

keeps its paint and its children within its rounded rectangle

exp sizing: Sizing = Sizing {}
exp on_context_menu: Option<|=| (&var Ui, Point)> = ::None

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::Start
exp background: Ink = Ink::None
exp border: Ink = Ink::None
exp radius: f32 = 0.0
exp clip_radii: Option<Radii> = ::None

keeps its paint and its children within its rounded rectangle

exp sizing: Sizing = Sizing {}
exp on_context_menu: Option<|=| (&var Ui, Point)> = ::None

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.0

between children on a line

exp line_gap: f32 = 0.0

between lines

exp align: Alignment = Alignment::Start

within a line's height

exp padding: Padding = Padding {}
exp background: Ink = Ink::None
exp border: Ink = Ink::None
exp radius: f32 = 0.0
exp clip_radii: Option<Radii> = ::None

keeps 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: f32
Content
Fraction: 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.0
exp row_gap: f32 = 0.0
exp align: Alignment = Alignment::Start

within a cell

exp padding: Padding = Padding {}
exp background: Ink = Ink::None
exp border: Ink = Ink::None
exp radius: f32 = 0.0
exp clip_radii: Option<Radii> = ::None

keeps 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 = false

scrolled sideways instead

exp sizing: Sizing = Sizing {}
exp length: f32 = 0.0

the scroll's own

Functions

type ImageIdsource

exp type ImageId = struct

A picture the Ui keeps, made from pixels with ui.image.

Fields

exp index: u32
exp generation: u32

an id of an image freed names none

type Fitsource

exp type Fit = enum

How a picture fills an image element of another shape.

Variants

Contain

all of it, centered

Cover

all of the element, clipped

Fill

stretched

type Imagesource

exp type Image : Widget = struct

A picture: its pixels' size in logical pixels unless sized.

Fields

exp image: ImageId
exp accessible: String = String::empty()

none: a screen reader passes over it

exp fit: Fit = Fit::Contain
exp mirrors: bool = false

drawn 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.0
exp fixed: bool = false
exp gap: f32 = 0.0
exp 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

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.0
exp wall: i64 = 0

nanoseconds since 1970 UTC

exp drawn: Drawn = Drawn::All

the 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

All
Last

those 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: AccessTree

the 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: String

the 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> = ::None
exp 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 serve waits 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.