Skip to main content

Theme

Struct Theme 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§mode: ThemeMode

Which config is active.

§light: ThemeConfig

The config used in light appearance.

§dark: ThemeConfig

The config used in dark appearance.

§radius: Pixels

The base corner radius. The radius scale derives from it.

§ui_font_size: Pixels

The 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: Pixels

The code font size.

§reduce_motion: ReduceMotion

Whether motion is reduced.

§motion: MotionTokens

Durations and curves components animate with.

§pointer_cursors: bool

Pointer cursor on interactive controls. Off keeps the platform arrow on buttons. Links always use the pointer.

§shadow: bool

Whether elevated surfaces cast shadows.

§touch: bool

Whether 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

Source

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

The theme global. Panics before crate::init.

Source

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.

Source

pub fn tokens(&self) -> &ThemeTokens

The derived tokens for the active appearance.

Source

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.

Source

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.

Source

pub fn scope(&self, key: &str) -> Option<&ThemeTokens>

The tokens of the scope key, if it is registered.

Source

pub fn appearance(&self) -> ThemeAppearance

The active appearance after resolving mode.

Source

pub fn is_dark(&self) -> bool

Whether the active appearance is dark.

Source

pub fn active_config(&self) -> &ThemeConfig

The config for the active appearance.

Source

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.

Source

pub fn change(mode: ThemeMode, cx: &mut App)

Switches the mode.

Source

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.

Source

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> 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> 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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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