swoop_ui/container/stack/
v_stack.rs

1use bevy_ecs::prelude::*;
2use bevy_ui::prelude::*;
3
4use crate::background::{BackgroundStyle, BackgroundView};
5use crate::border::{BorderStyle, BorderView};
6use crate::shadow::ShadowView;
7use crate::{View, ViewPack};
8
9use super::StackView;
10
11/// A vertical stack layout container that arranges children in a column.
12/// Implements background and border styling, and conforms to StackContainer behavior.
13#[derive(Debug, Clone, PartialEq)]
14pub struct VStack {
15    /// The name component used to identify the UI node
16    name: Name,
17    /// The layout node controlling size, flex direction, spacing, etc.
18    node: Node,
19    /// Border rendering style (color and radius)
20    border: BorderStyle,
21    /// Background rendering style (color or image)
22    background: BackgroundStyle,
23    /// Shadow rendering style (Vec<ShadowStyle>)
24    shadow: BoxShadow,
25}
26
27impl Default for VStack {
28    fn default() -> Self {
29        Self {
30            name: Name::new("VStack"),
31            node: Node {
32                display: Display::Flex,
33                flex_direction: FlexDirection::Column,
34                justify_content: JustifyContent::Start,
35                align_items: AlignItems::Center,
36                row_gap: Val::Px(0.0),
37                ..Default::default()
38            },
39            border: BorderStyle::default(),
40            background: BackgroundStyle::default(),
41            shadow: BoxShadow::default(),
42        }
43    }
44}
45
46impl View for VStack {
47    fn name_node(&mut self) -> &mut Name {
48        &mut self.name
49    }
50
51    fn node_node(&mut self) -> &mut Node {
52        &mut self.node
53    }
54}
55
56impl StackView for VStack {}
57
58impl BackgroundView for VStack {
59    fn background_node(&mut self) -> &mut BackgroundStyle {
60        &mut self.background
61    }
62}
63
64impl BorderView for VStack {
65    fn border_node(&mut self) -> &mut BorderStyle {
66        &mut self.border
67    }
68}
69
70impl ShadowView for VStack {
71    fn shadow_node(&mut self) -> &mut BoxShadow {
72        &mut self.shadow
73    }
74}
75
76impl ViewPack for VStack {
77    fn pack(self) -> impl Bundle {
78        let name = self.name;
79        let border = self.border.pack();
80        let background = self.background.pack();
81        (name, self.node, border, background, self.shadow)
82    }
83}