Extend RGBA hex color parsing to support 3-value and 4-value variants (#3295)

This PR extends our support for parsing hex color codes to `Rgba` to
additionally support 3-value (`#rgb`) and 4-value (`#rgba`) formats.

See [here](https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color)
for more details on these hex color variants.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2023-11-09 18:27:47 -05:00
committed by GitHub
2 changed files with 103 additions and 30 deletions
+2 -4
View File
@@ -1,5 +1,3 @@
use std::num::ParseIntError;
use gpui::{hsla, Hsla, Rgba};
use crate::colors::{StatusColors, SystemColors, ThemeColors};
@@ -413,10 +411,10 @@ struct StaticColorScaleSet {
}
impl TryFrom<StaticColorScaleSet> for ColorScaleSet {
type Error = ParseIntError;
type Error = anyhow::Error;
fn try_from(value: StaticColorScaleSet) -> Result<Self, Self::Error> {
fn to_color_scale(scale: StaticColorScale) -> Result<ColorScale, ParseIntError> {
fn to_color_scale(scale: StaticColorScale) -> Result<ColorScale, anyhow::Error> {
scale
.into_iter()
.map(|color| Rgba::try_from(color).map(Hsla::from))