Skip to main content

ThemeManager

Struct ThemeManager 

Source
pub struct ThemeManager { /* private fields */ }
Expand description

The theme registry and the active selection, installed as a gpui global alongside Theme itself. See the module docs.

Implementations§

Source§

impl ThemeManager

Source

pub fn new() -> Self

A registry holding just light and dark, following the system.

Those two ids are the light/dark pair ThemeChoice::System resolves through, so an app with its own two-theme identity can re-register them (same ids, its own themes and names) and get the follow behaviour for free. To use a different pair, see ThemeManager::pair.

Source

pub fn with_presets(self) -> Self

Add the six prebuilt presets (see PRESET_NAMES).

Source

pub fn with(self, entry: ThemeEntry) -> Self

Add one theme (builder form of ThemeManager::register).

Source

pub fn with_dir(self, dir: impl AsRef<Path>) -> Self

Load a directory of *.json theme files, ignoring the ones that fail. Use ThemeManager::load_dir when you want to report them.

Source

pub fn choice(self, choice: ThemeChoice) -> Self

Set the choice (builder form of ThemeManager::set_choice).

Source

pub fn pair( self, light: impl Into<SharedString>, dark: impl Into<SharedString>, ) -> Self

Point ThemeChoice::System at a different pair of registered themes.

Source

pub fn register(&mut self, entry: ThemeEntry)

Add a theme, replacing any entry with the same id.

Source

pub fn register_json( &mut self, id: impl Into<SharedString>, source: &str, ) -> Result<(), ThemeJsonError>

Register a theme from JSON the host already has in hand — an include_str!, a downloaded file, a string from its own config.

Source

pub fn load_dir(&mut self, dir: impl AsRef<Path>) -> Vec<ThemeLoadError>

Load every *.json file in dir as a theme, keyed by file stem, and return the files that failed. A missing directory is not an error — apps point this at a folder the user may never create.

Source

pub fn entries(&self) -> &[ThemeEntry]

Every registered theme, in registration order.

Source

pub fn entry(&self, id: &str) -> Option<&ThemeEntry>

Source

pub fn selection(&self) -> &ThemeChoice

The active choice. Persist it with to_string().

Source

pub fn system_scheme(&self) -> ColorScheme

The last OS appearance a watched window reported.

Source

pub fn resolved(&self) -> &ThemeEntry

The entry the current choice resolves to. Falls back to the light/dark pair, then to the first entry, so a stale id in a config file degrades to a sane theme instead of a panic.

Source

pub fn resolved_id(&self) -> &SharedString

The id of the theme currently in use.

Source

pub fn install(self, cx: &mut App)

Install as the global and apply the resolved theme.

Source

pub fn apply(cx: &mut App)

Write the resolved theme into the Theme global and redraw. Every mutator below ends here; call it directly after editing the manager through cx.global_mut::<ThemeManager>().

Source

pub fn select(cx: &mut App, id: impl Into<SharedString>) -> bool

Wear one registered theme. Unknown ids are ignored (and reported as false) so a picker can’t strand the app on a theme that isn’t there.

Source

pub fn follow_system(cx: &mut App)

Follow the OS appearance again.

Source

pub fn set_choice(cx: &mut App, choice: ThemeChoice)

Set the choice and apply it.

Source

pub fn toggle(cx: &mut App)

Swap to the light/dark counterpart of what is showing — what a light/dark toggle button does. Leaves ThemeChoice::System: an explicit toggle is an explicit choice.

Source

pub fn set_system_scheme(cx: &mut App, scheme: ColorScheme)

Record the OS appearance, restyling if the choice follows it. Usually driven by ThemeManager::watch; call it directly when the host learns the appearance some other way.

Source

pub fn watch(window: &mut Window, cx: &mut App)

Track a window’s appearance, so ThemeChoice::System follows the OS. Call once per window, from the window’s init. The subscription is held by the manager global, which outlives every window.

Trait Implementations§

Source§

impl Debug for ThemeManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ThemeManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Global for ThemeManager

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

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

Convert &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)

Convert &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> 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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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