Expand description
Day — the umbrella crate apps depend on. One backend feature per binary (§3.2).
Modules§
- lifecycle
- App-lifecycle support for the backend compiled into THIS binary (docs/lifecycle.md).
- prefs
- Persistent settings (docs/prefs.md): a small key/value string store backed by each platform’s
native facility —
NSUserDefaultson Apple,SharedPreferenceson Android, a file store elsewhere.day::prefs::{get, set, remove, contains}, plusbindto persist aSignalandinstall_nav_storeto make.restore(key)navigation survive a relaunch (docs/navigation.md). - prelude
- reactive
- The reactive core, whole (docs/async.md):
day::reactive::{Resource, Load}for async data loading — namespaced because the prelude’sResourceis the ASSET handle above, a different type that predates the async one. - record
- dayscript recording (docs/dayscript.md “Recording”, DESIGN §14.6): install a recorder that
captures the user’s taps, edits, selections, and navigation into a replayable dayscript.
day::record::{start, start_into, start_to_file, stop, is_recording, recording_signal, script, steps, save, clear, exclude_prefix}. A recorder also arms headlessly fromday launch --record <file>(theDAY_RECORDenv, honored insideday_script::init). What it records is an ordinary dayscript, so it replays cross-toolkit throughplay_scriptorday launch -p <target> --script <file>.
Macros§
- android_
main - Expands to the three JNI exports
dev.daybrite.day.bridge.DayBridge’s natives resolve against in the app cdylib (nativeStart/nativeOnEvent/nativeRunPosted), wired to the given root piece. - arkui_
main - Expands to the
day_arkui_startC export the HarmonyOS ArkUI shim’sstart(...)NAPI wrapper calls (from ArkTS:import native from 'libday_arkui.so'; native.start(nodeContent, w, h, density)). It mounts the app’srootpiece into the ArkTSNodeContentand runs the loop. - ios_
main - Expands to the
day_mainC export the iOS Runner’smain.swiftcalls (@_silgen_name("day_main")). The optional title is currently unused on iOS (the window fills the screen bounds); accepted for future window-scene use. - require_
lifecycle - Compile-time assert that the backend in this binary delivers
$phase, else a build error. Use it to make a hard dependency on a platform-specific phase explicit:day::require_lifecycle!(day::Lifecycle::DidEnterBackground);fails to compile on desktop. For soft handling, guard withlifecycle::supported/lifecycle_supportedinstead. - routes
- Define a plain routes enum and its
Routeimpl in one shot: - web_
main - Expands to the
day_dom_mainC export the web host’sshim.jscalls once the wasm module is instantiated (wasm.day_dom_main()at the end ofstart()incrates/day-cli/resources/web/shim.js).
Structs§
- AnyPiece
- Type-erased piece for heterogeneous branches and dynamic construction.
- Asset
Name - The bundled-data name that
resourceresolves by (the full file name, extension included). - BuildCx
- Font
Family - The family name of a bundled custom font, feeding
Font::custom. Holds a&'static str(soFontstaysCopy); generatedres::fonts::…constants supply it. The untypedFont::Custom(&'static str, f64)variant remains the escape hatch for a family known another way. - Image
Name - The bundled-image name that
imagecallers resolve by (the file stem). - Localized
Text - A localized text source:
label(tr("greeting").arg("name", name))(§12.2). - 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. - RNode
- Realized-node key.
NodeId(the spec-boundary id) is its FFI encoding. - Resource
- A handle to a bundled resource’s bytes with efficient random read-only access.
- Task
Handle - A handle to a spawned
task.Copyand!Send(the executor is thread-local). - Vector
Name - The bundled-vector name that
vectorcallers resolve by (docs/vectors.md): the stem of aresource/vectors/SVG (or.symbolsetbundle). Vectors and images share one per-backend resolution namespace — staging guarantees every vector name resolves as whatever form that backend loads natively (a VectorDrawable, a catalog entry, a rasterized PNG). - Window
Handle - A live secondary window (docs/windows.md). Cheap to clone; inert after close.
- Window
Options
Enums§
- Lifecycle
- An app-lifecycle phase (docs/lifecycle.md). Each backend maps these onto its OS’s native app /
activity delegate. Some phases only exist on some platforms — a mobile app truly enters the
background and can be low on memory, a desktop app essentially cannot — so
Lifecycle::is_universalmarks the ones every backend delivers, andToolkit::supports_lifecyclereports per-backend truth. - Window
Kind - What a secondary window IS, so backends can apply platform conventions (docs/windows.md).
Traits§
- IntoF
Arg - Disjoint-marker conversion for
.argvalues (the same E0119 dodge asIntoText). - Into
NumberF Arg - Marker for
IntoFArgvalues that carry a number — required for a Fluent variable used as a plural /selectselector, where CLDR plural rules select on a number (so a string can’t be passed there by mistake). Implemented for the numericIntoFArgtypes only (i64,f64, and theirSignals); the generatedres::str::<key>(…)functions (§18.5) type such parameters asimpl IntoNumberFArginstead ofimpl IntoFArg. - Piece
- A UI description consumed once (§5.2). Returns the root realized node it created.
- Piece
Seq - Children of a container: a tuple of pieces (the floem
ViewTuplepattern — implemented ONLY for tuples,(), andPieceVec, never via a blanket, to stay coherent).
Functions§
- app_
temp_ dir - An app-writable scratch directory. The OS temp dir is NOT app-writable on every target
(Android reports
getCacheDir()), so a backend records the right location at startup and this is how an app asks for it. For derived files an app can rebuild: rendered documents, thumbnails, export staging. An app-writable scratch directory: the backend-supplied one, elsestd::env::temp_dir(). Used by the file-save flow (docs/files.md) to stage bytes before the native save picker. - compare
- Compare two strings in the CURRENT locale’s collation order. Reads the locale signal (tracked), so a sort inside a reactive closure re-runs when the locale switches.
- compare_
in - Compare two strings in
locale’s collation order (untracked; accepts-u-co-extensions, e.g."zh-u-co-stroke"). Falls back to code-point order if the locale has no collation data. - dark_
mode - Whether the platform is rendering in dark appearance (see
Toolkit::dark_mode): the branch apps take when painting custom OPAQUE surfaces so fills track the theme that the default text colors already follow. - env
- An app-environment value, portably: the process environment on native targets, the page
URL’s query string on web-dom (where a browser sandbox has no process environment —
day launch --env K=Vforwards each pair as a query parameter, docs/web.md). Prefer this overstd::env::varfor anything a--envflag should be able to set on every target. - focused_
window - The most recently focused open secondary window, if any.
None⇒ the primary window is key (or no secondary window exists). - install_
locales - Register the app’s locales (see
day_l10n::install) and fix the layout direction from the locale that actually resolved (docs/localization): an RTL locale (Arabic, Hebrew, …) mirrors every horizontal placement and flips the native toolkit’s direction. Direction is resolved once, before the first layout — runtimeset_localeswitches strings but not direction. - invalidate_
size - Tell layout that a node’s intrinsic size may have changed. For tweaks (docs/tweaks.md): after a native call that alters a widget’s preferred size (fonts, tick marks, bezel styles), the measure cache along the node’s path must be invalidated — Day can’t see native mutations it didn’t make. Relayout runs at the next turn boundary as usual. No-op on a disposed node.
- launch
- launch_
external - Launch through an EXTERNAL toolkit’s backend (docs/extending.md “External toolkits”) — the
cfg-free counterpart of the feature-gated
launchentries below, for platform-toolkit pairs registered via[package.metadata.day.toolkit]. Feature-independent on purpose:day build -p <external>compiles the app with only the external toolkit’s own feature, so none of the launchers below exist in that build. Starts the dayscript engine exactly as they do — which is what keepsday launch --script,day drive, and the session registry working on a backend this repository has never heard of. - lifecycle_
supported - Does the running backend deliver
phase? Use this to guard registration at runtime:if day::lifecycle_supported(Lifecycle::DidEnterBackground) { on_lifecycle(...) }. - locale
- The current locale (a tracked read inside bindings).
- matches_
search matches_search_inagainst the CURRENT locale. Reads the locale signal (tracked), so a filtered list inside a reactive closure re-filters when the language changes — the same contractcrate::comparehas.- matches_
search_ in - Does
textmatchqueryunderlocale’s rules? (untracked — pass the locale explicitly). - on_
lifecycle - Register
fto run whenever the app reachesphase. Handlers run in registration order, in a reactive batch (signal writes coalesce into one UI update). Register early — beforelaunch, or at the top of the root builder — soWillLaunch/DidLaunchhandlers are in place when they fire. - open_
preferences - Open-or-focus the preferences surface (docs/windows.md): a
WindowKind::Preferencessingleton window on desktop, the cover fallback elsewhere — one call for menu items and toolbar gears alike.false= no preferences piece is registered (logged). - open_
window - Open a secondary window (docs/windows.md).
keynames the LOGICAL window: when a window with this key is already open it is focused and returned instead of duplicated (the preferences pattern);Nonealways opens a new one. Where the toolkit cannot open windows (Cap::MultiWindow=Unsupported— probe it to adapt chrome) the content presents as a fullscreen cover in the primary window instead, closable the same way. - play_
script - Replay a dayscript against the running app, in-process (docs/dayscript.md “Recording”): parse
yamland run each step through the embedded engine, on the main thread between flushes — the same executorday launch --scriptdrives. Returns an error while a recording is live (a replay must not record itself) and on web (no background thread — drive the page over the WebSocket transport there). Seerecord. - register_
new_ window - Register the builder behind File ▸ New Window and the macOS tab-bar “+” (docs/windows.md):
each call opens another
WindowKind::Normalwindow. Amenu_role(MenuRole::NewWindow)item lowers to this action; without a registration it lowers disabled. - register_
preferences - Declare the app’s preferences piece (docs/windows.md) — once, in
root(), ideally beforeapp_menu. Enables the desktop Preferences window (singleton, primary+,), the auto Settings…/Preferences menu item, andopen_preferenceseverywhere (cover fallback where the toolkit cannot open windows). The window titles itself withoptions.title; useregister_preferences_withto localize it or change the size. - register_
preferences_ with register_preferenceswith explicit window options (localized title, size).- resource
- Open a bundled resource by name for efficient random read-only access.
- safe_
area - The window’s safe-area insets, in points. Zero on every backend that clamps Day’s root to
the safe area natively (the default everywhere); nonzero only where a backend runs the root
edge-to-edge — today day-android’s opt-in immersive mode (docs/layout.md, the android
platform page). Compose it yourself where a background should run under the system bars:
paint the background unpadded, pad the content by these insets. The read is tracked, but
layout attributes like
.paddingcapture the value at build time — a mid-run inset change (rotation) does not re-pad already-built pages. - set_
appearance - Override the app’s appearance:
Some(true)dark,Some(false)light,Nonefollow the system again. On backends reportingCap::Appearancethe native widgets restyle in place anddark_modeanswers the override; app-painted surfaces pick it up on their next rebuild. Other backends ignore the call — probe before offering a theme picker. - sleep
- Resolve after (at least)
msmilliseconds, on the UI thread — the portable delay forday::taskflows (docs/async.md). RidesPlatform::post_delayed, so it works on single-threaded hosts (web) wherestd::thread::sleep+Settercannot. - sort_
localized - Sort a slice in place in the CURRENT locale’s collation order (tracked, like
compare). - task
- Spawn an async flow onto Day’s main-loop executor. This is the opt-in seam for actions
that open modals or pickers:
button.action(|| day::task(async move { … .await … })). The future is polled once before this returns; the returned handle canTaskHandle::abortit and is freely discardable. - toolkit_
name - The display name of the toolkit compiled into THIS binary —
"AppKit","GTK","Qt","UIKit","Android","XAML","ArkUI","DOM"(or"Mock"). Handy for a window title that names its backend. - tr
- window_
by_ key - The open window registered under
key, if any (the dayscriptscreenshotstep’swindow:target resolves here).