diff options
author | 2020-02-21 15:40:37 -0600 | |
---|---|---|
committer | 2020-04-24 15:13:22 -0500 | |
commit | 27a4cbccea91c508b914f2211a07aec2a4bed96e (patch) | |
tree | e4eef8785077423683faea9a62a2271aa7117e98 /core | |
parent | 62fddce2e676123b1325a16d144a1d0674dcd1ff (diff) | |
download | iced-27a4cbccea91c508b914f2211a07aec2a4bed96e.tar.gz iced-27a4cbccea91c508b914f2211a07aec2a4bed96e.tar.bz2 iced-27a4cbccea91c508b914f2211a07aec2a4bed96e.zip |
Add inversion functions, rename check_rgba -> new
Diffstat (limited to 'core')
-rw-r--r-- | core/src/color.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/core/src/color.rs b/core/src/color.rs index 799d85c9..fbc160e3 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -1,6 +1,5 @@ /// A color in the sRGB color space. #[derive(Debug, Clone, Copy, PartialEq)] -#[allow(missing_docs)] pub struct Color { /// Red component, 0.0 - 1.0 pub r: f32, @@ -12,7 +11,6 @@ pub struct Color { pub a: f32, } - impl Color { /// The black color. pub const BLACK: Color = Color { @@ -44,7 +42,7 @@ impl Color { } /// Ensures RGBA values on the range [0.0, 1.0] - pub fn check_rgba(r: f32, g: f32, b: f32, a:f32) -> Color { + pub fn new(r: f32, g: f32, b: f32, a: f32) -> Color { Color { r: Color::clamp(r), g: Color::clamp(g), @@ -57,7 +55,7 @@ impl Color { /// /// [`Color`]: struct.Color.html pub fn from_rgb(r: f32, g: f32, b: f32) -> Color { - Color::check_rgba(r, g, b, 1.0) + Color::new(r, g, b, 1.0) } /// Creates a [`Color`] from its RGB8 components. @@ -100,6 +98,18 @@ impl Color { self.a, ] } + + /// Invert the Color in-place + pub fn invert(&mut self) { + self.r = Color::clamp(1.0f32 - self.r); + self.b = Color::clamp(1.0f32 - self.g); + self.g = Color::clamp(1.0f32 - self.b); + } + + /// Return an inverted Color + pub fn inverse(self) -> Color { + Color::new(1.0f32 - self.r, 1.0f32 - self.g, 1.0f32 - self.b, self.a) + } } impl From<[f32; 3]> for Color { |