2023-05-19 03:32:21 +02:00
|
|
|
use crate::gradient::{self, Gradient};
|
|
|
|
|
use crate::Color;
|
2019-10-08 03:13:41 +02:00
|
|
|
|
2019-11-18 07:16:19 +01:00
|
|
|
/// The background of some element.
|
2019-10-08 03:13:41 +02:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
|
pub enum Background {
|
2023-05-11 09:12:06 -07:00
|
|
|
/// A solid color.
|
2019-10-08 03:13:41 +02:00
|
|
|
Color(Color),
|
2023-05-11 09:12:06 -07:00
|
|
|
/// Linearly interpolate between several colors.
|
|
|
|
|
Gradient(Gradient),
|
|
|
|
|
// TODO: Add image variant
|
2019-10-08 03:13:41 +02:00
|
|
|
}
|
2019-12-04 22:02:07 +01:00
|
|
|
|
2024-03-04 20:42:37 +01:00
|
|
|
impl Background {
|
2024-03-09 15:26:37 +08:00
|
|
|
/// Scales the alpha channel of the [`Background`] by the given
|
2024-03-08 13:40:10 +01:00
|
|
|
/// factor.
|
|
|
|
|
pub fn scale_alpha(self, factor: f32) -> Self {
|
2024-03-04 20:42:37 +01:00
|
|
|
match self {
|
2024-03-08 13:40:10 +01:00
|
|
|
Self::Color(color) => Self::Color(color.scale_alpha(factor)),
|
2024-03-04 20:42:37 +01:00
|
|
|
Self::Gradient(gradient) => {
|
2024-03-08 13:40:10 +01:00
|
|
|
Self::Gradient(gradient.scale_alpha(factor))
|
2024-03-04 20:42:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 22:02:07 +01:00
|
|
|
impl From<Color> for Background {
|
|
|
|
|
fn from(color: Color) -> Self {
|
|
|
|
|
Background::Color(color)
|
|
|
|
|
}
|
2020-01-01 17:27:14 +01:00
|
|
|
}
|
2020-08-19 01:30:22 +02:00
|
|
|
|
2023-05-19 03:32:21 +02:00
|
|
|
impl From<Gradient> for Background {
|
|
|
|
|
fn from(gradient: Gradient) -> Self {
|
|
|
|
|
Background::Gradient(gradient)
|
2020-08-19 01:30:22 +02:00
|
|
|
}
|
2020-08-19 01:30:46 +02:00
|
|
|
}
|
2023-05-11 09:12:06 -07:00
|
|
|
|
2023-05-19 03:32:21 +02:00
|
|
|
impl From<gradient::Linear> for Background {
|
|
|
|
|
fn from(gradient: gradient::Linear) -> Self {
|
|
|
|
|
Background::Gradient(Gradient::Linear(gradient))
|
2023-05-11 09:12:06 -07:00
|
|
|
}
|
|
|
|
|
}
|