blob: 9843002060f584c8e0d0dac1cd67b02578a4e4bf (
plain) (
tree)
|
|
mod background_image;
use std::sync::Arc;
use background_image::BackgroundImage;
use crate::gradient::{self, Gradient};
use crate::image::{FilterMethod, Handle};
use crate::{Color, Image, Point, Rectangle, Size, image};
/// The background of some element.
#[derive(Debug, Clone, PartialEq)]
pub enum Background {
/// A solid color.
Color(Color),
/// Linearly interpolate between several colors.
Gradient(Gradient),
/// A background image.
Image(BackgroundImage),
}
impl Background {
/// Scales 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.scale_alpha(factor)),
Self::Gradient(gradient) => {
Self::Gradient(gradient.scale_alpha(factor))
}
Self::Image(background_image) => {
Self::Image(background_image.scale_opacity(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))
}
}
impl From<BackgroundImage> for Background {
fn from(background_image: BackgroundImage) -> Self {
Background::Image(background_image)
}
}
|