Expand description
Your friendly neighbourhood whale crate for reading various system-level
accessibility and UI preferences across platforms 🐋
The following preferences are supported:
AccentColor—The user’s current system wide accent color preference.ColorScheme—The user’s preference for either light or dark mode.Contrast—The user’s preferred contrast level.ReducedMotion—The user’s reduced motion preference.ReducedTransparency—The user’s reduced transparency preference.DoubleClickInterval—The maximum amount of time allowed between the first and second click.
Note that each preference has a corresponding feature flag. By turning off default features you will only “pay” for what you actually need.
§Example
The easiest way to get the preferences is to use the
Preferences::stream function to create a stream that is continually
updated when things change:
use mundy::{Preferences, Interest};
use futures_lite::StreamExt as _;
// Interest tells mundy which preferences it should monitor for you.
// use `Interest::All` if you're interested in all preferences.
let mut stream = Preferences::stream(Interest::AccentColor);
while let Some(preferences) = stream.next().await {
eprintln!("accent color: {:?}", preferences.accent_color);
}Alternatively, there’s Preferences::subscribe which
accepts a simple callback function instead.
§Errors
Most errors (except some fatal errors at startup) are simply ignored
and the default value for the preference (which is usually NoPreference) is returned.
It can be useful to turn on the log feature to find out what’s going on.
«I believe in a universe that doesn’t care and people who do. […] but this whale is pretty cool. ― Angus
Modules§
- feature_
flags doc - Feature Flags
- platform
- Contains platform-specific functionality.
Structs§
- Accent
Color accent-color - The user’s current system wide accent color preference.
- Double
Click Interval double-click-interval - The maximum amount of time that may occur between the first and second click event for it to count as double click.
- Interest
- Interest used when creating a stream or a subscription. They indicate which preferences should be retrieved and monitored.
- Preferences
- A collection of preferences retrieved by calling either
Preferences::streamorPreferences::subscribe. - Preferences
Stream - A stream that continually yields preferences
whenever they are changed. Created by
Preferences::stream(). - Srgba
accent-color - A color in the sRGB color space. Each component is in the range
[0, 1]. - Subscription
callback - A subscription for preferences created using
Preferences::subscribe(). Dropping the subscription will cancel it and clean up all associated resources.
Enums§
- Color
Scheme color-scheme - The user’s preference for either light or dark mode. This corresponds to the
prefers-color-schemeCSS media feature. - Contrast
contrast - The user’s preferred contrast level. This corresponds to the
prefers-contrastCSS media feature. - Reduced
Motion reduced-motion - The user prefers to have a minimal amount of motion. Especially motion that simulates the third dimension.
This corresponds to the
prefers-reduced-motionCSS media feature. - Reduced
Transparency reduced-transparency - Indicates that applications should not use transparent or semitransparent backgrounds.
This corresponds to the
prefers-reduced-transparencyCSS media feature.
Traits§
- Callback
Fn callback