Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
Show 23 fields pub colors: ThemeColor, pub tokens: ThemeTokens, pub highlight_theme: Arc<HighlightTheme>, pub light_theme: Rc<ThemeConfig>, pub dark_theme: Rc<ThemeConfig>, pub mode: ThemeMode, pub font_family: SharedString, pub font_size: Pixels, pub mono_font_family: SharedString, pub mono_font_size: Pixels, pub radius: Pixels, pub radius_lg: Pixels, pub shadow: bool, pub focus_ring: bool, pub transparent: Hsla, pub scrollbar_mode: ScrollbarMode, pub notification: NotificationSettings, pub tile_grid_size: Pixels, pub tile_shadow: bool, pub tile_radius: Pixels, pub list: ListSettings, pub sheet: SheetSettings, pub motion: MotionTokens,
}
Expand description

The global theme configuration.

Fields§

§colors: ThemeColor§tokens: ThemeTokens

Component-specific resolved tokens retained for legacy compatibility.

New application-owned presentation should use Self::semantic_tokens rather than extending this legacy surface.

§highlight_theme: Arc<HighlightTheme>§light_theme: Rc<ThemeConfig>§dark_theme: Rc<ThemeConfig>§mode: ThemeMode§font_family: SharedString

The font family for the application, default is .SystemUIFont.

§font_size: Pixels

The base font size for the application, default is 16px.

§mono_font_family: SharedString

The monospace font family for the application.

Defaults to:

  • macOS: Menlo
  • Windows: Consolas
  • Linux: DejaVu Sans Mono
§mono_font_size: Pixels

The monospace font size for the application, default is 13px.

§radius: Pixels

Radius for the general elements.

§radius_lg: Pixels

Radius for the large elements, e.g.: Dialog, Notification border radius.

§shadow: bool§focus_ring: bool

Whether focused controls draw a ring outside their border, default true.

The ring is painted outside the element, so any ancestor that clips its content will cut it off. An application whose layout clips heavily can turn it off here: focused controls then show only their tinted border, which costs no space and cannot be clipped.

§transparent: Hsla§scrollbar_mode: ScrollbarMode

Show the scrollbar mode, default: Scrolling

§notification: NotificationSettings

The notification setting.

§tile_grid_size: Pixels

Tile grid size, default is 4px.

§tile_shadow: bool

The shadow of the tile panel.

§tile_radius: Pixels

The border radius of the tile panel, default is 0px.

§list: ListSettings

The list settings.

§sheet: SheetSettings

The sheet settings.

§motion: MotionTokens

Semantic motion policy for styled components.

Implementations§

Source§

impl Theme

Source

pub fn apply_config(&mut self, config: &Rc<ThemeConfig>)

Apply the given theme configuration to the current theme.

Source§

impl Theme

Source

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

Returns the global theme reference

Source

pub fn global_mut(cx: &mut App) -> &mut Theme

Returns the global theme mutable reference

Changes to fields the Base layer mirrors — the radius, the colors, the fonts — reach the scrollbar and resize handles only once Theme::sync_base runs.

Source

pub fn is_dark(&self) -> bool

Returns true if the theme is dark.

Source

pub fn theme_name(&self) -> &SharedString

Returns the current theme name.

Source

pub fn sync_system_appearance(window: Option<&mut Window>, cx: &mut App)

Sync the theme with the system appearance

Source

pub fn sync_scrollbar_appearance(cx: &mut App)

Sync the Scrollbar showing behavior with the system

Source

pub fn set_scrollbar_mode(mode: ScrollbarMode, cx: &mut App)

Changes the scrollbar display mode and synchronizes the Base projection.

Source

pub fn change( mode: impl Into<ThemeMode>, window: Option<&mut Window>, cx: &mut App, )

Change the theme mode.

Source

pub fn sync_base(cx: &mut App)

Push the current theme down to the Base layer.

The Base layer holds its own copy of the theme — the semantic tokens plus the scrollbar and resize-handle styles — because it paints those without going through gpui-component. Theme::change refreshes that copy, but writing to the theme’s public fields directly does not, so a scrollbar keeps painting with the radius and colors it was last given.

Call this after mutating the theme through Theme::global_mut:

Theme::global_mut(cx).radius = px(0.);
Theme::sync_base(cx);

It rebuilds the Base theme from scratch, so any style written straight onto the Base global is replaced — the same thing Theme::change does.

Source

pub fn input_background(&self) -> Hsla

Get the input background color.

For dark, use a transparent color mixed with the input border: cx.theme().input, otherwise use the cx.theme().background color.

Source

pub fn semantic_tokens(&self) -> SemanticThemeTokens

Returns a snapshot of the semantic design tokens represented by this theme. The snapshot is computed from the legacy public fields so direct mutations of those fields are reflected immediately.

Source

pub fn motion_tokens(&self) -> &MotionTokens

Returns the styled layer’s semantic motion policy.

Source

pub fn color_tokens(&self) -> ColorTokens

Source

pub fn radius_full(&self) -> Pixels

The radius of a shape that reads as a circle or a pill — an avatar, a slider thumb, a badge dot, a pill tab.

A theme whose Theme::radius is zero squares these off too, so one setting governs the whole UI instead of leaving a handful of permanently round elements behind. Use it in place of gpui::Styled::rounded_full, or reach for crate::ThemeStyled::rounded_full_style when styling an element.

Source

pub fn radius_2xl(&self) -> Pixels

Returns the next surface radius above the existing xl theme tier.

Larger surface tiers derive from the same application-controlled base radius, so adjusting or squaring the theme updates every tier together.

Source

pub fn radius_3xl(&self) -> Pixels

Returns the surface radius above Self::radius_2xl.

Source

pub fn radius_4xl(&self) -> Pixels

Returns the surface radius above Self::radius_3xl.

Source

pub fn radius_tokens(&self) -> RadiusTokens

Source

pub fn spacing_tokens(&self) -> SpacingTokens

Source

pub fn typography_tokens(&self) -> TypographyTokens

Source

pub fn shadow_tokens(&self) -> ShadowTokens

Source

pub fn apply_semantic_tokens(&mut self, tokens: &SemanticThemeTokens)

Applies the subset of semantic tokens representable by the legacy theme. Scale-only spacing and elevation details have no legacy storage; legacy components therefore keep their existing behavior.

Source

pub fn resolve_semantic_config( &self, config: &SemanticThemeConfig, ) -> SemanticThemeTokens

Resolves a standalone semantic configuration over the current legacy theme without mutating either value.

Source

pub fn apply_semantic_config( &mut self, config: &SemanticThemeConfig, ) -> SemanticThemeTokens

Applies the legacy-representable part of a standalone semantic config and returns the complete resolved snapshot for application-owned UI.

Source

pub fn apply_semantic_config_str( &mut self, content: &str, ) -> Result<SemanticThemeTokens>

Parses and applies a standalone { "tokens": ... } semantic theme file.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

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

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

impl Default for Theme

Source§

fn default() -> Self

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

impl Deref for Theme

Source§

type Target = ThemeColor

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Theme

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'de> Deserialize<'de> for Theme

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&ThemeColor> for Theme

Source§

fn from(colors: &ThemeColor) -> Self

Converts to this type from the input type.
Source§

impl Global for Theme

Source§

impl JsonSchema for Theme

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl Serialize for Theme

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Theme

§

impl !Send for Theme

§

impl !Sync for Theme

§

impl !UnwindSafe for Theme

§

impl Freeze 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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