Skip to main content

ThemeProvider

Struct ThemeProvider 

Source
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

Source

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.

Source

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.

Source

pub fn get(cx: &App) -> &Self

Returns the global provider. Panics if init has not registered it.

Source

pub fn theme(&self) -> &Theme

The active theme.

Source

pub fn contains(&self, id: &str) -> bool

Whether a theme with this id has been registered.

Source

pub fn active_id(&self) -> &SharedString

The id of the active theme.

Source

pub fn register(&mut self, theme: Theme)

Registers and activates a custom theme.

Source

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).

Source

pub fn theme_ids(&self) -> Vec<SharedString>

The ids of every registered theme, sorted.

Source

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.

Source

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§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ReadGlobal for T
where T: Global,

Source§

fn global(cx: &App) -> &T

Returns the global instance of the implementing type. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UpdateGlobal for T
where T: Global,

Source§

fn update_global<C, F, R>(cx: &mut C, update: F) -> R
where C: BorrowAppContext, F: FnOnce(&mut T, &mut C) -> R,

Updates the global instance of the implementing type using the provided closure. Read more
Source§

fn set_global<C>(cx: &mut C, global: T)

Set the global instance of the implementing type.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more