Self-Review Checklist: - [ ] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [ ] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [ ] Performance impact has been considered and is acceptable Closes #ISSUE Release Notes: - N/A
31 lines
809 B
Rust
31 lines
809 B
Rust
#![allow(missing_docs)]
|
|
|
|
use gpui::Hsla;
|
|
use palette::FromColor;
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// The appearance of a theme in serialized content.
|
|
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum AppearanceContent {
|
|
Light,
|
|
Dark,
|
|
}
|
|
|
|
/// Parses a color string into an [`Hsla`] value.
|
|
pub fn try_parse_color(color: &str) -> anyhow::Result<Hsla> {
|
|
let rgba = gpui::Rgba::try_from(color)?;
|
|
let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
|
|
let hsla = palette::Hsla::from_color(rgba);
|
|
|
|
let hsla = gpui::hsla(
|
|
hsla.hue.into_positive_degrees() / 360.,
|
|
hsla.saturation,
|
|
hsla.lightness,
|
|
hsla.alpha,
|
|
);
|
|
|
|
Ok(hsla)
|
|
}
|