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
use crate::{Renderable};
use crate::node::{Node, NodeContainer};
use std::borrow::BorrowMut;
use crate::DefaultModifiers;
use crate::components::{Appendable, ChildContainer};
#[derive(Debug, Clone)]
pub enum CardStyle {
Outlined,
Filled,
Raised,
}
#[derive(Debug, Clone)]
pub struct Card {
children: Vec<Box<dyn Renderable>>,
node: Node,
pub style: CardStyle,
}
impl Card {
pub fn new(style: CardStyle) -> Self {
Card {
children: vec![],
node: Node::default(),
style: style.clone(),
}
}
pub fn action(&mut self, url: &str) -> Self {
self
.tag("a")
.set_attr("href", url)
.add_class("clickable")
.clone()
}
}
impl NodeContainer for Card {
fn get_node(&mut self) -> &mut Node {
self.node.borrow_mut()
}
}
impl DefaultModifiers<Card> for Card {}
impl ChildContainer for Card {
fn get_children(&mut self) -> &mut Vec<Box<dyn Renderable>> {
return self.children.borrow_mut();
}
}
impl Appendable for Card {}
impl Renderable for Card {
fn render(&self) -> Node {
let mut view = self.clone()
.add_class("card")
.add_class(format!("card--{:?}", self.style).to_lowercase().as_str())
.node;
self.children.iter()
.for_each(|child|
view.children.push(child.render()));
view
}
}