diff options
author | 2020-04-02 17:29:26 -0500 | |
---|---|---|
committer | 2020-04-24 15:13:22 -0500 | |
commit | 04be010fbdf84300531b806fa8855f57bbf727b7 (patch) | |
tree | 0f4d739101da092077ccc3ea497e12841ac7255e /core/src | |
parent | ea3b7b528275c7ae8a336004ad77f85341599335 (diff) | |
download | iced-04be010fbdf84300531b806fa8855f57bbf727b7.tar.gz iced-04be010fbdf84300531b806fa8855f57bbf727b7.tar.bz2 iced-04be010fbdf84300531b806fa8855f57bbf727b7.zip |
Conversion traits for palette::Srgb
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/color.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/core/src/color.rs b/core/src/color.rs index 56d5455f..c061add6 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -1,5 +1,5 @@ #[cfg(feature = "palette")] -use palette::rgb::Srgba; +use palette::rgb::{Srgb, Srgba}; /// A color in the sRGB color space. #[derive(Debug, Clone, Copy, PartialEq, Default)] @@ -164,6 +164,28 @@ impl From<Color> for Srgba { } #[cfg(feature = "palette")] +/// Convert from palette's [`Srgb`] type to a [`Color`] +/// +/// [`Srgb`]: ../palette/rgb/type.Srgb.html +/// [`Color`]: struct.Color.html +impl From<Srgb> for Color { + fn from(srgb: Srgb) -> Self { + Color::new(srgb.red, srgb.green, srgb.blue, 1.0) + } +} + +#[cfg(feature = "palette")] +/// Convert from [`Color`] to palette's [`Srgb`] type +/// +/// [`Color`]: struct.Color.html +/// [`Srgb`]: ../palette/rgb/type.Srgb.html +impl From<Color> for Srgb { + fn from(c: Color) -> Self { + Srgb::new(c.r, c.g, c.b) + } +} + +#[cfg(feature = "palette")] #[cfg(test)] mod tests { use super::*; |