Expand description
day-pieces — the built-in piece library (DESIGN.md §5.3).
Every constructor is a plain function returning a piece value; builder methods configure;
build runs once. Dynamic attributes become seeded bindings writing sparse typed patches
through the thread-local tree.
The vocabulary is split across sibling modules (one logical group each) and re-exported here,
so the public API stays flat — day_pieces::button, day_pieces::stack, … — regardless of
which module a piece is defined in.
Re-exports§
pub use render::fill_measure;pub use linkme;
Modules§
- prelude
- render
- External-piece registration surface (DESIGN.md §8.2). The
renderer!macro registers a piece’s per-toolkit native renderer into a backend’sRENDERERSslice with typedmake/update(the macro inserts the&dyn Anydowncast) and no hand-written linkme boilerplate.fill_measureis the shared “growing leaf” sizing, so pieces stop hand-rolling it per backend.
Macros§
- dom_
renderer - Register a piece’s web-dom renderer, whose registry is populated at RUNTIME.
- glue_
modules - Declare a satellite piece’s per-toolkit glue modules — the
#[cfg]/#[path]block every piece otherwise hand-writes (docs/extending.md §2). Each named toolkit expands to the house-convention module gate bindinglib-<toolkit>.rsnext to the invoking lib.rs: - renderer
- Register a piece’s per-toolkit native renderer into
$slice(a backend’sRENDERERS). - routes
- Define a plain routes enum and its
Routeimpl in one shot:
Structs§
- A11y
Builder - Alert
- A dialog / confirmation / action sheet. Buttons carry a typed payload
T;.present()awaits and returns the chosen button’s payload, orNoneon cancel/dismiss. - Back
Request - The deferred pop handed to a
Stack::on_backguard. Hold it, then callproceedto perform the back the guard consumed (the unsaved-changes → confirm → leave flow). - Button
- Column
- Confirm
- A yes/no confirmation. Resolves to
trueonly if the confirm button is chosen. - Cover
- Divider
- Drag
- Drag info delivered to a shape’s
.on_draghandler. - Draw
- FileUrl
- A cross-platform handle to a file the user chose in a native open/save picker.
- Filled
Button Style - A filled, rounded button style: a solid
colorbackground with a white label and comfortable padding, composed fromDecorate::padding/Decorate::background/Decorate::corner_radius. v1 is static (no pressed/hover feedback). - FnMark
- Focus
Bool Mark - Focus
Group Mark - Form
Section - One grouped form section (created by
section): an optional header above a rounded card whose background is the platform’s own theme-adaptive grouped-content material (SurfaceRole::SectionCard— quaternary fill on AppKit, libadwaita.card, Qtpalette(alternate-base), tertiary system fill on iOS, Material surface-container, the XAML card brush), so it follows light/dark mode with no app code. - Grid
- GridRow
- Image
- A bundled image, resolved by name through the backend’s native image pipeline (§18.3). Scales
with
ContentMode::Fitby default (never stretches); tune with.content_mode()/.fill()/.stretch(), and optionally constrain the frame with.aspect_ratio(w/h). - Item
Slot - A
Copyhandle to one keyed item’s state — the unifiedeach/listcontract (§5.4). - Label
- Link
- A tappable run of text that opens
urlin the platform’s default handler — the system browser forhttp/https, the mail client formailto:, and so on. This is Day’s analogue of SwiftUI’sLink. - List
- A native recycling list: the platform widget owns scrolling + cell reuse; Day builds each
visible row once and rebinds it (a slot-write into its
ItemSlot) as cells recycle. Shares theItemSlotrow contract witheach; migrating is a one-word change. - Menu
Entry - A menu entry under construction. Build a command with
menu_item, a nested submenu withsub_menu, a standard system command withmenu_role, and a divider withmenu_separator. Attach to a Piece via [Decorate::context_menu] or install app-wide viaapp_menu. - Native
Ref - A liveness-checked reference to a mounted piece’s realized node — the retained half of the
tweaks API (docs/tweaks.md). Capture one with
Decorate::native_ref, then reach the native widget later (from event handlers, timers) through a toolkit ext accessor.node/withyieldNonebefore mount and after the node’s subtree is disposed, so async races are safe no-ops. - NavItem
- One data-driven selector item, returned by
iteminside aSelector::itemsmapper. - Open
File - A native “open file” picker.
.await(or.present().await) resolves to the chosenFileUrl, orNoneif the user cancels. - Picker
- A native picker bound two-way to
selected. Style via.menu()/.segmented()/.inline(). - Progress
- A progress indicator: a determinate bar (from
progress) or an indeterminate spinner (fromspinner). See docs/progress.md. - Prompt
- A single-line text prompt. Resolves to
Some(text)on OK,Noneon cancel/dismiss. - Renderer
- A third-party piece’s per-toolkit implementation.
makereceives the concrete backend (public helper surface) and returns a native handle the backend then owns like any built-in. - Route
Path - A typed absolute route: segments built from
Routevalues plus query params.route(&Section::Stack).then(&Drill::Item { id: 42 }).param("hint", "linked")encodes to"stack/item-42?hint=linked"—RoutePath::navigateit, or hand it tonav_link_to. - Row
- Save
File - A native “save file” picker carrying the bytes to write.
.awaitresolves to the chosen destinationFileUrl, orNoneon cancel. - Scroll
- Selector
- A one-of-N selector whose active key is an app-owned signal (two-way, exactly like
Picker/Toggle). Deep links and dayscript address items by key (docs/navigation.md). - Shape
Piece - A shape piece — one data-oriented piece parameterised by
ShapeKind, rendered atop the canvas. - Signal
Mark - Slider
- Spacer
- Stack
- A push/pop navigation stack whose contents are an app-owned
Signal<Vec<K>>(the path above the root). Day reconciles the native stack to the path; the native back button writes the pop back into it (docs/navigation.md). - Static
Mark - Text
Area - A native multi-line text editor bound two-way to
text. Configure a prompt with.placeholder(_), the auto-growing height band with.min_lines(_)/.max_lines(_), and the native editor attributes with.editable(_)/.selectable(_)/.spellcheck(_)(each accepts a constant or a reactivebool, and updates live). A backend that can’t honor an attribute answers the matchingCap::Text{Editable,Selectable,SpellCheck}withSupport::Unsupported. - Text
Field - Text
Style - Canvas text styling (named fields per the API style rule, docs/api-style.md).
- Toggle
- Toolbar
Entry - A toolbar item under construction. Build a command with
toolbar_button, a two-state button withtoolbar_toggle, a pull-down withtoolbar_menu, a search field withtoolbar_search, and the gaps withtoolbar_space/toolbar_flexible_space. - Vector
- A bundled vector glyph, resolved by name through whatever form the backend loads natively
(§18.3: a VectorDrawable on Android, a catalog entry on Apple, an SVG on the web, a
build-rasterized PNG where the toolkit has no vector path). Distinct from
imageon purpose: only a typedVectorNameis accepted, and the modifiers are the vector-appropriate ones —tintrecolors a monochrome glyph where the backend can (template rendering on Apple, drawable tint on Android, pixel recolor on GTK; backends without a tint path draw the authored colors). - ZStack
- A z-stack: children are layered back-to-front (the first child sits at the bottom), all
sharing the container bounds and positioned by the stack’s
Alignment. The stack sizes to the UNION (max width/height) of its children — contrast [Decorate::overlay], which sizes to its content and treats the overlaid piece as a non-sizing annotation. Pure composition: it is the same native panel as [column]/row, so there is no per-backend work.
Enums§
- Back
Response - What a
Stack::on_backguard returns for one back-like event (a native back gesture/button, ornav_back). Programmatic path writes are NOT guarded — the guard is a policy on the user’s back affordance, matching Jetpack Compose’sBackHandler(docs/navigation.md). - Corner
- A corner radius: absolute points, or a 0..1 fraction of
min(width, height). - Drag
Phase - The phase of a drag gesture (docs/shapes.md).
- Fraction
Source - Gesture
Kind - A gesture a node wants delivered. Backends attach the matching native recognizer when day-core
calls
Toolkit::enable_gesture; the default is no gesture (recognizers cost, so opt-in). - HAlign
- Reactive
- A parameter that is either a constant or a reactive source.
get()is a tracked read, so anyReactiveused inside a canvas draw closure makes that shape re-record when the source changes. - Reorder
- A reorder guard’s verdict on a proposed row move (docs/list.md): consulted synchronously from the native drag’s validate hook, so the affordance (gap, insertion mark, forbidden cursor) reflects the answer while the user is still dragging.
- Selector
Style - How a
selectorpresents its one-of-N choice. - Shape
Kind - A shape’s geometry, resolved against the rect layout assigns it (frame-relative, SwiftUI-style).
- Text
Source - VAlign
- Vector
Weight - A vector glyph’s stroke weight (docs/vectors.md). Template-form sources (SF template SVGs,
.symbolsetbundles) carry true per-weight art; plain SVGs alias every weight to the same glyph, so.weight(…)degrades to Regular rather than to a missing asset.
Traits§
- Button
Style - A pluggable button appearance (the SwiftUI
ButtonStyleanalog). Pure composition — a style builds its body from existing pieces/decorators, so it needs no per-backend native code. Apply one withButton::style. - Decorate
- Into
Focus Binding - A focus-binding target for [
Decorate::focused] (docs/focus.md): either aSignal<bool>(one control) or a(Signal<Option<K>>, K)pair (one control of a group sharing a signal). The two-marker split is the same E0119 dodge asIntoText. - Into
Fraction - Disjoint-marker conversion (like
IntoText) soprogress(_)accepts a constantf64, aSignal<f64>, or a closure. Reuses the same marker types. - Into
Insets - Into
Reactive - Disjoint-marker conversion (like
IntoText): acceptsT,Signal<T>, orFn() -> T. - Into
Text - Disjoint-marker conversion (the coherent form of §12.2’s IntoText):
literals,
String,Signal<String>, and closures all convert, each under its own marker. - Modifier
- A one-shot, by-value view transform (the SwiftUI
ViewModifieranalog): wrap a piece into a new one. Pure composition — no per-backend work. A plainFnOnce(AnyPiece) -> AnyPiececlosure is aModifiertoo (the blanket impl below), so the common case needs no new type. Apply one withDecorate::modifier. - Route
- A typed route key — the compile-checked alternative to raw string keys.
- Signal
Rw
Functions§
- alert
- app_
menu - Install the application menu — the native menu bar on desktop, the app-bar overflow on Android, the
UIMenuBuilder main menu on iPadOS/Catalyst. Top-level entries are usually
sub_menu(...)s (the menu-bar menus). Call at startup or whenever the menu changes; it replaces any previous app menu. - app_
menu_ reactive app_menuthat re-lowers and re-installs whenever a locale-tracked read inside the builder changes —menu_rolelabels,res::strtitles, andday::trall read the locale signal, so a runtime language switch rebuilds the menu in the new language (docs/menus.md). Replacement drops the previous install’s action closures (context menus are unaffected). The binding lives in a root-owned scope: install once, at startup.- arc
- button
- canvas
- The drawing closure is a binding: signal reads re-record; layout size changes re-record (via FrameChanged); replay is equality-gated by DrawOp’s PartialEq (§4.2).
- capsule
- circle
- column
- confirm
- cover
- A fullscreen cover over
open:Some(r)presentsbuild(&r),Nonedismisses (docs/cover.md). Registers a string-route adapter, sonavigate("<key>")opens it andnav_back()closes it, andcurrent_route()reports the presented key. - current_
route - The FULL current route — every mounted surface’s contribution, outermost to innermost,
/-joined. Round-trips throughnavigate: persist it on exit,navigate(&saved)on launch (docs/navigation.md). - divider
- each
- Reactive keyed collection (§5.4): keyed diff, per-key child scopes, slot writes for surviving keys, debug key-uniqueness assertion.
- ellipse
- environment
- Read the nearest ambient
Tprovided by an enclosingwith_environment, orNoneif none is in scope. Call it while constructing or building a piece within that subtree. - form
- A settings-style form: a vertical run of
sections whoselabeledrows share one label column across the WHOLE form. - frame_
clock - A frame clock (§8.4): an invisible, zero-size piece that calls
tickevery animation frame with the wall-clock delta since the previous frame, for as long as it is mounted. Drop it into the tree (e.g. behind acanvasin azstack) to drive a game loop or self-driven animation: the tick mutates stateSignals, and acanvasreading them re-records that frame. - grid
- A SwiftUI-style eager grid (docs/grid.md): columns are inferred from
grid_rowchildren — a column is as wide as its widest cell, agrow_wcell makes its column share the leftover width evenly, and a non-row child becomes a full-width cell spanning every column.spacer()inside a row is an inert empty cell that still occupies its column (a grid has explicit gutters, so stack-style push-apart spacers don’t apply). Cells opt into spans and per-cell alignment with [Decorate::grid_span] / [Decorate::grid_align]. - grid_
row - One row of a
grid: each child is a cell, assigned to columns left to right. Outside a grid a row degrades gracefully to a plainrow. Rows are transparent carriers — the grid places their cells directly — so decorating agrid_rowitself is unsupported (decorate the cells, or the grid). - image
- item
- A selector item for a data-driven list:
item(room.id, room.name).icon(res::images::room)(docs/navigation.md). Used inside the.items(signal, |t| …)mapper; the page it selects is built by the selector’sSelector::destination. - label
- labeled
- A form row:
labelsits in the form-wide aligned label column (right-aligned, vertically centered),controlbeside it. Outside aformthe label column is just this row’s own label width. A control with.grow()stretches to the row’s remaining width. - line
- A stroked segment between two unit points of the frame:
line((0.16, 0.5), (0.84, 0.5)). - link
- Build a
Linkthat opensurlwhen tapped. - list
- Build a recycling list from a reactive items closure, a key function, and a row builder.
- menu_
item - A clickable command:
menu_item("Save").key("s").action(|| …). - menu_
role - A standard/system command (
MenuRole::Copy,MenuRole::Quit, …) rendered with the platform’s NATIVE item — correct label, default shortcut, focus-targeting, and automatic enable/disable — so default menu items (Edit ▸ Cut/Copy/Paste, the app’s Quit/About) work without re-implementation. - menu_
separator - A visual divider between items.
- nav_
back - Pop one navigation level. False = nothing to pop.
- nav_
link - A tappable link that navigates to
pathwhen pressed. - nav_
link_ to - A tappable link that navigates to a typed
RoutePathwhen pressed. - navigate
- Navigate to a route (docs/navigation.md).
- navigate_
to - Navigate to a single typed key, RELATIVE (innermost surface first) — the typed
navigate(&r.key()), percent-escaped. For absolute paths chain aroute. - open_
file - Start a native open-file picker (docs/files.md).
- picker
picker(["A", "B", "C"], choice).segmented()— options are fixed,selectedis the bound index.- polygon
- A polygon of unit points of the frame:
polygon([(0.5, 0.0), (1.0, 1.0), (0.0, 1.0)]). - progress
- A determinate progress bar.
fractionis the completed portion in0.0..=1.0; pass a constant, aSignal<f64>, or a closure and it tracks reactively (out-of-range values are clamped). - prompt
- rectangle
- SwiftUI-ergonomic sugar — all build the same
ShapePiece. - rounded_
rectangle - route
- Start a typed
RoutePathat the outermost segment. - route_
param - One query param of the most recent
navigate(None= not present). - route_
params - The query params of the most recent
navigate(?name=value&…) — read inside a destination builder. See docs/navigation.md for when params apply. - row
- save_
file - Start a native save-file picker for
data(docs/files.md). - scroll
- section
- A grouped card of form rows;
.title(…)adds the header. Works inside aform(shared label column) or standalone. - selector
- shape
- The unified constructor:
shape(ShapeKind::RoundedRectangle { corner: 12.0.into() }). - shape_
group - Flatten many shape descriptions into ONE canvas leaf — one native view no matter how many
shapes (docs/shapes.md §3.6). Shapes draw in order; reactive properties re-record the group.
Child gestures are not wired inside a group — put
.on_tapon the group viaDecorate. - shape_
group_ fn - Size-aware
shape_group: the closure derives the shapes from the laid-out size and re-runs onFrameChanged, exactly likecanvas— for geometry that depends on the final size (e.g. data mapped along the width). - slider
- spacer
- spinner
- An indeterminate, animated progress indicator (a spinner / busy bar) for work with no known extent.
- stack
- sub_
menu - A nested submenu:
sub_menu("File", vec![menu_item("New"), …]). - text_
area text_area(text)— a native multi-line editor whose contents mirrortextin both directions.- text_
field - toggle
- toolbar
- Install the toolbar on the window being built — the primary window at startup, and the new
window inside a
register_new_windowbuilder. Replaces any previous toolbar on that window; an emptyitemsremoves it. Add or remove an item by calling this again with a different list, or usetoolbar_reactiveto keep the list derived from state. - toolbar_
button - A push button:
toolbar_button("refresh", tr("refresh")).icon(Symbol::Refresh).action(…). - toolbar_
flexible_ space - A gap that absorbs the leftover width. Everything before the first one is packed to the leading edge and everything after it to the trailing edge, which is how each toolkit’s own packing (GTK’s start/end, XAML’s content/commands) is expressed in one ordered list.
- toolbar_
label - Static text in the bar — a status or a caption.
- toolbar_
menu - A button that drops a menu, built from the same entries
crate::app_menutakes. - toolbar_
reactive toolbarthat re-lowers and re-installs whenever a reactive read insidebuilderchanges — a locale switch, or a command list that depends on what is selected.- toolbar_
search - A native search field bound two-way to
query—NSSearchToolbarItem,GtkSearchEntry, a Qt searchQLineEdit, anAutoSuggestBox. Set the prompt with.placeholder(_). - toolbar_
separator - A divider, where the platform draws one (macOS toolbars have none — AppKit renders it as a fixed gap; docs/toolbars.md).
- toolbar_
space - A fixed gap.
- toolbar_
toggle - A two-state button bound to
on: the user flipping it writes the signal, and writing the signal restyles the button. - vector
- when
- Reactive conditional subtree. The anchor is a layout-transparent group; the active arm lives in its own child scope, disposed on switch (§4.3).
- with_
environment - Provide an ambient value
Ttocontentand its ENTIRE descendant subtree (the SwiftUI@Environment/.environment(_)analog, layered over day-reactive’s scope context).content— and any piece built within it — reads it back withenvironment. A thin, non-reactive wrapper:Tis a snapshot captured here; for a value that must react, provide aSignal<T>(or aMemo<T>) and read it reactively inside the subtree. - zstack
- Build a
ZStackfrom a tuple of children (or aPieceVec).