swoop_ui/container/
stack.rs1use bevy_ui::prelude::*;
2
3use crate::UiBase;
4
5pub mod h_stack;
6pub mod v_stack;
7
8pub mod prelude {
9 pub use super::StackContainer;
10 pub use super::h_stack::*;
11 pub use super::v_stack::*;
12}
13
14pub trait StackContainer: UiBase + Default {
16 fn new(align_items: AlignItems, gap: Val) -> Self {
18 let mut stack = Self::default();
19 stack.node_node().align_items = align_items;
20 stack.spacing(gap)
21 }
22
23 fn reverse(mut self) -> Self {
25 let node = self.node_node();
26 let direction = match node.flex_direction {
27 FlexDirection::Row => FlexDirection::RowReverse,
28 FlexDirection::Column => FlexDirection::ColumnReverse,
29 FlexDirection::RowReverse => FlexDirection::Row,
30 FlexDirection::ColumnReverse => FlexDirection::Column,
31 };
32 node.flex_direction = direction;
33
34 self
35 }
36
37 fn wrap(mut self, wrap: FlexWrap) -> Self {
39 self.node_node().flex_wrap = wrap;
40 self
41 }
42
43 fn justify_content(mut self, justify: JustifyContent) -> Self {
45 self.node_node().justify_content = justify;
46 self
47 }
48
49 fn align_items(mut self, align_items: AlignItems) -> Self {
51 self.node_node().align_items = align_items;
52 self
53 }
54
55 fn row_gap(mut self, gap: Val) -> Self {
57 self.node_node().row_gap = gap;
58 self
59 }
60
61 fn column_gap(mut self, gap: Val) -> Self {
63 self.node_node().column_gap = gap;
64 self
65 }
66
67 fn spacing(mut self, gap: Val) -> Self {
69 let node = self.node_node();
70 match node.flex_direction {
71 FlexDirection::Row | FlexDirection::RowReverse => node.column_gap = gap,
72 FlexDirection::Column | FlexDirection::ColumnReverse => node.row_gap = gap,
73 }
74
75 self
76 }
77}