summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-01 21:51:08 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-01 21:51:08 +0200
commit0a011f90313dfbd77da5fdaa58bd93924ba7625c (patch)
treea93a26729c59689adfe355c4c3e7f93b3157780a
parent11e4039b5644606e40d603397f1039686ecd6fe5 (diff)
downloadiced-0a011f90313dfbd77da5fdaa58bd93924ba7625c.tar.gz
iced-0a011f90313dfbd77da5fdaa58bd93924ba7625c.tar.bz2
iced-0a011f90313dfbd77da5fdaa58bd93924ba7625c.zip
Improve `generate_theme` in `color_palette`
Diffstat (limited to '')
-rw-r--r--examples/color_palette/src/main.rs42
1 files changed, 15 insertions, 27 deletions
diff --git a/examples/color_palette/src/main.rs b/examples/color_palette/src/main.rs
index 46a4d085..12c24a64 100644
--- a/examples/color_palette/src/main.rs
+++ b/examples/color_palette/src/main.rs
@@ -21,36 +21,24 @@ pub struct State {
fn generate_theme(base_color: &Color) -> Vec<Color> {
use palette::{Hsl, Hue, Shade, Srgb};
- let mut theme = Vec::<Color>::new();
+
// Convert to HSL color for manipulation
let hsl = Hsl::from(Srgb::from(*base_color));
- theme.push(
- Srgb::from(hsl.shift_hue(-135.0).lighten(0.075))
- .clamp()
- .into(),
- );
- theme.push(Srgb::from(hsl.shift_hue(-120.0)).clamp().into());
- theme.push(
- Srgb::from(hsl.shift_hue(-105.0).darken(0.075))
- .clamp()
- .into(),
- );
- theme.push(Srgb::from(hsl.darken(0.075)).clamp().into());
- theme.push(*base_color);
- theme.push(Srgb::from(hsl.lighten(0.075)).clamp().into());
- theme.push(
- Srgb::from(hsl.shift_hue(105.0).darken(0.075))
- .clamp()
- .into(),
- );
- theme.push(Srgb::from(hsl.shift_hue(120.0)).clamp().into());
- theme.push(
- Srgb::from(hsl.shift_hue(135.0).lighten(0.075))
- .clamp()
- .into(),
- );
- theme
+ [
+ hsl.shift_hue(-135.0).lighten(0.075),
+ hsl.shift_hue(-120.0),
+ hsl.shift_hue(-105.0).darken(0.075),
+ hsl.darken(0.075),
+ hsl,
+ hsl.lighten(0.075),
+ hsl.shift_hue(105.0).darken(0.075),
+ hsl.shift_hue(120.0),
+ hsl.shift_hue(135.0).lighten(0.075),
+ ]
+ .iter()
+ .map(|&color| Srgb::from(color).clamp().into())
+ .collect()
}
struct ColorPicker<C: ColorSpace> {