Skip to main content

Module widgets

Module widgets 

Source
Expand description

Starter widget set. Composite widgets should be plain functions over these.

A blanket impl<W: Widget> From<W> for Element is rejected by coherence, so each widget opts in next to its definition. Third-party widgets can do the same or use Element::new.

Structs§

Builder
Subtree built from the state an async source writes. The source starts on first build, restarts with fresh state when deps change, and is dropped (cancelled) with the widget.
Button
A tappable box built by button; see there.
Column
One table column: a header, a cell builder, and optionally a sort order.
Container
Flex box with optional rounded, bordered, shadowed background.
Dropdown
Picks one of labels: shows the selected one and lists them all on tap.
Expanded
Keys of the expanded nodes; view state, kept apart from the model.
Icon
A Shape drawn size px square in one color; a button with on_click.
Image
A bitmap built by image; see there.
Label
A run of text built by text; see there.
List
Virtualized vertical list: builds only the rows near the viewport, keeps the first visible row in place across rebuilds, and slides rows in, out and to new positions by key. Bound its height like a scroll’s.
OnBack
Runs f on Escape or the Android back button, unless an overlay takes it first, and keeps the app open. Leave it out where Back should exit.
OnKey
Runs f for keys pressed while no text field is focused, e.g. arrows and Enter from a keyboard, remote or D-pad. Topmost first: one that handles a key calls EventCx::stop to keep it from those below.
Overlay
Content floating above the rest of the tree, outside the layout flow.
Overlays
Overlays opened from handlers with Handle<Overlays>::show, each kept until its exit animation ends.
Page
A screen built by page.
Progress
A horizontal bar: one or more fractions filled over a track, or, with none, a segment sweeping across while the length of a wait is unknown.
Provide
Makes T available to every descendant through Scope::get, e.g. a handle to external state or a service a builder starts work from.
Radio
One option of a group: a ring before child, filled when selected. The whole row is the tap target.
Scroll
Scroll view; drag (touch, flings on release) or wheel. Children are clipped.
Seen
The notifier version a watch last built from.
Segmented
A row of options with a sliding indicator under selected.
Shown
One overlay shown through Overlays, passed to its builder.
Slider
Controlled horizontal slider over range: shows value, reports drags via on_change. Tapping the track jumps there.
Snapshot
What an async source has produced so far, and whether it has finished.
Spinner
A spiral for a wait of unknown length, thin outside and thick at the centre: it draws in from the outer end, then retracts the same way.
Stateful
Widget with local state S, kept across rebuilds by tree position or key. Handlers change it with cx.update(handle, |s| ..), which rebuilds the subtree.
TableSort
Column and direction a table is sorted by.
TextInput
Single-line controlled text field: shows value, reports edits via on_change.
Toggle
Controlled on/off switch: shows on, reports taps via on_change.

Traits§

Styled
Flex-layout modifiers shared by every widget that owns a Style.

Functions§

backdrop
Fills the whole screen with child, system bars included, under the layers that come after it, e.g. a map below translucent bars.
badge
label over the top right corner of child, such as a count; it takes no layout space. In a column it stretches like any child, so the corner is the column’s.
bottom_sheet
Modal panel along the bottom edge, full width.
button
Tappable box around child; on_click runs on a release inside it. Text in it morphs to bold while pressed.
chip
A small rounded label; restyle with .bg and .content.
choice_chip
A chip to tap, filled while selected; handle it with .on_click.
column
Lays children out top to bottom.
container
A single child with optional background, radius, border and shadow.
dialog
Modal card centered over the dimmed window.
drawer
Modal full-height panel along the left edge.
dropdown
A dropdown over labels showing labels[selected]; the menu floats below it.
future_builder
Rebuilds once future resolves. future gets the providers in scope.
heading
Bold text sized for a page title.
icon
shape as a 24 px icon.
icon_button
A borderless button showing shape: the icon shrinks while pressed and springs back past its size on release. Padded to a comfortable touch target.
image
bitmap stretched over the widget’s box. Its natural size is one logical pixel per bitmap pixel, and a box sized on one axis keeps the aspect ratio.
list
A virtualized list of model’s items, each drawn by row.
on_back
Handles Back for the screen it’s placed in; see OnBack.
on_key
Handles keys for the screen it’s placed in; see OnKey.
overlay
Covers the window; place child in it with align and justify.
overlays
Hosts content and the overlays its handlers show through the handle.
page
A screen: a header row (a back or menu button, then title) above the body, padded and filling its parent. title is any widget: a heading, or tabs.
popup
Floats child just below its parent, at least as wide.
progress
A bar filled to value in 0..=1; changes ease in.
provide
child with value in its scope; see Provide.
radio
One choice of a group: a ring, filled when selected, and a label.
row
Lays children out left to right.
screen
Covers the whole screen, system bars included; place child in it with align and justify, and pad it by [crate::insets] to keep its content clear of the bars.
scroll
Vertical scroll view: wheel, drag and fling, clipping child to its box. horizontal makes it scroll sideways instead.
segmented
Pill-shaped segmented button with equal-width options.
slider
Thumb on a track for a value in range; tap to jump, drag to follow.
snackbar
Short message at the bottom of the window for four seconds after it enters the tree. Shown through Overlays it waits for earlier ones to leave and is removed after; in a plain tree give it a new key to show it again.
spacer
Flexible empty space; spacer().grow(1.) pushes siblings apart.
spinner
A 24 px spinner.
stacked_progress
Several fractions in one bar, e.g. played over buffered, or tasks running at different speeds. Smaller values are drawn on top, so each shows.
stateful
Builds a subtree from local state S, kept across rebuilds.
stateful_with
stateful starting from init, e.g. a form over existing data. init runs once; give the element a new key to start over from other data.
stream_builder
Rebuilds from a stream’s items, collected into S (a Vec, String, …). stream gets the providers in scope.
table
model’s items as rows of columns, under a header that sorts by the sortable ones. Rows are a virtualized list; bound its height the same way.
tabs
Tab bar with an underline; the app shows the selected tab’s content. Each tab is as wide as its label, plus an equal share of the spare width; the selected label turns bold, morphing glyph by glyph.
text
A run of text, wrapped at spaces to the available width.
text_input
Single-line editable text showing value; edits arrive in on_change.
toggle
On/off switch; on_change gets the new value.
tooltip
Shows tip above child while the pointer is over it.
tree_view
model’s nodes as an indented, virtualized list; the arrow before a node with children expands or collapses it. row draws the rest of each line.
wait_bar
A bar for a wait of unknown length: a segment sweeps across, looping.
watch
Rebuilds build’s subtree each time notifier is notified, from any thread. Unlike a stream, it can’t run dry: restarts and several watchers of one notifier all keep working.