color_lib/colors.rs
1//!
2//! This module includes all default colors for quick use
3//!
4
5use crate::{Color, ColorRGBA, ColorType};
6
7/// A color in the gray spectrum
8#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
9pub struct Grays {
10 /// The value for the color, 0: black, 1: white
11 v: f32,
12 /// The alpha value
13 a: f32,
14}
15
16impl Grays {
17 /// Constructs a new gray color
18 ///
19 /// parameters
20 ///
21 /// v: The value of the gray color, 0: black, 1: white
22 ///
23 /// a: The alpha value
24 pub fn new(v: f32, a: f32) -> Self {
25 return Self {
26 v: v.clamp(0.0, 1.0),
27 a: a.clamp(0.0, 1.0),
28 };
29 }
30
31 /// Constructs a new gray color without clamping the input values
32 ///
33 /// parameters
34 ///
35 /// v: The value of the gray color, 0: black, 1: white
36 ///
37 /// a: The alpha value
38 pub unsafe fn new_unsafe(v: f32, a: f32) -> Self {
39 return Self { v, a };
40 }
41}
42
43impl Color for Grays {
44 const TYPE: ColorType = ColorType::RGB;
45
46 fn get_rgba(&self) -> crate::ColorRGBA {
47 return unsafe { ColorRGBA::new_unsafe(self.v, self.v, self.v, self.a) };
48 }
49}