mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
Add font_style
and font_weight
to serialized theme representation (#6838)
This PR adds `font_style` and `font_weight` as fields on the `HighlightStyleContent` used in the serialized theme representation. Release Notes: - N/A
This commit is contained in:
parent
fd3c96dbed
commit
536a4ab87a
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -7864,6 +7864,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
"settings",
|
"settings",
|
||||||
"story",
|
"story",
|
||||||
"toml",
|
"toml",
|
||||||
|
@ -117,6 +117,7 @@ schemars = { version = "0.8" }
|
|||||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||||
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
||||||
serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }
|
serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }
|
||||||
|
serde_repr = "0.1"
|
||||||
smallvec = { version = "1.6", features = ["union"] }
|
smallvec = { version = "1.6", features = ["union"] }
|
||||||
smol = { version = "1.2" }
|
smol = { version = "1.2" }
|
||||||
strum = { version = "0.25.0", features = ["derive"] }
|
strum = { version = "0.25.0", features = ["derive"] }
|
||||||
|
@ -32,6 +32,7 @@ schemars = { workspace = true, features = ["indexmap"] }
|
|||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
serde_repr.workspace = true
|
||||||
settings = { path = "../settings" }
|
settings = { path = "../settings" }
|
||||||
story = { path = "../story", optional = true }
|
story = { path = "../story", optional = true }
|
||||||
toml.workspace = true
|
toml.workspace = true
|
||||||
|
@ -2,8 +2,12 @@ use anyhow::Result;
|
|||||||
use gpui::{HighlightStyle, Hsla};
|
use gpui::{HighlightStyle, Hsla};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use palette::FromColor;
|
use palette::FromColor;
|
||||||
|
use schemars::gen::SchemaGenerator;
|
||||||
|
use schemars::schema::{Schema, SchemaObject};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
|
||||||
use crate::{StatusColorsRefinement, ThemeColorsRefinement};
|
use crate::{StatusColorsRefinement, ThemeColorsRefinement};
|
||||||
|
|
||||||
@ -1126,8 +1130,71 @@ impl StatusColorsContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum FontStyleContent {
|
||||||
|
Normal,
|
||||||
|
Italic,
|
||||||
|
Oblique,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
|
||||||
|
#[repr(u16)]
|
||||||
|
pub enum FontWeightContent {
|
||||||
|
Thin = 100,
|
||||||
|
ExtraLight = 200,
|
||||||
|
Light = 300,
|
||||||
|
Normal = 400,
|
||||||
|
Medium = 500,
|
||||||
|
Semibold = 600,
|
||||||
|
Bold = 700,
|
||||||
|
ExtraBold = 800,
|
||||||
|
Black = 900,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JsonSchema for FontWeightContent {
|
||||||
|
fn schema_name() -> String {
|
||||||
|
"FontWeightContent".to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_referenceable() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn json_schema(_: &mut SchemaGenerator) -> Schema {
|
||||||
|
let mut schema_object = SchemaObject::default();
|
||||||
|
schema_object.enum_values = Some(vec![
|
||||||
|
100.into(),
|
||||||
|
200.into(),
|
||||||
|
300.into(),
|
||||||
|
400.into(),
|
||||||
|
500.into(),
|
||||||
|
600.into(),
|
||||||
|
700.into(),
|
||||||
|
800.into(),
|
||||||
|
900.into(),
|
||||||
|
]);
|
||||||
|
schema_object.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct HighlightStyleContent {
|
pub struct HighlightStyleContent {
|
||||||
pub color: Option<String>,
|
pub color: Option<String>,
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "treat_error_as_none")]
|
||||||
|
pub font_style: Option<FontStyleContent>,
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "treat_error_as_none")]
|
||||||
|
pub font_weight: Option<FontWeightContent>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
|
||||||
|
where
|
||||||
|
T: Deserialize<'de>,
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
Ok(T::deserialize(value).ok())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user