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: ThemeTokensComponent-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: SharedStringThe font family for the application, default is .SystemUIFont.
font_size: PixelsThe base font size for the application, default is 16px.
mono_font_family: SharedStringThe monospace font family for the application.
Defaults to:
- macOS:
Menlo - Windows:
Consolas - Linux:
DejaVu Sans Mono
mono_font_size: PixelsThe monospace font size for the application, default is 13px.
radius: PixelsRadius for the general elements.
radius_lg: PixelsRadius for the large elements, e.g.: Dialog, Notification border radius.
shadow: bool§focus_ring: boolWhether 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: ScrollbarModeShow the scrollbar mode, default: Scrolling
notification: NotificationSettingsThe notification setting.
tile_grid_size: PixelsTile grid size, default is 4px.
tile_shadow: boolThe shadow of the tile panel.
tile_radius: PixelsThe border radius of the tile panel, default is 0px.
list: ListSettingsThe list settings.
sheet: SheetSettingsThe sheet settings.
motion: MotionTokensSemantic motion policy for styled components.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn apply_config(&mut self, config: &Rc<ThemeConfig>)
pub fn apply_config(&mut self, config: &Rc<ThemeConfig>)
Apply the given theme configuration to the current theme.
Source§impl Theme
impl Theme
Sourcepub fn global_mut(cx: &mut App) -> &mut Theme
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.
Sourcepub fn theme_name(&self) -> &SharedString
pub fn theme_name(&self) -> &SharedString
Returns the current theme name.
Sourcepub fn sync_system_appearance(window: Option<&mut Window>, cx: &mut App)
pub fn sync_system_appearance(window: Option<&mut Window>, cx: &mut App)
Sync the theme with the system appearance
Sourcepub fn sync_scrollbar_appearance(cx: &mut App)
pub fn sync_scrollbar_appearance(cx: &mut App)
Sync the Scrollbar showing behavior with the system
Sourcepub fn set_scrollbar_mode(mode: ScrollbarMode, cx: &mut App)
pub fn set_scrollbar_mode(mode: ScrollbarMode, cx: &mut App)
Changes the scrollbar display mode and synchronizes the Base projection.
Sourcepub fn change(
mode: impl Into<ThemeMode>,
window: Option<&mut Window>,
cx: &mut App,
)
pub fn change( mode: impl Into<ThemeMode>, window: Option<&mut Window>, cx: &mut App, )
Change the theme mode.
Sourcepub fn sync_base(cx: &mut App)
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.
Sourcepub fn input_background(&self) -> Hsla
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.
Sourcepub fn semantic_tokens(&self) -> SemanticThemeTokens
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.
Sourcepub fn motion_tokens(&self) -> &MotionTokens
pub fn motion_tokens(&self) -> &MotionTokens
Returns the styled layer’s semantic motion policy.
pub fn color_tokens(&self) -> ColorTokens
Sourcepub fn radius_full(&self) -> Pixels
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.
Sourcepub fn radius_2xl(&self) -> Pixels
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.
Sourcepub fn radius_3xl(&self) -> Pixels
pub fn radius_3xl(&self) -> Pixels
Returns the surface radius above Self::radius_2xl.
Sourcepub fn radius_4xl(&self) -> Pixels
pub fn radius_4xl(&self) -> Pixels
Returns the surface radius above Self::radius_3xl.
pub fn radius_tokens(&self) -> RadiusTokens
pub fn spacing_tokens(&self) -> SpacingTokens
pub fn typography_tokens(&self) -> TypographyTokens
pub fn shadow_tokens(&self) -> ShadowTokens
Sourcepub fn apply_semantic_tokens(&mut self, tokens: &SemanticThemeTokens)
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.
Sourcepub fn resolve_semantic_config(
&self,
config: &SemanticThemeConfig,
) -> SemanticThemeTokens
pub fn resolve_semantic_config( &self, config: &SemanticThemeConfig, ) -> SemanticThemeTokens
Resolves a standalone semantic configuration over the current legacy theme without mutating either value.
Sourcepub fn apply_semantic_config(
&mut self,
config: &SemanticThemeConfig,
) -> SemanticThemeTokens
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.
Sourcepub fn apply_semantic_config_str(
&mut self,
content: &str,
) -> Result<SemanticThemeTokens>
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<'de> Deserialize<'de> for Theme
impl<'de> Deserialize<'de> for Theme
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&ThemeColor> for Theme
impl From<&ThemeColor> for Theme
Source§fn from(colors: &ThemeColor) -> Self
fn from(colors: &ThemeColor) -> Self
impl Global for Theme
Source§impl JsonSchema for Theme
impl JsonSchema for Theme
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreAuto 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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
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().