swoop_ui/container/grid/
v_grid.rs

1use bevy_ecs::prelude::*;
2use bevy_ui::prelude::*;
3
4use crate::View;
5use crate::background::{BackgroundStyle, BackgroundView};
6use crate::border::{BorderStyle, BorderView};
7use crate::prelude::PositionView;
8use crate::shadow::BoxShadowView;
9
10use super::GridView;
11
12/// A vertical grid layout container that arranges children using `GridAutoFlow::Column`.
13/// Supports background and border styling, and allows for dynamic grid track configuration.
14#[derive(Bundle, Debug, Clone)]
15pub struct VGrid {
16    /// The name component used to identify the UI node
17    name: Name,
18    /// The layout node controlling grid structure, flow, and spacing
19    node: Node,
20    /// Border rendering style (color and radius)
21    border: BorderStyle,
22    /// Background rendering style (color or image)
23    background: BackgroundStyle,
24    /// Shadow rendering style (Vec<ShadowStyle>)
25    shadow: BoxShadow,
26}
27
28impl Default for VGrid {
29    fn default() -> Self {
30        Self {
31            name: Name::new("VGrid"),
32            node: Node {
33                display: Display::Grid,
34                grid_auto_flow: GridAutoFlow::Row,
35                justify_content: JustifyContent::Start,
36                align_items: AlignItems::Center,
37                row_gap: Val::Px(0.0),
38                ..Default::default()
39            },
40            border: BorderStyle::default(),
41            background: BackgroundStyle::default(),
42            shadow: BoxShadow::default(),
43        }
44    }
45}
46
47impl View for VGrid {
48    fn name_node(&mut self) -> &mut Name {
49        &mut self.name
50    }
51
52    fn node_node(&mut self) -> &mut Node {
53        &mut self.node
54    }
55}
56
57impl GridView for VGrid {
58    fn grid_auto_track(mut self, tracks: Vec<GridTrack>) -> Self {
59        self.node_node().grid_auto_rows = tracks;
60        self
61    }
62
63    fn grid_template_track(mut self, tracks: Vec<RepeatedGridTrack>) -> Self {
64        self.node_node().grid_template_rows = tracks;
65        self
66    }
67}
68
69impl BackgroundView for VGrid {
70    fn background_node(&mut self) -> &mut BackgroundStyle {
71        &mut self.background
72    }
73}
74
75impl BorderView for VGrid {
76    fn border_node(&mut self) -> &mut BorderStyle {
77        &mut self.border
78    }
79}
80
81impl BoxShadowView for VGrid {
82    fn box_shadow_node(&mut self) -> &mut BoxShadow {
83        &mut self.shadow
84    }
85}
86
87impl PositionView for VGrid {}