maybe_fatal/
color_palette.rs1pub use ariadne::{Color, ColorGenerator};
2
3#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub struct ColorPalette {
6 pub special: Color,
8
9 pub random: [Color; Self::N_RANDOM_COLORS],
11}
12
13impl ColorPalette {
14 pub const N_RANDOM_COLORS: usize = 4;
16
17 pub const DEFAULT_RANDOM_COLORS: [Color; Self::N_RANDOM_COLORS] = {
19 let mut r#gen = ColorGenerator::new();
22 [r#gen.next(), r#gen.next(), r#gen.next(), r#gen.next()]
23 };
24
25 pub const DEFAULT_SPECIAL_COLOR: Color = Color::Fixed(81);
27
28 pub const fn new() -> Self {
32 Self {
33 special: Self::DEFAULT_SPECIAL_COLOR,
34 random: Self::DEFAULT_RANDOM_COLORS,
35 }
36 }
37
38 pub const fn with_special(&mut self, color: Color) -> &mut Self {
40 self.special = color;
41 self
42 }
43
44 pub const fn with_random_colors(
46 &mut self,
47 colors: [Color; Self::N_RANDOM_COLORS],
48 ) -> &mut Self {
49 self.random = colors;
50 self
51 }
52
53 pub fn with_regenerated_random_colors(&mut self, color_gen: &mut ColorGenerator) -> &mut Self {
55 self.with_random_colors(core::array::from_fn(|_| color_gen.next()))
56 }
57}
58
59impl Default for ColorPalette {
60 fn default() -> Self {
61 Self::new()
62 }
63}