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::*;
13 pub use super::v_stack::*;
14}
15
16pub trait StackView: View {
18 fn new(align_items: AlignItems, gap: Val) -> Self {
20 let mut stack = Self::default();
21 stack.node_node().align_items = align_items;
22 stack.spacing(gap)
23 }
24
25 fn reverse(mut self) -> Self {
27 let node = self.node_node();
28 let direction = match node.flex_direction {
29 FlexDirection::Row => FlexDirection::RowReverse,
30 FlexDirection::Column => FlexDirection::ColumnReverse,
31 FlexDirection::RowReverse => FlexDirection::Row,
32 FlexDirection::ColumnReverse => FlexDirection::Column,
33 };
34 node.flex_direction = direction;
35
36 self
37 }
38
39 fn wrap(mut self, wrap: FlexWrap) -> Self {
41 self.node_node().flex_wrap = wrap;
42 self
43 }
44
45 fn justify_content(mut self, justify: JustifyContent) -> Self {
47 self.node_node().justify_content = justify;
48 self
49 }
50
51 fn align_items(mut self, align_items: AlignItems) -> Self {
53 self.node_node().align_items = align_items;
54 self
55 }
56
57 fn row_gap(mut self, gap: Val) -> Self {
59 self.node_node().row_gap = gap;
60 self
61 }
62
63 fn column_gap(mut self, gap: Val) -> Self {
65 self.node_node().column_gap = gap;
66 self
67 }
68
69 fn spacing(mut self, gap: Val) -> Self {
71 let node = self.node_node();
72 match node.flex_direction {
73 FlexDirection::Row | FlexDirection::RowReverse => node.column_gap = gap,
74 FlexDirection::Column | FlexDirection::ColumnReverse => node.row_gap = gap,
75 }
76
77 self
78 }
79}