Skip to main content

Crate day_piece_settings

Crate day_piece_settings 

Source
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 the Store (the platform’s own preferences store through day-part-prefs unless the app installs another).
  • Declaration. Preferences holds an About and the Groups of Sections 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 a Provider.
  • Presentation. Preferences::install registers 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 the settings/<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.
MemoryStore
An in-process store that forgets everything at exit: tests, and deterministic script runs.
NativeStore
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 call Self::install.
Prefs
The handle Preferences::install returns: 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::provider name 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).
ChoiceStyle
How a rows::choice row presents its options.
GroupIcon
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::install collects.
SettingsRoute
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_THEME wins at launch.
LANGUAGE
The language pref every app shares, key day.locale: a locale tag, or empty for the system language. DAY_LOCALE wins at launch.
PROVIDERS
Every statically registered Provider (native targets; empty on wasm).

Traits§

PrefValue
A value a Pref can hold: encoded to one string in the store and back. Implemented for the plain scalars and strings; enums get it from pref_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 with install_store before building the settings UI; tests use MemoryStore.

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). locales is the app’s generated res::locales::ALL.
group_page_of
One installed group’s page alone (see Prefs::group_page).
install_store
Replace the store every Pref reads 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 no Prefs handle at hand. An empty piece before Preferences::install.
persistence_failures
The keys whose last write the store refused (Store::set/remove returned 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_group calls it, and an app that uses the prefs without the group calls it itself. Honors the env-wins rule: under DAY_THEME/DAY_LOCALE the stored value is not applied at boot (the launch override stays deterministic), while live changes always apply.

Type Aliases§

LocaleTable
A (tag, autonym) locale table, the shape of a generated res::locales::ALL.