swoop_ui/container/grid/
h_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::shadow::ShadowView;
8
9use super::GridView;
10
11/// A horizontal grid layout container that arranges children using `GridAutoFlow::Row`.
12/// Supports background and border styling as well as custom grid track configuration.
13#[derive(Bundle, Debug, Clone)]
14pub struct HGrid {
15    /// The name component used to identify the UI node
16    name: Name,
17    /// The layout node controlling grid behavior 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 HGrid {
28    fn default() -> Self {
29        Self {
30            name: Name::new("HGrid"),
31            node: Node {
32                display: Display::Grid,
33                grid_auto_flow: GridAutoFlow::Column,
34                justify_content: JustifyContent::Start,
35                align_items: AlignItems::Center,
36                column_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 HGrid {
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 HGrid {
57    fn grid_auto_track(mut self, tracks: Vec<GridTrack>) -> Self {
58        self.node_node().grid_auto_columns = tracks;
59        self
60    }
61
62    fn grid_template_track(mut self, tracks: Vec<RepeatedGridTrack>) -> Self {
63        self.node_node().grid_template_columns = tracks;
64        self
65    }
66}
67
68impl BackgroundView for HGrid {
69    fn background_node(&mut self) -> &mut BackgroundStyle {
70        &mut self.background
71    }
72}
73
74impl BorderView for HGrid {
75    fn border_node(&mut self) -> &mut BorderStyle {
76        &mut self.border
77    }
78}
79
80impl ShadowView for HGrid {
81    fn shadow_node(&mut self) -> &mut BoxShadow {
82        &mut self.shadow
83    }
84}