Adjust ColorScale representation (#3204)

This PR adjusts the representations of `ColorScale`s to allow us to
remove an unsafe `From` impl when converting from the statically-defined
representation of the scale.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2023-11-01 21:10:50 -04:00
committed by GitHub
parent f415a37a3d
commit 69aafe9ff6
2 changed files with 147 additions and 93 deletions
+18 -4
View File
@@ -2,7 +2,24 @@ use gpui2::{AppContext, Hsla, SharedString};
use crate::{ActiveTheme, Appearance};
pub type ColorScale = [Hsla; 12];
/// A one-based step in a [`ColorScale`].
pub type ColorScaleStep = usize;
pub struct ColorScale(Vec<Hsla>);
impl FromIterator<Hsla> for ColorScale {
fn from_iter<T: IntoIterator<Item = Hsla>>(iter: T) -> Self {
Self(Vec::from_iter(iter))
}
}
impl std::ops::Index<ColorScaleStep> for ColorScale {
type Output = Hsla;
fn index(&self, index: ColorScaleStep) -> &Self::Output {
&self.0[index - 1]
}
}
pub struct ColorScales {
pub gray: ColorScaleSet,
@@ -85,9 +102,6 @@ impl IntoIterator for ColorScales {
}
}
/// A one-based step in a [`ColorScale`].
pub type ColorScaleStep = usize;
pub struct ColorScaleSet {
name: SharedString,
light: ColorScale,