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
use crate::{Renderable};
use crate::node::{Node, NodeContainer};
use crate::components::Alignment;
use std::borrow::BorrowMut;
use crate::{sp, DefaultModifiers};
use crate::components::{Appendable, ChildContainer};
#[derive(Debug, Clone)]
pub struct HStack {
children: Vec<Box<dyn Renderable>>,
node: Node,
pub alignment: Alignment,
}
impl Default for HStack {
fn default() -> Self {
HStack {
children: vec![],
node: Default::default(),
alignment: Alignment::Stretch,
}
}
}
impl NodeContainer for HStack {
fn get_node(&mut self) -> &mut Node {
self.node.borrow_mut()
}
}
impl DefaultModifiers<HStack> for HStack {}
impl HStack {
pub fn new(alignment: Alignment) -> Self {
HStack {
children: vec![],
node: Default::default(),
alignment,
}
}
pub fn justify_content(&mut self, justification: &str) -> Self {
self.node.node_style.push(("justify-content".to_string(), justification.to_string()));
self.clone()
}
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 flex_wrap(&mut self) -> Self {
self.node.node_style.push(("flex-wrap".to_string(), "wrap".to_string()));
self.clone()
}
}
impl ChildContainer for HStack {
fn get_children(&mut self) -> &mut Vec<Box<dyn Renderable>> {
return self.children.borrow_mut();
}
}
impl Appendable for HStack {}
impl Renderable for HStack {
fn render(&self) -> Node {
let mut view = self
.clone()
.add_class("stack")
.add_class("stack--horizontal")
.add_class(
format!("stack--align-{:?}", self.alignment)
.to_lowercase()
.as_str()
)
.node;
self.children.iter()
.for_each(|child|
view.children.push(child.render()));
view
}
}