swoop_ui/container/
stack.rs1use bevy_ui::prelude::*;
2
3use crate::View;
4
5pub mod h_stack;
7pub mod v_stack;
9
10pub mod prelude {
11 pub use super::StackView;
12 pub use super::h_stack::HStack;
13 pub use super::v_stack::VStack;
14}
15
16pub trait StackView: View {
18 fn from_justify_content(justify_content: JustifyContent) -> Self {
19 let mut stack = Self::default();
20 stack.node_node().justify_content = justify_content;
21 stack
22 }
23
24 fn from_align_items(align_items: AlignItems) -> Self {
25 let mut stack = Self::default();
26 stack.node_node().align_items = align_items;
27 stack
28 }
29
30 fn reverse(mut self) -> Self {
32 let node = self.node_node();
33 let direction = match node.flex_direction {
34 FlexDirection::Row => FlexDirection::RowReverse,
35 FlexDirection::Column => FlexDirection::ColumnReverse,
36 FlexDirection::RowReverse => FlexDirection::Row,
37 FlexDirection::ColumnReverse => FlexDirection::Column,
38 };
39 node.flex_direction = direction;
40
41 self
42 }
43
44 fn wrap(mut self, wrap: FlexWrap) -> Self {
46 self.node_node().flex_wrap = wrap;
47 self
48 }
49
50 fn justify_content(mut self, justify: JustifyContent) -> Self {
52 self.node_node().justify_content = justify;
53 self
54 }
55
56 fn align_items(mut self, align_items: AlignItems) -> Self {
58 self.node_node().align_items = align_items;
59 self
60 }
61
62 fn row_gap(mut self, gap: Val) -> Self {
64 self.node_node().row_gap = gap;
65 self
66 }
67
68 fn column_gap(mut self, gap: Val) -> Self {
70 self.node_node().column_gap = gap;
71 self
72 }
73
74 fn spacing(mut self, gap: Val) -> Self {
76 let node = self.node_node();
77 match node.flex_direction {
78 FlexDirection::Row | FlexDirection::RowReverse => node.column_gap = gap,
79 FlexDirection::Column | FlexDirection::ColumnReverse => node.row_gap = gap,
80 }
81
82 self
83 }
84}