mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +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_derive",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"settings",
|
||||
"story",
|
||||
"toml",
|
||||
|
@ -117,6 +117,7 @@ schemars = { version = "0.8" }
|
||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
||||
serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }
|
||||
serde_repr = "0.1"
|
||||
smallvec = { version = "1.6", features = ["union"] }
|
||||
smol = { version = "1.2" }
|
||||
strum = { version = "0.25.0", features = ["derive"] }
|
||||
|
@ -32,6 +32,7 @@ schemars = { workspace = true, features = ["indexmap"] }
|
||||
serde.workspace = true
|
||||
serde_derive.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde_repr.workspace = true
|
||||
settings = { path = "../settings" }
|
||||
story = { path = "../story", optional = true }
|
||||
toml.workspace = true
|
||||
|
@ -2,8 +2,12 @@ use anyhow::Result;
|
||||
use gpui::{HighlightStyle, Hsla};
|
||||
use indexmap::IndexMap;
|
||||
use palette::FromColor;
|
||||
use schemars::gen::SchemaGenerator;
|
||||
use schemars::schema::{Schema, SchemaObject};
|
||||
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};
|
||||
|
||||
@ -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)]
|
||||
#[serde(default)]
|
||||
pub struct HighlightStyleContent {
|
||||
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