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.
The reduced-motion preference is left as it is: GPUI does not surface
the OS prefers-reduced-motion setting and this crate reads no
environment variable, so an application that offers the preference
sets it explicitly with set_reduce_motion (before or after this
call) from its own settings.
Sourcepub fn get(cx: &App) -> &Self
pub fn get(cx: &App) -> &Self
Returns the global provider. Panics if init has not registered it.
Sourcepub fn active_id(&self) -> &SharedString
pub fn active_id(&self) -> &SharedString
The id of the active theme.
Sourcepub fn insert(&mut self, theme: Theme)
pub fn insert(&mut self, theme: Theme)
Registers a theme without activating it, replacing any theme with the same id. The active theme is unchanged (re-inserting the active id swaps its tokens in place).
Sourcepub fn theme_ids(&self) -> Vec<SharedString>
pub fn theme_ids(&self) -> Vec<SharedString>
The ids of every registered theme, sorted.
Sourcepub fn set_active(
&mut self,
id: impl Into<SharedString>,
) -> Result<(), UnknownThemeError>
pub fn set_active( &mut self, id: impl Into<SharedString>, ) -> Result<(), UnknownThemeError>
Activates a previously registered theme by id.
An id that was never registered is refused: the active theme stays as it was and the error carries the rejected 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