Rename transparentize to scale_alpha

This commit is contained in:
Héctor Ramón Jiménez 2024-03-08 13:40:10 +01:00
parent 288025f514
commit 3e99f39a86
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 24 additions and 18 deletions

View file

@ -12,13 +12,13 @@ pub enum Background {
} }
impl Background { impl Background {
/// Increases the translucency of the [`Background`] /// Scales the the alpha channel of the [`Background`] by the given
/// by the given factor. /// factor.
pub fn transparentize(self, factor: f32) -> Self { pub fn scale_alpha(self, factor: f32) -> Self {
match 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) => {
Self::Gradient(gradient.transparentize(factor)) Self::Gradient(gradient.scale_alpha(factor))
} }
} }
} }

View file

@ -151,8 +151,8 @@ impl Color {
Color::new(1.0f32 - self.r, 1.0f32 - self.g, 1.0f32 - self.b, self.a) Color::new(1.0f32 - self.r, 1.0f32 - self.g, 1.0f32 - self.b, self.a)
} }
/// Transparentizes the [`Color`] by the given factor. /// Scales the alpha channel of the [`Color`] by the given factor.
pub fn transparentize(self, factor: f32) -> Color { pub fn scale_alpha(self, factor: f32) -> Color {
Self { Self {
a: self.a * factor, a: self.a * factor,
..self ..self

View file

@ -12,18 +12,14 @@ pub enum Gradient {
} }
impl Gradient { impl Gradient {
/// Adjust the opacity of the gradient by a multiplier applied to each color stop. /// Scales the alpha channel of the [`Gradient`] by the given factor.
pub fn transparentize(mut self, factor: f32) -> Self { pub fn scale_alpha(self, factor: f32) -> Self {
match &mut self { match self {
Gradient::Linear(linear) => { Gradient::Linear(linear) => {
for stop in linear.stops.iter_mut().flatten() { Gradient::Linear(linear.scale_alpha(factor))
stop.color.a *= factor;
} }
} }
} }
self
}
} }
impl From<Linear> for Gradient { impl From<Linear> for Gradient {
@ -100,4 +96,14 @@ impl Linear {
self 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
}
} }

View file

@ -537,7 +537,7 @@ pub fn text(theme: &Theme, status: Status) -> Appearance {
match status { match status {
Status::Active | Status::Pressed => base, Status::Active | Status::Pressed => base,
Status::Hovered => Appearance { Status::Hovered => Appearance {
text_color: palette.background.base.text.transparentize(0.8), text_color: palette.background.base.text.scale_alpha(0.8),
..base ..base
}, },
Status::Disabled => disabled(base), Status::Disabled => disabled(base),
@ -557,8 +557,8 @@ fn disabled(appearance: Appearance) -> Appearance {
Appearance { Appearance {
background: appearance background: appearance
.background .background
.map(|background| background.transparentize(0.5)), .map(|background| background.scale_alpha(0.5)),
text_color: appearance.text_color.transparentize(0.5), text_color: appearance.text_color.scale_alpha(0.5),
..appearance ..appearance
} }
} }