paiagram/
colors.rs

1use bevy::color::{Srgba, palettes::tailwind::*};
2use egui::{Color32, Widget};
3use strum_macros::{EnumCount, EnumIter};
4
5#[derive(Debug, Clone, Copy)]
6pub enum DisplayColor {
7    Predefined(PredefinedColor),
8    Custom(Color32),
9}
10
11impl Default for DisplayColor {
12    fn default() -> Self {
13        Self::Predefined(PredefinedColor::Red)
14    }
15}
16
17impl DisplayColor {
18    fn get(self, light: bool) -> Color32 {
19        match self {
20            Self::Predefined(p) => p.get(light),
21            Self::Custom(c) => c,
22        }
23    }
24}
25
26impl Widget for DisplayColor {
27    fn ui(self, ui: &mut egui::Ui) -> egui::Response {
28        let light = !ui.visuals().dark_mode;
29        let a = Color32::default();
30        ui.button("123")
31        // TODO: finish this
32    }
33}
34
35#[derive(Debug, Clone, Copy, EnumIter, EnumCount)]
36pub enum PredefinedColor {
37    Red,
38    Orange,
39    Amber,
40    Yellow,
41    Lime,
42    Green,
43    Emerald,
44    Teal,
45    Cyan,
46    Sky,
47    Blue,
48    Indigo,
49    Violet,
50    Purple,
51    Fuchsia,
52    Pink,
53    Rose,
54    Slate,
55    Gray,
56    Zinc,
57    Neutral,
58    Stone,
59}
60
61impl PredefinedColor {
62    // use 700 shade if light, otherwise use 400
63    // neutral is special
64    pub const fn get(self, light: bool) -> Color32 {
65        #[rustfmt::skip]
66        let c = match (self, light) {
67            (Self::Red, true)       => RED_700,
68            (Self::Red, false)      => RED_400,
69            (Self::Orange, true)    => ORANGE_700,
70            (Self::Orange, false)   => ORANGE_400,
71            (Self::Amber, true)     => AMBER_700,
72            (Self::Amber, false)    => AMBER_400,
73            (Self::Yellow, true)    => YELLOW_700,
74            (Self::Yellow, false)   => YELLOW_400,
75            (Self::Lime, true)      => LIME_700,
76            (Self::Lime, false)     => LIME_400,
77            (Self::Green, true)     => GREEN_700,
78            (Self::Green, false)    => GREEN_400,
79            (Self::Emerald, true)   => EMERALD_700,
80            (Self::Emerald, false)  => EMERALD_400,
81            (Self::Teal, true)      => TEAL_700,
82            (Self::Teal, false)     => TEAL_400,
83            (Self::Cyan, true)      => CYAN_700,
84            (Self::Cyan, false)     => CYAN_400,
85            (Self::Sky, true)       => SKY_700,
86            (Self::Sky, false)      => SKY_400,
87            (Self::Blue, true)      => BLUE_700,
88            (Self::Blue, false)     => BLUE_400,
89            (Self::Indigo, true)    => INDIGO_700,
90            (Self::Indigo, false)   => INDIGO_400,
91            (Self::Violet, true)    => VIOLET_700,
92            (Self::Violet, false)   => VIOLET_400,
93            (Self::Purple, true)    => PURPLE_700,
94            (Self::Purple, false)   => PURPLE_400,
95            (Self::Fuchsia, true)   => FUCHSIA_700,
96            (Self::Fuchsia, false)  => FUCHSIA_400,
97            (Self::Pink, true)      => PINK_700,
98            (Self::Pink, false)     => PINK_400,
99            (Self::Rose, true)      => ROSE_700,
100            (Self::Rose, false)     => ROSE_400,
101            (Self::Slate, true)     => SLATE_700,
102            (Self::Slate, false)    => SLATE_400,
103            (Self::Gray, true)      => GRAY_700,
104            (Self::Gray, false)     => GRAY_400,
105            (Self::Zinc, true)      => ZINC_700,
106            (Self::Zinc, false)     => ZINC_400,
107            (Self::Neutral, true)   => NEUTRAL_700,
108            (Self::Neutral, false)  => NEUTRAL_400,
109            (Self::Stone, true)     => STONE_700,
110            (Self::Stone, false)    => STONE_400,
111        };
112        translate_srgba_to_color32(c)
113    }
114}
115
116pub const fn translate_srgba_to_color32(c: Srgba) -> Color32 {
117    Color32::from_rgba_unmultiplied_const(
118        (c.red * 256.0) as u8,
119        (c.green * 256.0) as u8,
120        (c.blue * 256.0) as u8,
121        (c.alpha * 256.0) as u8,
122    )
123}