1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use super::super::super::widget::image;
use vek::Rgba;

/// Container Border
#[derive(Clone, Copy)]
pub enum Border {
    DoubleCornerless {
        inner: Rgba<u8>,
        outer: Rgba<u8>,
    },
    Image {
        corner: image::Handle,
        edge: image::Handle,
    },
    None,
}

/// Background of the container
#[derive(Clone, Copy)]
pub enum Style {
    Image(image::Handle, Rgba<u8>),
    Color(Rgba<u8>, Border),
    None,
}

impl Style {
    /// Shorthand for common case where the color of the image is not modified
    pub fn image(image: image::Handle) -> Self { Self::Image(image, Rgba::broadcast(255)) }

    /// Shorthand for a color background with no border
    pub fn color(color: Rgba<u8>) -> Self { Self::Color(color, Border::None) }

    /// Shorthand for a color background with a cornerless border
    pub fn color_with_double_cornerless_border(
        color: Rgba<u8>,
        inner: Rgba<u8>,
        outer: Rgba<u8>,
    ) -> Self {
        Self::Color(color, Border::DoubleCornerless { inner, outer })
    }

    /// Shorthand for a color background with image borders where the corners
    /// are inset
    pub fn color_with_image_border(
        color: Rgba<u8>,
        corner: image::Handle,
        edge: image::Handle,
    ) -> Self {
        Self::Color(color, Border::Image { corner, edge })
    }
}

impl Default for Style {
    fn default() -> Self { Self::None }
}