summaryrefslogtreecommitdiff
path: root/src/layout/background.rs
blob: bb155073fab323a859f90e6a78c00b2afa0d022c (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
use super::*;

/// A node that places a rectangular filled background behind its child.
#[derive(Debug, Clone, PartialEq)]
pub struct BackgroundNode {
    /// The background fill.
    pub fill: Fill,
    /// The child node to be filled.
    pub child: Node,
}

impl Layout for BackgroundNode {
    fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Fragment {
        let mut layouted = self.child.layout(ctx, areas);

        for frame in layouted.frames_mut() {
            let element = Element::Geometry(Geometry {
                shape: Shape::Rect(frame.size),
                fill: self.fill,
            });
            frame.elements.insert(0, (Point::ZERO, element));
        }

        layouted
    }
}

impl From<BackgroundNode> for AnyNode {
    fn from(background: BackgroundNode) -> Self {
        Self::new(background)
    }
}