zng_color/
colors.rs

1//! Named primary, secondary and tertiary colors.
2//!
3//! You can use [`darken`] and [`lighten`] to derive more shades from these colors.
4//!
5//! [`darken`]: crate::MixAdjust::darken
6//! [`lighten`]: crate::MixAdjust::lighten
7
8use zng_var::context_var;
9
10use crate::{LightDark, light_dark};
11
12use super::Rgba;
13
14macro_rules! rgb {
15    ($r:literal, $g:literal, $b:literal) => {
16        Rgba {
17            red: $r as f32 / 255.,
18            green: $g as f32 / 255.,
19            blue: $b as f32 / 255.,
20            alpha: 1.0,
21        }
22    };
23}
24
25/// <span style="display: inline-block; background-color:#000000; width:20px; height:20px;"></span> Black, `#000000`, `rgb(0, 0, 0)`.
26pub const BLACK: Rgba = rgb!(0, 0, 0);
27
28/// <span style="display: inline-block; background-color:#808080; width:20px; height:20px;"></span> Gray, `#808080`, `rgb(128, 128, 128)`.
29pub const GRAY: Rgba = rgb!(128, 128, 128);
30
31/// <span style="display: inline-block; background-color:#FFFFFF; width:20px; height:20px;"></span> White, `#FFFFFF`, `rgb(255, 255, 255)`.
32pub const WHITE: Rgba = rgb!(255, 255, 255);
33
34/// <span style="display: inline-block; background-color:#FF0000; width:20px; height:20px;"></span> Red, `#FF0000`, `rgb(255, 0, 0)`.
35pub const RED: Rgba = rgb!(255, 0, 0);
36
37/// <span style="display: inline-block; background-color:#FF8000; width:20px; height:20px;"></span> Orange, `#FF8000`, `rgb(255, 128, 0)`.
38pub const ORANGE: Rgba = rgb!(255, 128, 0);
39
40/// <span style="display: inline-block; background-color:#FFFF00; width:20px; height:20px;"></span> Yellow, `#FFFF00`, `rgb(255, 255, 0)`.
41pub const YELLOW: Rgba = rgb!(255, 255, 0);
42
43/// <span style="display: inline-block; background-color:#80FF00; width:20px; height:20px;"></span> Lime, `#80FF00`, `rgb(128, 255, 0)`.
44pub const LIME: Rgba = rgb!(128, 255, 0);
45
46/// <span style="display: inline-block; background-color:#00FF00; width:20px; height:20px;"></span> Green, `#00FF00`, `rgb(0, 255, 0)`.
47pub const GREEN: Rgba = rgb!(0, 255, 0);
48
49/// <span style="display: inline-block; background-color:#00FF80; width:20px; height:20px;"></span> Spring, `#00FF80`, `rgb(0, 255, 128)`.
50pub const SPRING: Rgba = rgb!(0, 255, 128);
51
52/// <span style="display: inline-block; background-color:#00FFFF; width:20px; height:20px;"></span> Cyan, `#00FFFF`, `rgb(0, 255, 255)`.
53pub const CYAN: Rgba = rgb!(0, 255, 255);
54
55/// <span style="display: inline-block; background-color:#0080FF; width:20px; height:20px;"></span> Azure, `#0080FF`, `rgb(0, 128, 255)`.
56pub const AZURE: Rgba = rgb!(0, 128, 255);
57
58/// <span style="display: inline-block; background-color:#0000FF; width:20px; height:20px;"></span> Blue, `#0000FF`, `rgb(0, 0, 255)`.
59pub const BLUE: Rgba = rgb!(0, 0, 255);
60
61/// <span style="display: inline-block; background-color:#8000FF; width:20px; height:20px;"></span> Violet, `#8000FF`, `rgb(128, 0, 255)`.
62pub const VIOLET: Rgba = rgb!(128, 0, 255);
63
64/// <span style="display: inline-block; background-color:#FF00FF; width:20px; height:20px;"></span> Magenta, `#FF00FF`, `rgb(255, 0, 255)`.
65pub const MAGENTA: Rgba = rgb!(255, 0, 255);
66
67/// <span style="display: inline-block; background-color:#FF0080; width:20px; height:20px;"></span> Rose, `#FF0080`, `rgb(255, 0, 128)`.
68pub const ROSE: Rgba = rgb!(255, 0, 128);
69
70context_var! {
71    /// Color that contrasts with the text color.
72    pub static ACCENT_COLOR_VAR: LightDark = BLUE;
73
74    /// Seed color for widget background.
75    ///
76    /// See also [`LightDarkVarExt`] for helper methods implemented on [`LightDark`] variables.
77    ///
78    /// [`LightDarkVarExt`]: crate::LightDarkVarExt
79    pub static BASE_COLOR_VAR: LightDark = light_dark(WHITE, BLACK);
80}