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
71
72
73
74
75
76
77
78
79
80
81
82
83
use crate::theme::Theme;
use seed::prelude::*;

/// This is the main trait used to render elments
pub trait Render<PMsg: 'static> {
    /// the returne type from `render` function
    type View: View<PMsg>;
    type Style;

    /// Return style for the current state of the element
    fn style(&self, theme: &impl Theme) -> Self::Style;

    /// This is the function used to render element and returne `Self::View`
    ///
    /// # Arguments
    /// `Theme` used to get the current style for the element
    fn render(&self, theme: &impl Theme) -> Self::View {
        self.render_with_style(theme, self.style(theme))
    }

    /// This is the main function used to render element with the passed style
    fn render_with_style(&self, _: &impl Theme, _: Self::Style) -> Self::View;
}

impl<PMsg: 'static> Render<PMsg> for Node<PMsg> {
    type View = Node<PMsg>;
    type Style = ();

    fn style(&self, _: &impl Theme) -> Self::Style {
        ()
    }

    fn render_with_style(&self, _: &impl Theme, _: Self::Style) -> Self::View {
        self.clone()
    }
}

impl<PMsg: 'static> Render<PMsg> for Vec<Node<PMsg>> {
    type View = Vec<Node<PMsg>>;
    type Style = ();

    fn style(&self, _: &impl Theme) -> Self::Style {
        ()
    }

    fn render_with_style(&self, _: &impl Theme, _: Self::Style) -> Self::View {
        self.clone()
    }
}

impl<PMsg: 'static> Render<PMsg> for El<PMsg> {
    type View = El<PMsg>;
    type Style = ();

    fn style(&self, _: &impl Theme) -> Self::Style {
        ()
    }

    fn render_with_style(&self, _: &impl Theme, _: Self::Style) -> Self::View {
        self.clone()
    }
}

impl<PMsg: 'static> Render<PMsg> for Vec<El<PMsg>> {
    type View = Vec<El<PMsg>>;
    type Style = ();

    fn style(&self, _: &impl Theme) -> Self::Style {
        ()
    }

    fn render_with_style(&self, _: &impl Theme, _: Self::Style) -> Self::View {
        self.clone()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_name() {}
}