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
use crate::{Renderable};
use crate::node::{Node, NodeContainer};
use std::borrow::BorrowMut;
use crate::{DefaultModifiers, sp};
use crate::components::{Appendable, ChildContainer};
#[derive(Debug, Clone)]
pub enum Alignment {
Center,
Start,
End,
Stretch
}
#[derive(Debug, Clone)]
pub struct VStack {
children: Vec<Box<dyn Renderable>>,
node: Node,
pub alignment: Alignment,
}
impl NodeContainer for VStack {
fn get_node(&mut self) -> &mut Node {
self.node.borrow_mut()
}
}
impl DefaultModifiers<VStack> for VStack {}
impl VStack {
pub fn new(alignment: Alignment) -> Self {
VStack {
children: vec![],
node: Default::default(),
alignment,
}
}
pub fn gap(&mut self, gaps: Vec<i32>) -> Self {
let params: Vec<String> = gaps.iter().map(|size| sp(size.clone())).collect();
self.node.node_style.push(("grid-gap".to_string(), params.join(" ")));
self.clone()
}
pub fn justify_content(&mut self, value: &str) -> Self {
self.node.node_style.push(("justify-content".to_string(), value.to_string()));
self.clone()
}
pub fn flex_wrap(&mut self) -> Self {
self.node.node_style.push(("flex-wrap".to_string(), "wrap".to_string()));
self.clone()
}
}
impl ChildContainer for VStack {
fn get_children(&mut self) -> &mut Vec<Box<dyn Renderable>> {
return self.children.borrow_mut();
}
}
impl Appendable for VStack {}
impl Renderable for VStack {
fn render(&self) -> Node {
let mut stack = self
.clone()
.add_class("stack")
.add_class("stack--vertical")
.add_class(
&format!("stack--align-{}", match self.alignment {
Alignment::Center => {"center"}
Alignment::Start => {"start"}
Alignment::End => {"end"}
Alignment::Stretch => {"stretch"}
})
);
self.children.iter()
.for_each(|child|
stack.node.children.push(child.render()));
stack.node
}
}