diff options
-rw-r--r-- | core/src/background.rs | 10 | ||||
-rw-r--r-- | core/src/color.rs | 4 | ||||
-rw-r--r-- | core/src/gradient.rs | 22 | ||||
-rw-r--r-- | widget/src/button.rs | 6 |
4 files changed, 24 insertions, 18 deletions
diff --git a/core/src/background.rs b/core/src/background.rs index 2e28e560..eb4b5021 100644 --- a/core/src/background.rs +++ b/core/src/background.rs @@ -12,13 +12,13 @@ pub enum Background { } impl Background { - /// Increases the translucency of the [`Background`] - /// by the given factor. - pub fn transparentize(self, factor: f32) -> Self { + /// Scales the the alpha channel of the [`Background`] by the given + /// factor. + pub fn scale_alpha(self, factor: f32) -> Self { match self { - Self::Color(color) => Self::Color(color.transparentize(factor)), + Self::Color(color) => Self::Color(color.scale_alpha(factor)), Self::Gradient(gradient) => { - Self::Gradient(gradient.transparentize(factor)) + Self::Gradient(gradient.scale_alpha(factor)) } } } diff --git a/core/src/color.rs b/core/src/color.rs index da40ca15..4e79defb 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -151,8 +151,8 @@ impl Color { Color::new(1.0f32 - self.r, 1.0f32 - self.g, 1.0f32 - self.b, self.a) } - /// Transparentizes the [`Color`] by the given factor. - pub fn transparentize(self, factor: f32) -> Color { + /// Scales the alpha channel of the [`Color`] by the given factor. + pub fn scale_alpha(self, factor: f32) -> Color { Self { a: self.a * factor, ..self 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 + } } diff --git a/widget/src/button.rs b/widget/src/button.rs index 243eaf04..e265aa1f 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -537,7 +537,7 @@ pub fn text(theme: &Theme, status: Status) -> Appearance { match status { Status::Active | Status::Pressed => base, Status::Hovered => Appearance { - text_color: palette.background.base.text.transparentize(0.8), + text_color: palette.background.base.text.scale_alpha(0.8), ..base }, Status::Disabled => disabled(base), @@ -557,8 +557,8 @@ fn disabled(appearance: Appearance) -> Appearance { Appearance { background: appearance .background - .map(|background| background.transparentize(0.5)), - text_color: appearance.text_color.transparentize(0.5), + .map(|background| background.scale_alpha(0.5)), + text_color: appearance.text_color.scale_alpha(0.5), ..appearance } } |