Expand description
day-piece-settings: the settings and About surface every Day app shares (docs/settings.md).
Three layers, all toolkit-neutral:
- Values.
Pref<T>: a typed, persisted, reactive setting declared once as a static. Reads are signals the app can watch; writes land in theStore(the platform’s own preferences store through day-part-prefs unless the app installs another). - Declaration.
Preferencesholds anAboutand theGroups ofSections of rows (rows::toggle,rows::choice,rows::slider,rows::stepper,rows::text,rows::action,rows::link,rows::navigate,rows::info,rows::note,rows::custom). Groups carry a localized title, an icon and a route id. Other crates contribute groups through aProvider. - Presentation.
Preferences::installregisters the Preferences window (desktop) or the navigation presentation (mobile: an About header, then the groups as a list that pushes one page per group), the About window, the Settings…/About/Check for Updates… menu items, and thesettings/<group>string routes. The pieces are composed from ordinary Day pieces on every backend; a toolkit feature adds native rows and panels where the platform has a stronger idiom.
ⓘ
// root(), after res::locales::install():
let prefs = day_piece_settings::Preferences::new()
.about(About::from_manifest().link(res::str::about_website(), "https://daybrite.dev"))
.group(day_piece_settings::general_group(res::locales::ALL))
.install();
// … and in the nav, for the platforms with no menu bar:
nav(section)
.items(prefs.nav_item(Section::Settings))
.destination(move |_: &Section| prefs.page())Modules§
- prelude
- What an app’s
root()and settings module import: the declaration types, the handle, the row constructors as a module, and the General group. - rows
- The row constructors (docs/settings.md). Use them qualified (
rows::toggle(..)): several share a name with a piece in the Day prelude.
Macros§
- pref_
enum - Declare an enum that round-trips through the store under short stable tags:
- provider
- Declare a provider static and register it (docs/settings.md):
Structs§
- About
- The app’s About content (docs/settings.md): a window on the desktops, the toolkit’s About dialog on GTK, a page inside Settings on mobile and Windows.
- Group
- One group of settings (docs/settings.md): a page on desktop (a toolbar tab, a dialog page, a sidebar entry) and a row of the mobile root list that pushes the page.
- Memory
Store - An in-process store that forgets everything at exit: tests, and deterministic script runs.
- Native
Store - The platform store through day-part-prefs (docs/prefs.md): NSUserDefaults, SharedPreferences, a per-app config file, localStorage.
- Pref
- A typed, persisted, reactive setting (docs/settings.md), declared once as a static:
- Preferences
- The settings declaration (docs/settings.md). Build it in
root()and callSelf::install. - Prefs
- The handle
Preferences::installreturns:Copy, so pages and the nav take it by value. - Provider
- A settings group contributed by another crate (docs/settings.md): the self-updater’s
Updates group is the first. Declared as a static through
provider!, which registers it in the link-time slice on native targets; on wasm (no linkme) and anywhere an explicit order matters,register_provider/Preferences::providername it directly. - Row
- One row of a section (docs/settings.md), built by the row constructors.
- Section
- A titled card of rows inside a group.
Enums§
- Appearance
- The app’s appearance override: the platform’s light or dark look, or whatever the system says (the default).
- Choice
Style - How a
rows::choicerow presents its options. - Group
Icon - A group’s icon: a bundled vector/image (
res::vectors::prefs_weather) or a standard glyph. - Presentation
- How the surface is presented; chosen per toolkit by default.
- Providers
- Which providers
Preferences::installcollects. - Settings
Route - The route type of the navigation presentation’s stack: pushed pages are groups, About, a row’s sub-page or a choice list.
Constants§
- NAV_KEY
- The nav item key an app conventionally mounts the surface under;
open()tries it first.
Statics§
- APPEARANCE
- The appearance pref every app shares, key
day.appearance.DAY_THEMEwins at launch. - LANGUAGE
- The language pref every app shares, key
day.locale: a locale tag, or empty for the system language.DAY_LOCALEwins at launch. - PROVIDERS
- Every statically registered
Provider(native targets; empty on wasm).
Traits§
- Pref
Value - A value a
Prefcan hold: encoded to one string in the store and back. Implemented for the plain scalars and strings; enums get it frompref_enum!. - Store
- Where values live (docs/settings.md). The default,
NativeStore, is day-part-prefs: the platform’s own preferences facility. An app installs another withinstall_storebefore building the settings UI; tests useMemoryStore.
Functions§
- appearance_
row - The Light / Dark / System row alone (id
theme-picker), for apps composing their own group. - general_
group - The “General” group every app starts with: Appearance (
theme-picker, present where the toolkit honors a runtime override) and Language (language-picker: System plus every bundled locale under its own name).localesis the app’s generatedres::locales::ALL. - group_
page_ of - One installed group’s page alone (see
Prefs::group_page). - install_
store - Replace the store every
Prefreads and writes. Call before any pref is read (before building the settings UI); signals already seeded keep their values. - language_
row - The language row alone (id
language-picker). - open
- Open-or-focus the installed settings surface (see
Prefs::open). - open_at
- Open the surface at a group route (
"updates","updates/check"). - page
- The installed navigation presentation as a piece (see
Prefs::page), for code that has noPrefshandle at hand. An empty piece beforePreferences::install. - persistence_
failures - The keys whose last write the store refused (
Store::set/removereturned false), in key order; empty while every write has landed. A failed write is also logged. The in-memory value stays what the user chose for this run; it will not survive a relaunch, which is what an app watching this signal can say. A key leaves the list when its own next write lands; another key’s success never clears it. - register_
provider - Register a provider at run time (before
Preferences::install): the wasm path, and the explicit alternative to the link-time slice anywhere. - wire_
general - Apply the persisted appearance and language at boot and keep applying every later change
(docs/settings.md). Runs once per process;
general_groupcalls it, and an app that uses the prefs without the group calls it itself. Honors the env-wins rule: underDAY_THEME/DAY_LOCALEthe stored value is not applied at boot (the launch override stays deterministic), while live changes always apply.
Type Aliases§
- Locale
Table - A
(tag, autonym)locale table, the shape of a generatedres::locales::ALL.