@@ -67,6 +67,7 @@ impl FocusRing {
6767 alpha : f32 ,
6868 exponent : f32 ,
6969 gradient_angle_offset : f32 ,
70+ mix_ratio : f32 ,
7071 ) {
7172 let width = self . config . width ;
7273 self . full_size = win_size + Size :: from ( ( width, width) ) . upscale ( 2. ) ;
@@ -86,6 +87,24 @@ impl FocusRing {
8687
8788 let radius = radius. fit_to ( self . full_size . w as f32 , self . full_size . h as f32 ) ;
8889
90+ fn mix_color ( active : Gradient , inactive : Gradient , mix_ratio : f32 ) -> Gradient {
91+ let t = mix_ratio;
92+ let inv = 1. - mix_ratio;
93+
94+ let mut new = active. clone ( ) ;
95+ new. from . r = active. from . r * t + inactive. from . r * inv;
96+ new. from . g = active. from . g * t + inactive. from . g * inv;
97+ new. from . b = active. from . b * t + inactive. from . b * inv;
98+ new. from . a = active. from . a * t + inactive. from . a * inv;
99+
100+ new. to . r = active. to . r * t + inactive. to . r * inv;
101+ new. to . g = active. to . g * t + inactive. to . g * inv;
102+ new. to . b = active. to . b * t + inactive. to . b * inv;
103+ new. to . a = active. to . a * t + inactive. to . a * inv;
104+
105+ new
106+ }
107+
89108 let gradient = if is_urgent {
90109 self . config . urgent_gradient
91110 } else if is_active {
@@ -97,7 +116,38 @@ impl FocusRing {
97116 self . use_border_shader = radius != CornerRadius :: default ( ) || gradient. is_some ( ) ;
98117
99118 // Set the defaults for solid color + rounded corners.
100- let gradient = gradient. unwrap_or_else ( || Gradient :: from ( color) ) ;
119+ // let gradient = gradient.unwrap_or_else(|| Gradient::from(color));
120+ let gradient = if is_urgent {
121+ mix_color (
122+ self . config
123+ . urgent_gradient
124+ . unwrap_or_else ( || Gradient :: from ( self . config . urgent_color ) ) ,
125+ self . config
126+ . inactive_gradient
127+ . unwrap_or_else ( || Gradient :: from ( self . config . inactive_color ) ) ,
128+ mix_ratio,
129+ )
130+ } else if is_active {
131+ mix_color (
132+ self . config
133+ . active_gradient
134+ . unwrap_or_else ( || Gradient :: from ( self . config . active_color ) ) ,
135+ self . config
136+ . inactive_gradient
137+ . unwrap_or_else ( || Gradient :: from ( self . config . inactive_color ) ) ,
138+ mix_ratio,
139+ )
140+ } else {
141+ mix_color (
142+ self . config
143+ . active_gradient
144+ . unwrap_or_else ( || Gradient :: from ( self . config . active_color ) ) ,
145+ self . config
146+ . inactive_gradient
147+ . unwrap_or_else ( || Gradient :: from ( self . config . inactive_color ) ) ,
148+ mix_ratio,
149+ )
150+ } ;
101151
102152 let full_rect = Rectangle :: new ( Point :: from ( ( -width, -width) ) , self . full_size ) ;
103153 let gradient_area = match gradient. relative_to {
0 commit comments