@@ -510,7 +510,7 @@ pub struct Primary {
510510impl Primary {
511511 /// Generates a set of [`Primary`] colors from the base, background, and text colors.
512512 pub fn generate ( base : Color , background : Color , text : Color ) -> Self {
513- let weak = mix ( base , background, 0.4 ) ;
513+ let weak = base . mix ( background, 0.4 ) ;
514514 let strong = deviate ( base, 0.1 ) ;
515515
516516 Self {
@@ -537,9 +537,9 @@ impl Secondary {
537537 pub fn generate ( base : Color , text : Color ) -> Self {
538538 let factor = if is_dark ( base) { 0.2 } else { 0.4 } ;
539539
540- let weak = mix ( deviate ( base, 0.1 ) , text, factor) ;
541- let strong = mix ( deviate ( base, 0.3 ) , text, factor) ;
542- let base = mix ( deviate ( base, 0.2 ) , text, factor) ;
540+ let weak = deviate ( base, 0.1 ) . mix ( text, factor) ;
541+ let strong = deviate ( base, 0.3 ) . mix ( text, factor) ;
542+ let base = deviate ( base, 0.2 ) . mix ( text, factor) ;
543543
544544 Self {
545545 base : Pair :: new ( base, text) ,
@@ -563,7 +563,7 @@ pub struct Success {
563563impl Success {
564564 /// Generates a set of [`Success`] colors from the base, background, and text colors.
565565 pub fn generate ( base : Color , background : Color , text : Color ) -> Self {
566- let weak = mix ( base , background, 0.4 ) ;
566+ let weak = base . mix ( background, 0.4 ) ;
567567 let strong = deviate ( base, 0.1 ) ;
568568
569569 Self {
@@ -588,7 +588,7 @@ pub struct Warning {
588588impl Warning {
589589 /// Generates a set of [`Warning`] colors from the base, background, and text colors.
590590 pub fn generate ( base : Color , background : Color , text : Color ) -> Self {
591- let weak = mix ( base , background, 0.4 ) ;
591+ let weak = base . mix ( background, 0.4 ) ;
592592 let strong = deviate ( base, 0.1 ) ;
593593
594594 Self {
@@ -613,7 +613,7 @@ pub struct Danger {
613613impl Danger {
614614 /// Generates a set of [`Danger`] colors from the base, background, and text colors.
615615 pub fn generate ( base : Color , background : Color , text : Color ) -> Self {
616- let weak = mix ( base , background, 0.4 ) ;
616+ let weak = base . mix ( background, 0.4 ) ;
617617 let strong = deviate ( base, 0.1 ) ;
618618
619619 Self {
@@ -677,22 +677,6 @@ pub fn deviate(color: Color, amount: f32) -> Color {
677677 }
678678}
679679
680- /// Mixes two colors by the given factor.
681- pub fn mix ( a : Color , b : Color , factor : f32 ) -> Color {
682- let b_amount = factor. clamp ( 0.0 , 1.0 ) ;
683- let a_amount = 1.0 - b_amount;
684-
685- let a_linear = a. into_linear ( ) . map ( |c| c * a_amount) ;
686- let b_linear = b. into_linear ( ) . map ( |c| c * b_amount) ;
687-
688- Color :: from_linear_rgba (
689- a_linear[ 0 ] + b_linear[ 0 ] ,
690- a_linear[ 1 ] + b_linear[ 1 ] ,
691- a_linear[ 2 ] + b_linear[ 2 ] ,
692- a_linear[ 3 ] + b_linear[ 3 ] ,
693- )
694- }
695-
696680/// Computes a [`Color`] from the given text color that is
697681/// readable on top of the given background color.
698682pub fn readable ( background : Color , text : Color ) -> Color {
@@ -719,9 +703,9 @@ pub fn readable(background: Color, text: Color) -> Color {
719703 let black_contrast = background. relative_contrast ( Color :: BLACK ) ;
720704
721705 if white_contrast >= black_contrast {
722- mix ( Color :: WHITE , background, 0.05 )
706+ Color :: WHITE . mix ( background, 0.05 )
723707 } else {
724- mix ( Color :: BLACK , background, 0.05 )
708+ Color :: BLACK . mix ( background, 0.05 )
725709 }
726710}
727711
0 commit comments