#[non_exhaustive]pub struct ThemeState { /* private fields */ }Available on crate features
state and storage only.Expand description
Requested and effective theme, follow-system, and reduced-motion preferences.
§Example
use crisol_core::state::ThemeState;
use crisol_core::theme::ThemeId;
let state = ThemeState::new(ThemeId::GithubDark, false);
assert_eq!(state.effective(), ThemeId::GithubDark);
assert!(state.is_dark());Implementations§
Source§impl ThemeState
impl ThemeState
Sourcepub fn new(requested: ThemeId, follow_system: bool) -> Self
pub fn new(requested: ThemeId, follow_system: bool) -> Self
State for requested, optionally following the desktop preference.
Sourcepub fn with_reduced_motion(
requested: ThemeId,
follow_system: bool,
reduced_motion: bool,
) -> Self
pub fn with_reduced_motion( requested: ThemeId, follow_system: bool, reduced_motion: bool, ) -> Self
Like Self::new, with reduced motion.
Sourcepub fn from_settings(
requested: &str,
follow_system: bool,
reduced_motion: bool,
) -> Self
pub fn from_settings( requested: &str, follow_system: bool, reduced_motion: bool, ) -> Self
Restore from stored settings; unknown identifiers fall back to GitHub Light.
Sourcepub fn follow_system(&self) -> bool
pub fn follow_system(&self) -> bool
Whether the light/dark base follows the desktop preference.
Sourcepub fn reduced_motion(&self) -> bool
pub fn reduced_motion(&self) -> bool
Whether animations are disabled.
Sourcepub fn set_accent(&mut self, accent: Option<Rgba>) -> bool
pub fn set_accent(&mut self, accent: Option<Rgba>) -> bool
Replace the brand accent.
Sourcepub fn set_custom(&mut self, custom: Option<Theme>) -> bool
pub fn set_custom(&mut self, custom: Option<Theme>) -> bool
Install or remove a custom token set.
Sourcepub fn set_requested(&mut self, requested: ThemeId) -> bool
pub fn set_requested(&mut self, requested: ThemeId) -> bool
Change the requested theme.
Sourcepub fn set_follow_system(&mut self, follow_system: bool) -> bool
pub fn set_follow_system(&mut self, follow_system: bool) -> bool
Turn follow-system on or off.
Sourcepub fn set_reduced_motion(&mut self, reduced_motion: bool) -> bool
pub fn set_reduced_motion(&mut self, reduced_motion: bool) -> bool
Turn reduced motion on or off.
Sourcepub fn resolve(&mut self, system_dark: bool) -> (ThemeId, bool)
pub fn resolve(&mut self, system_dark: bool) -> (ThemeId, bool)
Resolve the effective theme for the current desktop preference.
Returns the effective theme and whether it changed.
Sourcepub fn sync_system(&mut self, system_dark: bool) -> bool
pub fn sync_system(&mut self, system_dark: bool) -> bool
Re-resolve after the desktop preference changed.
Returns true when the effective theme changed.
Sourcepub fn theme_setting(&self) -> &'static str
pub fn theme_setting(&self) -> &'static str
The stored theme identifier.
Trait Implementations§
Source§impl Clone for ThemeState
impl Clone for ThemeState
impl Copy for ThemeState
Source§impl Debug for ThemeState
impl Debug for ThemeState
Source§impl Default for ThemeState
impl Default for ThemeState
Source§impl<'de> Deserialize<'de> for ThemeState
impl<'de> Deserialize<'de> for ThemeState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for ThemeState
Source§impl PartialEq for ThemeState
impl PartialEq for ThemeState
Source§impl Serialize for ThemeState
impl Serialize for ThemeState
impl StructuralPartialEq for ThemeState
Auto Trait Implementations§
impl Forget for ThemeState
impl Freeze for ThemeState
impl Move for ThemeState
impl RefUnwindSafe for ThemeState
impl Send for ThemeState
impl Sync for ThemeState
impl Unpin for ThemeState
impl UnsafeUnpin for ThemeState
impl UnwindSafe for ThemeState
Blanket Implementations§
impl<T> Allocation for T
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> ⓘ
Converts
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> ⓘ
Converts
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