pub struct SystemTheme {
pub name: String,
pub is_dark: bool,
pub light: ResolvedThemeVariant,
pub dark: ResolvedThemeVariant,
pub preset: String,
/* private fields */
}Expand description
Result of the OS-first pipeline. Holds both resolved variants.
Produced by SystemTheme::from_system() and SystemTheme::from_system_async().
Both light and dark are always populated: the OS-active variant
comes from the reader + preset + resolve, the inactive variant
comes from the preset + resolve.
Fields§
§name: StringTheme name (from reader or preset).
is_dark: boolWhether the OS is currently in dark mode.
light: ResolvedThemeVariantResolved light variant (always populated).
dark: ResolvedThemeVariantResolved dark variant (always populated).
preset: StringThe platform preset used (e.g., “kde-breeze”, “adwaita”, “macos-sonoma”).
Implementations§
Source§impl SystemTheme
impl SystemTheme
Sourcepub fn active(&self) -> &ResolvedThemeVariant
pub fn active(&self) -> &ResolvedThemeVariant
Returns the OS-active resolved variant.
If is_dark is true, returns &self.dark; otherwise &self.light.
Sourcepub fn pick(&self, is_dark: bool) -> &ResolvedThemeVariant
pub fn pick(&self, is_dark: bool) -> &ResolvedThemeVariant
Pick a resolved variant by explicit preference.
pick(true) returns &self.dark, pick(false) returns &self.light.
Sourcepub fn with_overlay(&self, overlay: &ThemeSpec) -> Result<Self>
pub fn with_overlay(&self, overlay: &ThemeSpec) -> Result<Self>
Apply an app-level TOML overlay and re-resolve.
Merges the overlay onto the pre-resolve ThemeVariant (not the
already-resolved ResolvedThemeVariant) so that changed source fields
propagate correctly through resolve(). For example, changing
defaults.accent in the overlay will cause button.primary_background,
checkbox.checked_background, slider.fill, etc. to be re-derived from
the new accent color.
§Examples
let system = native_theme::SystemTheme::from_system().unwrap();
let overlay = native_theme::ThemeSpec::from_toml(r##"
[light.defaults]
accent = "#ff6600"
[dark.defaults]
accent = "#ff6600"
"##).unwrap();
let customized = system.with_overlay(&overlay).unwrap();
// customized.active().defaults.accent is now #ff6600
// and all accent-derived fields are updatedSourcepub fn with_overlay_toml(&self, toml: &str) -> Result<Self>
pub fn with_overlay_toml(&self, toml: &str) -> Result<Self>
Apply an app overlay from a TOML string.
Parses the TOML as a ThemeSpec and calls with_overlay.
Sourcepub fn from_system() -> Result<Self>
pub fn from_system() -> Result<Self>
Load the OS theme synchronously.
Detects the platform and desktop environment, reads the current theme
settings, merges with a platform preset, and returns a fully resolved
SystemTheme with both light and dark variants.
The return value goes through the full pipeline: reader output →
resolve → validate → SystemTheme with both light and dark
ResolvedThemeVariant variants.
§Platform Behavior
- macOS: Calls
from_macos()when themacosfeature is enabled. Reads both light and dark variants via NSAppearance, merges withmacos-sonomapreset. - Linux (KDE): Calls
from_kde()whenXDG_CURRENT_DESKTOPcontains “KDE” and thekdefeature is enabled, merges withkde-breezepreset. - Linux (other): Uses the
adwaitapreset. For live GNOME portal data, usefrom_system_async()(requiresportal-tokioorportal-async-iofeature). - Windows: Calls
from_windows()when thewindowsfeature is enabled, merges withwindows-11preset. - Other platforms: Returns
Error::Unsupported.
§Errors
Error::Unsupportedif the platform has no reader or the required feature is not enabled.Error::Unavailableif the platform reader cannot access theme data.
§Examples
let system = native_theme::SystemTheme::from_system().unwrap();
let active = system.active();Sourcepub async fn from_system_async() -> Result<Self>
pub async fn from_system_async() -> Result<Self>
Async version of from_system() that uses D-Bus
portal backend detection to improve desktop environment heuristics on
Linux.
When XDG_CURRENT_DESKTOP is unset or unrecognized, queries the
D-Bus session bus for portal backend activatable names to determine
whether KDE or GNOME portal is running, then dispatches to the
appropriate reader.
Returns a SystemTheme with both resolved light and dark variants,
same as from_system().
On non-Linux platforms, behaves identically to
from_system().
Trait Implementations§
Source§impl Clone for SystemTheme
impl Clone for SystemTheme
Source§fn clone(&self) -> SystemTheme
fn clone(&self) -> SystemTheme
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more