schema.rs

 1#![allow(missing_docs)]
 2
 3use gpui::Hsla;
 4use palette::FromColor;
 5use schemars::JsonSchema;
 6use serde::{Deserialize, Serialize};
 7
 8/// The appearance of a theme in serialized content.
 9#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum AppearanceContent {
12    Light,
13    Dark,
14}
15
16/// Parses a color string into an [`Hsla`] value.
17pub fn try_parse_color(color: &str) -> anyhow::Result<Hsla> {
18    let rgba = gpui::Rgba::try_from(color)?;
19    let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
20    let hsla = palette::Hsla::from_color(rgba);
21
22    let hsla = gpui::hsla(
23        hsla.hue.into_positive_degrees() / 360.,
24        hsla.saturation,
25        hsla.lightness,
26        hsla.alpha,
27    );
28
29    Ok(hsla)
30}