Make indexing into ColorScales safe (#3205)

This PR makes indexing into `ColorScale`s safe by constraining the
`ColorScaleStep`s to a set of known values.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-11-02 02:52:42 +01:00 committed by GitHub
parent 69aafe9ff6
commit 72d060108d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 155 additions and 22 deletions

View file

@ -1,6 +1,6 @@
use crate::story::Story;
use gpui2::{px, Div, Render};
use theme2::default_color_scales;
use theme2::{default_color_scales, ColorScaleStep};
use ui::prelude::*;
pub struct ColorsStory;
@ -30,9 +30,14 @@ impl Render for ColorsStory {
.line_height(px(24.))
.child(scale.name().to_string()),
)
.child(div().flex().gap_1().children(
(1..=12).map(|step| div().flex().size_6().bg(scale.step(cx, step))),
))
.child(
div()
.flex()
.gap_1()
.children(ColorScaleStep::ALL.map(|step| {
div().flex().size_6().bg(scale.step(cx, step))
})),
)
})),
)
}