summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-26 19:02:29 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-26 19:02:29 +0200
commitfcb1b454368638209862aeb5db41bc5f7d6d51a7 (patch)
treef3ae3169ddaf545a8de27d74718908f3c0d3f760 /core/src
parentc61a4cc21ca4d5019cd10df2f316ebbdb24061f1 (diff)
parentcf2c8f2037907d8d619348a70594bab28f166d64 (diff)
downloadiced-fcb1b454368638209862aeb5db41bc5f7d6d51a7.tar.gz
iced-fcb1b454368638209862aeb5db41bc5f7d6d51a7.tar.bz2
iced-fcb1b454368638209862aeb5db41bc5f7d6d51a7.zip
Merge pull request #1875 from clarkmoody/palette-0.7
Upgrade `palette` dependency
Diffstat (limited to 'core/src')
-rw-r--r--core/src/color.rs40
1 files changed, 19 insertions, 21 deletions
diff --git a/core/src/color.rs b/core/src/color.rs
index fe0a1856..1392f28b 100644
--- a/core/src/color.rs
+++ b/core/src/color.rs
@@ -183,15 +183,15 @@ macro_rules! color {
}
#[cfg(feature = "palette")]
-/// Converts from palette's `Srgba` type to a [`Color`].
+/// Converts from palette's `Rgba` type to a [`Color`].
impl From<Srgba> for Color {
- fn from(srgba: Srgba) -> Self {
- Color::new(srgba.red, srgba.green, srgba.blue, srgba.alpha)
+ fn from(rgba: Srgba) -> Self {
+ Color::new(rgba.red, rgba.green, rgba.blue, rgba.alpha)
}
}
#[cfg(feature = "palette")]
-/// Converts from [`Color`] to palette's `Srgba` type.
+/// Converts from [`Color`] to palette's `Rgba` type.
impl From<Color> for Srgba {
fn from(c: Color) -> Self {
Srgba::new(c.r, c.g, c.b, c.a)
@@ -199,15 +199,15 @@ impl From<Color> for Srgba {
}
#[cfg(feature = "palette")]
-/// Converts from palette's `Srgb` type to a [`Color`].
+/// Converts from palette's `Rgb` type to a [`Color`].
impl From<Srgb> for Color {
- fn from(srgb: Srgb) -> Self {
- Color::new(srgb.red, srgb.green, srgb.blue, 1.0)
+ fn from(rgb: Srgb) -> Self {
+ Color::new(rgb.red, rgb.green, rgb.blue, 1.0)
}
}
#[cfg(feature = "palette")]
-/// Converts from [`Color`] to palette's `Srgb` type.
+/// Converts from [`Color`] to palette's `Rgb` type.
impl From<Color> for Srgb {
fn from(c: Color) -> Self {
Srgb::new(c.r, c.g, c.b)
@@ -218,12 +218,12 @@ impl From<Color> for Srgb {
#[cfg(test)]
mod tests {
use super::*;
- use palette::Blend;
+ use palette::blend::Blend;
#[test]
fn srgba_traits() {
let c = Color::from_rgb(0.5, 0.4, 0.3);
- // Round-trip conversion to the palette:Srgba type
+ // Round-trip conversion to the palette::Srgba type
let s: Srgba = c.into();
let r: Color = s.into();
assert_eq!(c, r);
@@ -231,6 +231,8 @@ mod tests {
#[test]
fn color_manipulation() {
+ use approx::assert_relative_eq;
+
let c1 = Color::from_rgb(0.5, 0.4, 0.3);
let c2 = Color::from_rgb(0.2, 0.5, 0.3);
@@ -238,19 +240,15 @@ mod tests {
let l1 = Srgba::from(c1).into_linear();
let l2 = Srgba::from(c2).into_linear();
- // Take the lighter of each of the RGB components
+ // Take the lighter of each of the sRGB components
let lighter = l1.lighten(l2);
// Convert back to our Color
- let r: Color = Srgba::from_linear(lighter).into();
- assert_eq!(
- r,
- Color {
- r: 0.5,
- g: 0.5,
- b: 0.3,
- a: 1.0
- }
- );
+ let result: Color = Srgba::from_linear(lighter).into();
+
+ assert_relative_eq!(result.r, 0.5);
+ assert_relative_eq!(result.g, 0.5);
+ assert_relative_eq!(result.b, 0.3);
+ assert_relative_eq!(result.a, 1.0);
}
}