iced_core/
background.rs

1use crate::Color;
2use crate::gradient::{self, Gradient};
3
4/// The background of some element.
5#[derive(Debug, Clone, Copy, PartialEq)]
6pub enum Background {
7    /// A solid color.
8    Color(Color),
9    /// Linearly interpolate between several colors.
10    Gradient(Gradient),
11    // TODO: Add image variant
12}
13
14impl Background {
15    /// Scales the alpha channel of the [`Background`] by the given
16    /// factor.
17    pub fn scale_alpha(self, factor: f32) -> Self {
18        match self {
19            Self::Color(color) => Self::Color(color.scale_alpha(factor)),
20            Self::Gradient(gradient) => Self::Gradient(gradient.scale_alpha(factor)),
21        }
22    }
23}
24
25impl From<Color> for Background {
26    fn from(color: Color) -> Self {
27        Background::Color(color)
28    }
29}
30
31impl From<Gradient> for Background {
32    fn from(gradient: Gradient) -> Self {
33        Background::Gradient(gradient)
34    }
35}
36
37impl From<gradient::Linear> for Background {
38    fn from(gradient: gradient::Linear) -> Self {
39        Background::Gradient(Gradient::Linear(gradient))
40    }
41}