blob: 2e28e560fde9847376789cefed85d67a6f23bcff (
plain) (
tree)
|
|
use crate::gradient::{self, Gradient};
use crate::Color;
/// The background of some element.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Background {
/// A solid color.
Color(Color),
/// Linearly interpolate between several colors.
Gradient(Gradient),
// 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)
}
}
impl From<Gradient> for Background {
fn from(gradient: Gradient) -> Self {
Background::Gradient(gradient)
}
}
impl From<gradient::Linear> for Background {
fn from(gradient: gradient::Linear) -> Self {
Background::Gradient(Gradient::Linear(gradient))
}
}
|