pub struct ThemeProvider { /* private fields */ }Expand description
Holds the active theme, any registered custom themes, and the opt-in “follow the OS appearance” mode.
The reduced-motion preference is deliberately not a field here. GPUI owns
that flag (App::reduce_motion) and its own Animation/spring elements read
it directly, so a copy on this global would be a second source of truth: a
consumer app writing a plain gpui::Animation, or any GPUI internal such as
animated-image playback, would keep animating after HeroGPUI was told to
stop. ActiveTheme::reduce_motion therefore reads GPUI’s flag and
set_reduce_motion writes it, so the two cannot disagree.
Implementations§
Source§impl ThemeProvider
impl ThemeProvider
Sourcepub fn init(cx: &mut App)
pub fn init(cx: &mut App)
Registers the provider with the default light theme.
Call this once before opening the first window. Rendering a themed component before initialization panics.
Sourcepub fn init_with(theme: Theme, cx: &mut App)
pub fn init_with(theme: Theme, cx: &mut App)
Registers the provider starting from an explicit theme.
Call this once before opening the first window. Rendering a themed component before initialization panics.
pub fn get(cx: &App) -> &Self
pub fn theme(&self) -> &Theme
pub fn active_id(&self) -> &SharedString
Sourcepub fn set_active(&mut self, id: impl Into<SharedString>)
pub fn set_active(&mut self, id: impl Into<SharedString>)
Activates a previously registered theme by id.
Sourcepub fn follows_system_appearance(&self) -> bool
pub fn follows_system_appearance(&self) -> bool
Whether the OS light/dark appearance is being followed — the state a three-way “Light / Dark / System” setting needs to render itself.
Trait Implementations§
impl Global for ThemeProvider
Auto Trait Implementations§
impl !RefUnwindSafe for ThemeProvider
impl !Send for ThemeProvider
impl !Sync for ThemeProvider
impl !UnwindSafe for ThemeProvider
impl Freeze for ThemeProvider
impl Unpin for ThemeProvider
impl UnsafeUnpin for ThemeProvider
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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