hUI/hui-shared/src/color.rs

129 lines
7.2 KiB
Rust
Raw Normal View History

2024-03-06 19:24:45 -06:00
//! various predefined color constants and helper functions
2024-02-27 13:31:16 -06:00
2024-02-26 09:33:55 -06:00
use glam::{vec4, Vec4};
2024-03-06 19:24:45 -06:00
/// Create a color from red, green, blue components
pub fn rgb(r: u8, g: u8, b: u8) -> Vec4 {
vec4(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0)
}
/// Create a color from red, green, blue, alpha components
pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Vec4 {
vec4(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a as f32 / 255.0)
}
/// Create an RGB color from a u32 (/hex) value
pub fn rgb_hex(value: u32) -> Vec4 {
let r = (value >> 16) & 0xff;
let g = (value >> 8) & 0xff;
let b = value & 0xff;
vec4(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0)
}
/// Create an RGBA color from a u32 (/hex) value
pub fn rgba_hex(value: u32) -> Vec4 {
let r = (value >> 16) & 0xff;
let g = (value >> 8) & 0xff;
let b = value & 0xff;
let a = (value >> 24) & 0xff;
vec4(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a as f32 / 255.0)
}
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background: repeating-conic-gradient(grey 0 25%,darkgrey 0 50%) 50%/8px 8px; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#00000000` Transparent
2024-02-26 09:33:55 -06:00
pub const TRANSPARENT: Vec4 = vec4(0.0, 0.0, 0.0, 0.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #000000; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#000000` Black
2024-02-26 09:33:55 -06:00
pub const BLACK: Vec4 = vec4(0.0, 0.0, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #ffffff; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#ffffff` White
2024-02-26 09:33:55 -06:00
pub const WHITE: Vec4 = vec4(1.0, 1.0, 1.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #ff0000; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#ff0000` Red
2024-02-26 09:33:55 -06:00
pub const RED: Vec4 = vec4(1.0, 0.0, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #800000; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#800000` Dark red
2024-02-26 09:33:55 -06:00
pub const DARK_RED: Vec4 = vec4(0.5, 0.0, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #00ff00; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#00ff00` Green
2024-02-26 09:33:55 -06:00
pub const GREEN: Vec4 = vec4(0.0, 1.0, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #008000; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#008000` Dark green
2024-02-26 09:33:55 -06:00
pub const DARK_GREEN: Vec4 = vec4(0.0, 0.5, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #0000ff; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#0000ff` Blue
2024-02-26 09:33:55 -06:00
pub const BLUE: Vec4 = vec4(0.0, 0.0, 1.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #000080; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#000080` Dark blue
2024-02-26 09:33:55 -06:00
pub const DARK_BLUE: Vec4 = vec4(0.0, 0.0, 0.5, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #ffff00; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#ffff00` Yellow
2024-02-26 09:33:55 -06:00
pub const YELLOW: Vec4 = vec4(1.0, 1.0, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #00ffff; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#00ffff` Cyan
2024-02-26 09:33:55 -06:00
pub const CYAN: Vec4 = vec4(0.0, 1.0, 1.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #ff00ff; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#ff00ff` Magenta
2024-02-26 09:33:55 -06:00
pub const MAGENTA: Vec4 = vec4(1.0, 0.0, 1.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #808080; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#808080` Gray
2024-02-26 09:33:55 -06:00
pub const GRAY: Vec4 = vec4(0.5, 0.5, 0.5, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #c0c0c0; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#c0c0c0` Light gray
2024-02-26 09:33:55 -06:00
pub const LIGHT_GRAY: Vec4 = vec4(0.75, 0.75, 0.75, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #404040; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#404040` Dark gray
2024-02-26 09:33:55 -06:00
pub const DARK_GRAY: Vec4 = vec4(0.25, 0.25, 0.25, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #ff8000; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#ff8000` Orange
2024-02-26 09:33:55 -06:00
pub const ORANGE: Vec4 = vec4(1.0, 0.5, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #804000; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#804000` Brown
2024-02-26 09:33:55 -06:00
pub const BROWN: Vec4 = vec4(0.5, 0.25, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #ff80ff; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#ff80ff` Pink
2024-02-26 09:33:55 -06:00
pub const PINK: Vec4 = vec4(1.0, 0.5, 1.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #800080; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#800080` Purple
2024-02-26 09:33:55 -06:00
pub const PURPLE: Vec4 = vec4(0.5, 0.0, 0.5, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #80ff00; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#80ff00` Lime
2024-02-26 09:33:55 -06:00
pub const LIME: Vec4 = vec4(0.5, 1.0, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #008080; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#008080` Teal
2024-02-26 09:33:55 -06:00
pub const TEAL: Vec4 = vec4(0.0, 0.5, 0.5, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #004080; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#004080` Indigo
2024-02-26 09:33:55 -06:00
pub const INDIGO: Vec4 = vec4(0.0, 0.25, 0.5, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #808000; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#808000` Olive
2024-02-26 09:33:55 -06:00
pub const OLIVE: Vec4 = vec4(0.5, 0.5, 0.0, 1.0);
2024-02-27 15:57:46 -06:00
#[cfg_attr(doc, doc="<span style='display: inline-block; background-color: #87ceeb; width: 1em; height: 1em; border-radius: 50%; border: 1px solid black; vertical-align: -7%'></span>")]
2024-02-27 15:38:43 -06:00
/// `#87ceeb` Sky blue
2024-02-26 09:33:55 -06:00
pub const SKY_BLUE: Vec4 = vec4(0.53, 0.81, 0.92, 1.0);
//TODO color macro