@@ -4,7 +4,9 @@ use iced::{
44 alignment, Alignment , Color , Element , Length , Point , Rectangle , Renderer ,
55 Sandbox , Settings , Size , Vector ,
66} ;
7- use palette:: { self , convert:: FromColor , Hsl , Srgb } ;
7+ use palette:: {
8+ self , convert:: FromColor , rgb:: Rgb , Darken , Hsl , Lighten , ShiftHue ,
9+ } ;
810use std:: marker:: PhantomData ;
911use std:: ops:: RangeInclusive ;
1012
@@ -49,12 +51,12 @@ impl Sandbox for ColorPalette {
4951
5052 fn update ( & mut self , message : Message ) {
5153 let srgb = match message {
52- Message :: RgbColorChanged ( rgb) => palette :: Srgb :: from ( rgb) ,
53- Message :: HslColorChanged ( hsl) => palette :: Srgb :: from_color ( hsl) ,
54- Message :: HsvColorChanged ( hsv) => palette :: Srgb :: from_color ( hsv) ,
55- Message :: HwbColorChanged ( hwb) => palette :: Srgb :: from_color ( hwb) ,
56- Message :: LabColorChanged ( lab) => palette :: Srgb :: from_color ( lab) ,
57- Message :: LchColorChanged ( lch) => palette :: Srgb :: from_color ( lch) ,
54+ Message :: RgbColorChanged ( rgb) => Rgb :: from ( rgb) ,
55+ Message :: HslColorChanged ( hsl) => Rgb :: from_color ( hsl) ,
56+ Message :: HsvColorChanged ( hsv) => Rgb :: from_color ( hsv) ,
57+ Message :: HwbColorChanged ( hwb) => Rgb :: from_color ( hwb) ,
58+ Message :: LabColorChanged ( lab) => Rgb :: from_color ( lab) ,
59+ Message :: LchColorChanged ( lch) => Rgb :: from_color ( lch) ,
5860 } ;
5961
6062 self . theme = Theme :: new ( srgb) ;
@@ -63,7 +65,7 @@ impl Sandbox for ColorPalette {
6365 fn view ( & self ) -> Element < Message > {
6466 let base = self . theme . base ;
6567
66- let srgb = palette :: Srgb :: from ( base) ;
68+ let srgb = Rgb :: from ( base) ;
6769 let hsl = palette:: Hsl :: from_color ( srgb) ;
6870 let hsv = palette:: Hsv :: from_color ( srgb) ;
6971 let hwb = palette:: Hwb :: from_color ( srgb) ;
@@ -95,12 +97,10 @@ struct Theme {
9597
9698impl Theme {
9799 pub fn new ( base : impl Into < Color > ) -> Theme {
98- use palette:: { Hue , Shade } ;
99-
100100 let base = base. into ( ) ;
101101
102102 // Convert to HSL color for manipulation
103- let hsl = Hsl :: from_color ( Srgb :: from ( base) ) ;
103+ let hsl = Hsl :: from_color ( Rgb :: from ( base) ) ;
104104
105105 let lower = [
106106 hsl. shift_hue ( -135.0 ) . lighten ( 0.075 ) ,
@@ -119,12 +119,12 @@ impl Theme {
119119 Theme {
120120 lower : lower
121121 . iter ( )
122- . map ( |& color| Srgb :: from_color ( color) . into ( ) )
122+ . map ( |& color| Rgb :: from_color ( color) . into ( ) )
123123 . collect ( ) ,
124124 base,
125125 higher : higher
126126 . iter ( )
127- . map ( |& color| Srgb :: from_color ( color) . into ( ) )
127+ . map ( |& color| Rgb :: from_color ( color) . into ( ) )
128128 . collect ( ) ,
129129 canvas_cache : canvas:: Cache :: default ( ) ,
130130 }
@@ -209,14 +209,14 @@ impl Theme {
209209
210210 text. vertical_alignment = alignment:: Vertical :: Bottom ;
211211
212- let hsl = Hsl :: from_color ( Srgb :: from ( self . base ) ) ;
212+ let hsl = Hsl :: from_color ( Rgb :: from ( self . base ) ) ;
213213 for i in 0 ..self . len ( ) {
214214 let pct = ( i as f32 + 1.0 ) / ( self . len ( ) as f32 + 1.0 ) ;
215215 let graded = Hsl {
216216 lightness : 1.0 - pct,
217217 ..hsl
218218 } ;
219- let color: Color = Srgb :: from_color ( graded) . into ( ) ;
219+ let color: Color = Rgb :: from_color ( graded) . into ( ) ;
220220
221221 let anchor = Point {
222222 x : ( i as f32 ) * box_size. width ,
@@ -352,7 +352,7 @@ impl ColorSpace for palette::Hsl {
352352
353353 fn components ( & self ) -> [ f32 ; 3 ] {
354354 [
355- self . hue . to_positive_degrees ( ) ,
355+ self . hue . into_positive_degrees ( ) ,
356356 self . saturation ,
357357 self . lightness ,
358358 ]
@@ -361,7 +361,7 @@ impl ColorSpace for palette::Hsl {
361361 fn to_string ( & self ) -> String {
362362 format ! (
363363 "hsl({:.1}, {:.1}%, {:.1}%)" ,
364- self . hue. to_positive_degrees ( ) ,
364+ self . hue. into_positive_degrees ( ) ,
365365 100.0 * self . saturation,
366366 100.0 * self . lightness
367367 )
@@ -378,13 +378,17 @@ impl ColorSpace for palette::Hsv {
378378 }
379379
380380 fn components ( & self ) -> [ f32 ; 3 ] {
381- [ self . hue . to_positive_degrees ( ) , self . saturation , self . value ]
381+ [
382+ self . hue . into_positive_degrees ( ) ,
383+ self . saturation ,
384+ self . value ,
385+ ]
382386 }
383387
384388 fn to_string ( & self ) -> String {
385389 format ! (
386390 "hsv({:.1}, {:.1}%, {:.1}%)" ,
387- self . hue. to_positive_degrees ( ) ,
391+ self . hue. into_positive_degrees ( ) ,
388392 100.0 * self . saturation,
389393 100.0 * self . value
390394 )
@@ -406,7 +410,7 @@ impl ColorSpace for palette::Hwb {
406410
407411 fn components ( & self ) -> [ f32 ; 3 ] {
408412 [
409- self . hue . to_positive_degrees ( ) ,
413+ self . hue . into_positive_degrees ( ) ,
410414 self . whiteness ,
411415 self . blackness ,
412416 ]
@@ -415,7 +419,7 @@ impl ColorSpace for palette::Hwb {
415419 fn to_string ( & self ) -> String {
416420 format ! (
417421 "hwb({:.1}, {:.1}%, {:.1}%)" ,
418- self . hue. to_positive_degrees ( ) ,
422+ self . hue. into_positive_degrees ( ) ,
419423 100.0 * self . whiteness,
420424 100.0 * self . blackness
421425 )
@@ -450,15 +454,15 @@ impl ColorSpace for palette::Lch {
450454 }
451455
452456 fn components ( & self ) -> [ f32 ; 3 ] {
453- [ self . l , self . chroma , self . hue . to_positive_degrees ( ) ]
457+ [ self . l , self . chroma , self . hue . into_positive_degrees ( ) ]
454458 }
455459
456460 fn to_string ( & self ) -> String {
457461 format ! (
458462 "Lch({:.1}, {:.1}, {:.1})" ,
459463 self . l,
460464 self . chroma,
461- self . hue. to_positive_degrees ( )
465+ self . hue. into_positive_degrees ( )
462466 )
463467 }
464468}
0 commit comments