ranim_core/color/
mod.rs

1// pub use color::{AlphaColor, OpaqueColor, Srgb};
2pub use color::*;
3
4/// palettes
5pub mod palettes;
6pub use ::color::HueDirection;
7
8/// Color preludes
9pub mod prelude {
10    pub use super::{color, try_color};
11    pub use super::{rgb, rgb8, rgba, rgba8};
12}
13
14/// Construct an [`AlphaColor<Srgb>`] from rgb u8, the alpha value will be 255
15pub const fn rgb8(r: u8, g: u8, b: u8) -> AlphaColor<Srgb> {
16    OpaqueColor::from_rgb8(r, g, b).with_alpha(1.0)
17}
18
19/// Construct an [`AlphaColor<Srgb>`] from rgba u8
20pub const fn rgba8(r: u8, g: u8, b: u8, a: u8) -> AlphaColor<Srgb> {
21    AlphaColor::from_rgba8(r, g, b, a)
22}
23
24/// Construct an [`AlphaColor<Srgb>`] from rgb f32, the alpha value will be 1.0
25pub const fn rgb(r: f32, g: f32, b: f32) -> AlphaColor<Srgb> {
26    OpaqueColor::new([r, g, b]).with_alpha(1.0)
27}
28
29/// Construct an [`AlphaColor<Srgb>`] from rgba f32
30pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> AlphaColor<Srgb> {
31    AlphaColor::new([r, g, b, a])
32}
33
34/// Parse color string to [`AlphaColor<Srgb>`]
35///
36/// In its inner it uses [`color::parse_color`]
37pub fn color(color_str: &str) -> AlphaColor<Srgb> {
38    parse_color(color_str)
39        .expect("Invalid color string")
40        .to_alpha_color::<Srgb>()
41}
42
43/// Parse color string to [`AlphaColor<Srgb>`] without panic
44///
45/// In its inner it uses [`color::parse_color`]
46pub fn try_color(color_str: &str) -> Result<AlphaColor<Srgb>, ParseError> {
47    parse_color(color_str).map(|c| c.to_alpha_color::<Srgb>())
48}