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