From f4a4845ddbdced81ae4ff60bfa19f0e602d84709 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 4 Mar 2024 20:42:37 +0100 Subject: Simplify theming for `Button` widget --- core/src/gradient.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/src/gradient.rs') diff --git a/core/src/gradient.rs b/core/src/gradient.rs index 4711b044..ecf7830f 100644 --- a/core/src/gradient.rs +++ b/core/src/gradient.rs @@ -13,11 +13,11 @@ pub enum Gradient { impl Gradient { /// Adjust the opacity of the gradient by a multiplier applied to each color stop. - pub fn mul_alpha(mut self, alpha_multiplier: f32) -> Self { + pub fn transparentize(mut self, factor: f32) -> Self { match &mut self { Gradient::Linear(linear) => { for stop in linear.stops.iter_mut().flatten() { - stop.color.a *= alpha_multiplier; + stop.color.a *= factor; } } } -- cgit From 3e99f39a8680bb48d5c15b043c399a3337765ae5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Mar 2024 13:40:10 +0100 Subject: Rename `transparentize` to `scale_alpha` --- core/src/gradient.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'core/src/gradient.rs') diff --git a/core/src/gradient.rs b/core/src/gradient.rs index ecf7830f..ccae0bce 100644 --- a/core/src/gradient.rs +++ b/core/src/gradient.rs @@ -12,17 +12,13 @@ pub enum Gradient { } impl Gradient { - /// Adjust the opacity of the gradient by a multiplier applied to each color stop. - pub fn transparentize(mut self, factor: f32) -> Self { - match &mut self { + /// Scales the alpha channel of the [`Gradient`] by the given factor. + pub fn scale_alpha(self, factor: f32) -> Self { + match self { Gradient::Linear(linear) => { - for stop in linear.stops.iter_mut().flatten() { - stop.color.a *= factor; - } + Gradient::Linear(linear.scale_alpha(factor)) } } - - self } } @@ -100,4 +96,14 @@ impl Linear { self } + + /// Scales the alpha channel of the [`Linear`] gradient by the given + /// factor. + pub fn scale_alpha(mut self, factor: f32) -> Self { + for stop in self.stops.iter_mut().flatten() { + stop.color.a *= factor; + } + + self + } } -- cgit