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
impl ThemeManager
Sourcepub fn new() -> Self
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.
Sourcepub fn with_presets(self) -> Self
pub fn with_presets(self) -> Self
Add the six prebuilt presets (see PRESET_NAMES).
Sourcepub fn with(self, entry: ThemeEntry) -> Self
pub fn with(self, entry: ThemeEntry) -> Self
Add one theme (builder form of ThemeManager::register).
Sourcepub fn with_dir(self, dir: impl AsRef<Path>) -> Self
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.
Sourcepub fn choice(self, choice: ThemeChoice) -> Self
pub fn choice(self, choice: ThemeChoice) -> Self
Set the choice (builder form of ThemeManager::set_choice).
Sourcepub fn pair(
self,
light: impl Into<SharedString>,
dark: impl Into<SharedString>,
) -> Self
pub fn pair( self, light: impl Into<SharedString>, dark: impl Into<SharedString>, ) -> Self
Point ThemeChoice::System at a different pair of registered themes.
Sourcepub fn register(&mut self, entry: ThemeEntry)
pub fn register(&mut self, entry: ThemeEntry)
Add a theme, replacing any entry with the same id.
Sourcepub fn register_json(
&mut self,
id: impl Into<SharedString>,
source: &str,
) -> Result<(), ThemeJsonError>
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.
Sourcepub fn load_dir(&mut self, dir: impl AsRef<Path>) -> Vec<ThemeLoadError>
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.
Sourcepub fn entries(&self) -> &[ThemeEntry]
pub fn entries(&self) -> &[ThemeEntry]
Every registered theme, in registration order.
pub fn entry(&self, id: &str) -> Option<&ThemeEntry>
Sourcepub fn selection(&self) -> &ThemeChoice
pub fn selection(&self) -> &ThemeChoice
The active choice. Persist it with to_string().
Sourcepub fn system_scheme(&self) -> ColorScheme
pub fn system_scheme(&self) -> ColorScheme
The last OS appearance a watched window reported.
Sourcepub fn resolved(&self) -> &ThemeEntry
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.
Sourcepub fn resolved_id(&self) -> &SharedString
pub fn resolved_id(&self) -> &SharedString
The id of the theme currently in use.
Sourcepub fn apply(cx: &mut App)
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>().
Sourcepub fn select(cx: &mut App, id: impl Into<SharedString>) -> bool
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.
Sourcepub fn follow_system(cx: &mut App)
pub fn follow_system(cx: &mut App)
Follow the OS appearance again.
Sourcepub fn set_choice(cx: &mut App, choice: ThemeChoice)
pub fn set_choice(cx: &mut App, choice: ThemeChoice)
Set the choice and apply it.
Sourcepub fn toggle(cx: &mut App)
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.
Sourcepub fn set_system_scheme(cx: &mut App, scheme: ColorScheme)
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.
Sourcepub fn watch(window: &mut Window, cx: &mut App)
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
impl Debug for ThemeManager
Source§impl Default for ThemeManager
impl Default for ThemeManager
impl Global for ThemeManager
Auto Trait Implementations§
impl !RefUnwindSafe for ThemeManager
impl !Send for ThemeManager
impl !Sync for ThemeManager
impl !UnwindSafe for ThemeManager
impl Freeze for ThemeManager
impl Unpin for ThemeManager
impl UnsafeUnpin for ThemeManager
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ReadGlobal for Twhere
T: Global,
impl<T> ReadGlobal for Twhere
T: Global,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().