Simplify theming for Button widget
This commit is contained in:
parent
db92e1c942
commit
f4a4845ddb
16 changed files with 306 additions and 412 deletions
|
|
@ -11,6 +11,19 @@ pub enum Background {
|
|||
// TODO: Add image variant
|
||||
}
|
||||
|
||||
impl Background {
|
||||
/// Increases the translucency of the [`Background`]
|
||||
/// by the given factor.
|
||||
pub fn transparentize(self, factor: f32) -> Self {
|
||||
match self {
|
||||
Self::Color(color) => Self::Color(color.transparentize(factor)),
|
||||
Self::Gradient(gradient) => {
|
||||
Self::Gradient(gradient.transparentize(factor))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Color> for Background {
|
||||
fn from(color: Color) -> Self {
|
||||
Background::Color(color)
|
||||
|
|
|
|||
|
|
@ -151,6 +151,14 @@ impl Color {
|
|||
pub fn inverse(self) -> 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 {
|
||||
Self {
|
||||
a: self.a * factor,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[f32; 3]> for Color {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue