#[non_exhaustive]pub struct Theme {
pub mode: ThemeMode,
pub light: ThemeConfig,
pub dark: ThemeConfig,
pub radius: Pixels,
pub ui_font_size: Pixels,
pub code_font_size: Pixels,
pub reduce_motion: ReduceMotion,
pub motion: MotionTokens,
pub pointer_cursors: bool,
pub shadow: bool,
pub touch: bool,
/* private fields */
}Expand description
The gpui-cn theme, a GPUI global.
Public fields are the inputs. Edit them through Theme::update, which
re-derives the tokens, projects them onto gpui_base::Theme, applies the
motion preference, and refreshes every window. Components read the
derived ThemeTokens through ActiveTheme::theme.
gpui-cn owns gpui_base::Theme the same way gpui-component does:
every change is projected onto it, and nothing reads it back.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.mode: ThemeModeWhich config is active.
light: ThemeConfigThe config used in light appearance.
dark: ThemeConfigThe config used in dark appearance.
radius: PixelsThe base corner radius. The radius scale derives from it.
ui_font_size: PixelsThe interface font size. It is also the window rem size, so it is the zoom control for everything on the rem scale.
code_font_size: PixelsThe code font size.
reduce_motion: ReduceMotionWhether motion is reduced.
motion: MotionTokensDurations and curves components animate with.
pointer_cursors: boolPointer cursor on interactive controls. Off keeps the platform arrow on buttons. Links always use the pointer.
shadow: boolWhether elevated surfaces cast shadows.
touch: boolWhether a finger is the pointer. On by default on iOS and Android. Controls and rows grow to the 44pt hit target of Apple’s Human Interface Guidelines, text takes its body size, and nothing shows a hover state, since a finger cannot hover.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn global(cx: &App) -> &Self
pub fn global(cx: &App) -> &Self
The theme global. Panics before crate::init.
Sourcepub fn holds_still(cx: &App) -> bool
pub fn holds_still(cx: &App) -> bool
Whether a looping animation (a spinner, a pulse, a sweep) holds still: under reduced motion, or with every motion duration at zero.
Sourcepub fn tokens(&self) -> &ThemeTokens
pub fn tokens(&self) -> &ThemeTokens
The derived tokens for the active appearance.
Sourcepub fn active_tokens(&self) -> &ThemeTokens
pub fn active_tokens(&self) -> &ThemeTokens
The tokens a component reads: the scope’s while it draws inside a
ThemeScope, the active appearance’s otherwise.
Sourcepub fn set_scope(
cx: &mut App,
key: impl Into<SharedString>,
config: ThemeConfig,
)
pub fn set_scope( cx: &mut App, key: impl Into<SharedString>, config: ThemeConfig, )
Registers or replaces the scope key: a part of the window drawn on
its own surface and ink, such as a terminal with its own colors.
Its tokens derive from config with this theme’s sizes, and its
appearance follows the surface: dark when the surface’s OKLab
lightness is under one half. They derive again whenever the theme
changes, so a font size change reaches them too.
Sourcepub fn scope(&self, key: &str) -> Option<&ThemeTokens>
pub fn scope(&self, key: &str) -> Option<&ThemeTokens>
The tokens of the scope key, if it is registered.
Sourcepub fn appearance(&self) -> ThemeAppearance
pub fn appearance(&self) -> ThemeAppearance
The active appearance after resolving mode.
Sourcepub fn active_config(&self) -> &ThemeConfig
pub fn active_config(&self) -> &ThemeConfig
The config for the active appearance.
Sourcepub fn update<R>(cx: &mut App, edit: impl FnOnce(&mut Theme) -> R) -> R
pub fn update<R>(cx: &mut App, edit: impl FnOnce(&mut Theme) -> R) -> R
Edits the theme, then re-derives tokens, projects them onto base, applies the motion preference, and refreshes every window.
Sourcepub fn sync_system_appearance(window: Option<&Window>, cx: &mut App)
pub fn sync_system_appearance(window: Option<&Window>, cx: &mut App)
Reads the system appearance again. gpui-cn’s root layer calls this when the
window appearance changes; it matters only in ThemeMode::System.
Sourcepub fn set_ui_font_size(cx: &mut App, size: Pixels)
pub fn set_ui_font_size(cx: &mut App, size: Pixels)
Sets both font sizes at once, keeping their ratio.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Theme
impl !RefUnwindSafe for Theme
impl !Send for Theme
impl !Sync for Theme
impl !UnwindSafe for Theme
impl Unpin for Theme
impl UnsafeUnpin for Theme
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 more