Start documenting Theme crate

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nate Butler 2024-01-09 12:49:56 -05:00
parent ab6cd1d93a
commit bcbfa7d036
6 changed files with 51 additions and 47 deletions

23
Cargo.lock generated
View file

@ -1515,7 +1515,7 @@ dependencies = [
"tonic", "tonic",
"tower", "tower",
"tracing", "tracing",
"tracing-log 0.1.3", "tracing-log",
"tracing-subscriber", "tracing-subscriber",
"unindent", "unindent",
"util", "util",
@ -6930,9 +6930,9 @@ dependencies = [
[[package]] [[package]]
name = "sharded-slab" name = "sharded-slab"
version = "0.1.7" version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
] ]
@ -8316,17 +8316,6 @@ dependencies = [
"tracing-core", "tracing-core",
] ]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]] [[package]]
name = "tracing-serde" name = "tracing-serde"
version = "0.1.3" version = "0.1.3"
@ -8339,9 +8328,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.18" version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
dependencies = [ dependencies = [
"matchers", "matchers",
"nu-ansi-term", "nu-ansi-term",
@ -8354,7 +8343,7 @@ dependencies = [
"thread_local", "thread_local",
"tracing", "tracing",
"tracing-core", "tracing-core",
"tracing-log 0.2.0", "tracing-log",
"tracing-serde", "tracing-serde",
] ]

View file

@ -2,41 +2,31 @@ use gpui::{AppContext, Hsla, SharedString};
use crate::{ActiveTheme, Appearance}; use crate::{ActiveTheme, Appearance};
/// A one-based step in a [`ColorScale`]. /// A collection of colors that are used to style the UI.
///
/// Each step has a semantic meaning, and is used to style different parts of the UI.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub struct ColorScaleStep(usize); pub struct ColorScaleStep(usize);
impl ColorScaleStep { impl ColorScaleStep {
pub const ONE: Self = Self(1); const ONE: Self = Self(1);
pub const TWO: Self = Self(2); const TWO: Self = Self(2);
pub const THREE: Self = Self(3); const THREE: Self = Self(3);
pub const FOUR: Self = Self(4); const FOUR: Self = Self(4);
pub const FIVE: Self = Self(5); const FIVE: Self = Self(5);
pub const SIX: Self = Self(6); const SIX: Self = Self(6);
pub const SEVEN: Self = Self(7); const SEVEN: Self = Self(7);
pub const EIGHT: Self = Self(8); const EIGHT: Self = Self(8);
pub const NINE: Self = Self(9); const NINE: Self = Self(9);
pub const TEN: Self = Self(10); const TEN: Self = Self(10);
pub const ELEVEN: Self = Self(11); const ELEVEN: Self = Self(11);
pub const TWELVE: Self = Self(12); const TWELVE: Self = Self(12);
/// All of the steps in a [`ColorScale`].
pub const ALL: [ColorScaleStep; 12] = [
Self::ONE,
Self::TWO,
Self::THREE,
Self::FOUR,
Self::FIVE,
Self::SIX,
Self::SEVEN,
Self::EIGHT,
Self::NINE,
Self::TEN,
Self::ELEVEN,
Self::TWELVE,
];
} }
/// A scale of colors for a given [ColorScaleSet].
///
/// Each [ColorScale] contains exactly 12 colors. Refer to
/// [ColorScaleStep] for a reference of what each step is used for.
pub struct ColorScale(Vec<Hsla>); pub struct ColorScale(Vec<Hsla>);
impl FromIterator<Hsla> for ColorScale { impl FromIterator<Hsla> for ColorScale {
@ -229,6 +219,7 @@ impl IntoIterator for ColorScales {
} }
} }
/// Provides groups of [ColorScale]s for light and dark themes, as well as transparent versions of each scale.
pub struct ColorScaleSet { pub struct ColorScaleSet {
name: SharedString, name: SharedString,
light: ColorScale, light: ColorScale,

View file

@ -27,7 +27,7 @@ pub struct ThemeSettings {
} }
#[derive(Default)] #[derive(Default)]
pub struct AdjustedBufferFontSize(Pixels); pub(crate) struct AdjustedBufferFontSize(Pixels);
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct ThemeSettingsContent { pub struct ThemeSettingsContent {

View file

@ -7,6 +7,7 @@ use crate::{PlayerColors, StatusColors, StatusColorsRefinement, SyntaxTheme, Sys
#[derive(Refineable, Clone, Debug)] #[derive(Refineable, Clone, Debug)]
#[refineable(Debug, serde::Deserialize)] #[refineable(Debug, serde::Deserialize)]
pub struct ThemeColors { pub struct ThemeColors {
/// Border color. Used for most borders, is usually a high contrast color.
pub border: Hsla, pub border: Hsla,
/// Border color. Used for deemphasized borders, like a visual divider between two sections /// Border color. Used for deemphasized borders, like a visual divider between two sections
pub border_variant: Hsla, pub border_variant: Hsla,

View file

@ -1,3 +1,11 @@
//! # Theme
//!
//! This crate provides the theme system for Zed.
//!
//! ## Overview
//!
//! A theme is a collection of colors used to build a consistent appearance for UI components across the application.
mod default_colors; mod default_colors;
mod default_theme; mod default_theme;
mod one_themes; mod one_themes;

15
crates/theme/theme.md Normal file
View file

@ -0,0 +1,15 @@
# Theme
This crate provides the theme system for Zed.
## Overview
A theme is a collection of colors used to build a consistent appearance for UI components across the application.
To produce a theme in Zed,
A theme is made of of two parts: A [ThemeFamily] and one or more [Theme]s.
//
A [ThemeFamily] contains metadata like theme name, author, and theme-specific [ColorScales] as well as a series of themes.
- [ThemeColors] - A set of colors that are used to style the UI. Refer to the [ThemeColors] documentation for more information.