swoop_ui/container/grid/
v_grid.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::GridView;
10
11/// A vertical grid layout container that arranges children using `GridAutoFlow::Column`.
12/// Supports background and border styling, and allows for dynamic grid track configuration.
13#[derive(Debug, Clone, PartialEq)]
14pub struct VGrid {
15    /// The name component used to identify the UI node
16    name: Name,
17    /// The layout node controlling grid structure, flow, and spacing
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 VGrid {
28    fn default() -> Self {
29        Self {
30            name: Name::new("VGrid"),
31            node: Node {
32                display: Display::Grid,
33                grid_auto_flow: GridAutoFlow::Row,
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 VGrid {
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 GridView for VGrid {
57    fn grid_auto_track(mut self, tracks: Vec<GridTrack>) -> Self {
58        self.node_node().grid_auto_rows = tracks;
59        self
60    }
61
62    fn grid_template_track(mut self, tracks: Vec<RepeatedGridTrack>) -> Self {
63        self.node_node().grid_template_rows = tracks;
64        self
65    }
66}
67
68impl BackgroundView for VGrid {
69    fn background_node(&mut self) -> &mut BackgroundStyle {
70        &mut self.background
71    }
72}
73
74impl BorderView for VGrid {
75    fn border_node(&mut self) -> &mut BorderStyle {
76        &mut self.border
77    }
78}
79
80impl ShadowView for VGrid {
81    fn shadow_node(&mut self) -> &mut BoxShadow {
82        &mut self.shadow
83    }
84}
85
86impl ViewPack for VGrid {
87    fn pack(self) -> impl Bundle {
88        let name = self.name;
89        let border = self.border.pack();
90        let background = self.background.pack();
91        (name, self.node, border, background, self.shadow)
92    }
93}