summaryrefslogtreecommitdiffstats
path: root/web/src/widget/empty.rs
blob: dda17efe1613d8fd7b89eac2d656afb85ab95fb8 (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
61
62
63
64
65
66
67
68
69
70
use crate::{style, Bus, Element, Length, Widget};
use dodrio::bumpalo;

/// An amount of empty space.
///
/// It can be useful if you want to fill some space with nothing.
///
/// [`Empty`]: struct.Empty.html
#[derive(Debug)]
pub struct Empty {
    width: Length,
    height: Length,
}

impl Empty {
    /// Creates an amount of [`Empty`] space.
    ///
    /// [`Empty`]: struct.Empty.html
    pub fn new() -> Self {
        Empty {
            width: Length::Shrink,
            height: Length::Shrink,
        }
    }

    /// Sets the width of the [`Empty`] space.
    ///
    /// [`Empty`]: struct..html
    pub fn width(mut self, width: Length) -> Self {
        self.width = width;
        self
    }

    /// Sets the height of the [`Empty`] space.
    ///
    /// [`Empty`]: struct.Column.html
    pub fn height(mut self, height: Length) -> Self {
        self.height = height;
        self
    }
}

impl<'a, Message> Widget<Message> for Empty {
    fn node<'b>(
        &self,
        bump: &'b bumpalo::Bump,
        _publish: &Bus<Message>,
        _style_sheet: &mut style::Sheet<'b>,
    ) -> dodrio::Node<'b> {
        use dodrio::builder::*;

        let width = style::length(self.width);
        let height = style::length(self.height);

        let style = bumpalo::format!(
            in bump,
            "width: {}; height: {};",
            width,
            height
        );

        div(bump).attr("style", style.into_bump_str()).finish()
    }
}

impl<'a, Message> From<Empty> for Element<'a, Message> {
    fn from(empty: Empty) -> Element<'a, Message> {
        Element::new(empty)
    }
}