summaryrefslogtreecommitdiffstats
path: root/core/src/background/background_image.rs
blob: 75d63dfc425a3ba8803139f02f87e9b85013fa7a (plain) (blame)
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
56
57
58
59
60
use crate::{Image, Point, Size};

/// A background image.
#[derive(Debug, Clone, PartialEq)]
pub struct BackgroundImage {
    // TODO: svg support
    image: Image,
    attachment: Attachment,
    clip: Sizing,
    origin: Sizing,
    /// (x, y)
    repeat: (Repeat, Repeat),
    size: Size,
    // filter_method: FilterMethod,
    // opacity: f32,
    // TODO: blend mode
}

impl BackgroundImage {
    /// Scales the opacity  of the [`BackgroundImage`] by the given factor.
    pub fn scale_opacity(mut self, factor: f32) -> Self {
        let opacity = self.image.opacity * factor;
        self.image = self.image.opacity(opacity);
        self
    }
}

/// An attachment property.
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum Attachment {
    /// Fixed relative to the viewport.
    Fixed,
    /// Fixed relative to self.
    #[default]
    Local,
}

/// A sizing property.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Sizing {
    /// At outside edge of border.
    Border,
    /// At outside edge of padding.
    Padding,
    /// At outside edge of content.
    Content,
}

/// A repetition property.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Repeat {
    /// Repeat beginning at offset. Will be clipped if necessary.
    Repeat(Point),
    /// Repeated as much as possible without clipping. Whitespace is evenly distributed between each instance.
    Space,
    /// Repeated as much as possible without clipping. Stretched until there is room for another to be added.
    Round,
    /// No repetition. Position defined by point. Will be clipped if necessary.
    NoRepeat(Point),
}