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-02 02:10:50 +01:00 committed by GitHub
parent f415a37a3d
commit 69aafe9ff6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 147 additions and 93 deletions

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,