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<SystemTheme, Error>
pub fn with_overlay(&self, overlay: &ThemeSpec) -> Result<SystemTheme, Error>
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<SystemTheme, Error>
pub fn with_overlay_toml(&self, toml: &str) -> Result<SystemTheme, Error>
Apply an app overlay from a TOML string.
Parses the TOML as a ThemeSpec and calls with_overlay.
Sourcepub fn from_system() -> Result<SystemTheme, Error>
pub fn from_system() -> Result<SystemTheme, Error>
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<SystemTheme, Error>
pub async fn from_system_async() -> Result<SystemTheme, Error>
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 moreSource§impl Debug for SystemTheme
impl Debug for SystemTheme
Source§impl SystemThemeExt for SystemTheme
impl SystemThemeExt for SystemTheme
Auto Trait Implementations§
impl Freeze for SystemTheme
impl RefUnwindSafe for SystemTheme
impl Send for SystemTheme
impl Sync for SystemTheme
impl Unpin for SystemTheme
impl UnsafeUnpin for SystemTheme
impl UnwindSafe for SystemTheme
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more