diff options
author | 2024-03-08 13:40:10 +0100 | |
---|---|---|
committer | 2024-03-08 13:40:10 +0100 | |
commit | 3e99f39a8680bb48d5c15b043c399a3337765ae5 (patch) | |
tree | fbf1dd4d7fbe5f64c6931dbc933c0c21dfffc120 /core/src/gradient.rs | |
parent | 288025f5143f4e3f8bc5af36e86f7afa7f07a4c7 (diff) | |
download | iced-3e99f39a8680bb48d5c15b043c399a3337765ae5.tar.gz iced-3e99f39a8680bb48d5c15b043c399a3337765ae5.tar.bz2 iced-3e99f39a8680bb48d5c15b043c399a3337765ae5.zip |
Rename `transparentize` to `scale_alpha`
Diffstat (limited to 'core/src/gradient.rs')
-rw-r--r-- | core/src/gradient.rs | 22 |
1 files changed, 14 insertions, 8 deletions
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 + } } |