swoop_ui/container/stack/
h_stack.rs

1use bevy_ecs::prelude::*;
2use bevy_ui::prelude::*;
3
4use crate::container::{BackgroundContainer, BackgroundStyle, BorderContainer, BorderStyle};
5use crate::{UiBase, UiToBundle};
6
7use super::StackContainer;
8
9/// A horizontal stack layout container that arranges children in a row.
10/// It supports background and border styling, and conforms to StackContainer behavior.
11pub struct HStack {
12    /// The name component used to identify the UI node
13    name: Name,
14    /// The layout node controlling size, flex direction, spacing, etc.
15    node: Node,
16    /// Border rendering style (color and radius)
17    border: BorderStyle,
18    /// Background rendering style (color or image)
19    background: BackgroundStyle,
20}
21
22impl Default for HStack {
23    fn default() -> Self {
24        Self {
25            name: Name::new("HStack"),
26            node: Node {
27                display: Display::Flex,
28                flex_direction: FlexDirection::Row,
29                justify_content: JustifyContent::Start,
30                align_items: AlignItems::Center,
31                column_gap: Val::Px(0.0),
32                ..Default::default()
33            },
34            border: BorderStyle::default(),
35            background: BackgroundStyle::default(),
36        }
37    }
38}
39
40impl UiBase for HStack {
41    fn name_node(&mut self) -> &mut Name {
42        &mut self.name
43    }
44
45    fn node_node(&mut self) -> &mut Node {
46        &mut self.node
47    }
48}
49
50impl StackContainer for HStack {}
51
52impl BackgroundContainer for HStack {
53    fn background_node(&mut self) -> &mut BackgroundStyle {
54        &mut self.background
55    }
56}
57
58impl BorderContainer for HStack {
59    fn border_node(&mut self) -> &mut BorderStyle {
60        &mut self.border
61    }
62}
63
64impl UiToBundle for HStack {
65    fn pack(self) -> impl Bundle {
66        let name = self.name;
67        let border = self.border.pack();
68        let background = self.background.pack();
69        (name, self.node, border, background)
70    }
71}