swoop_ui/button/
v_button.rs

1use bevy_ecs::prelude::*;
2use bevy_ui::prelude::*;
3
4use crate::View;
5use crate::background::BackgroundStyle;
6use crate::border::{BorderStyle, BorderView};
7use crate::prelude::{BackgroundView, PositionView, StackView};
8use crate::shadow::BoxShadowView;
9
10/// A vertically stacked button view with customizable styling, including border, background,
11/// and box shadow. Suited for UI layouts where label and icon should be stacked top-to-bottom.
12///
13/// By default, `VButton` is configured with:
14/// - `flex_direction`: `Column`
15/// - `justify_content`: `Center`
16/// - `align_items`: `Center`
17/// - `row_gap`: `0.0`
18///
19/// Implements styling traits such as `BackgroundView`, `BorderView`, `BoxShadowView`,
20/// and layout behavior from `PositionView` and `StackView`.
21///
22/// # Example
23/// ```ignore
24/// commands.spawn(VButton::default()
25///     .text("Submit")
26///     .font(my_font)
27///     .background_color(Color::ORANGE)
28///     .border_radius(Val::Px(8.0)));
29/// ```
30#[derive(Bundle, Debug, Clone)]
31pub struct VButton {
32    /// Name tag for debugging or entity identification.
33    name: Name,
34
35    /// Layout configuration node using vertical flex.
36    node: Node,
37
38    /// Interaction marker enabling Bevy’s UI click behavior.
39    botton: Button,
40
41    /// Border visuals such as width, color, and radius.
42    border: BorderStyle,
43
44    /// Background visuals such as fill color or gradient.
45    background: BackgroundStyle,
46
47    /// Drop shadow rendering for elevation or depth.
48    shadow: BoxShadow,
49}
50
51impl Default for VButton {
52    /// Constructs a `VButton` with vertical stack layout and default styles.
53    fn default() -> Self {
54        Self {
55            name: Name::new("VButton"),
56            node: Node {
57                display: Display::Flex,
58                flex_direction: FlexDirection::Column,
59                justify_content: JustifyContent::Center,
60                align_items: AlignItems::Center,
61                row_gap: Val::Px(0.0),
62                ..Default::default()
63            },
64            botton: Button,
65            border: BorderStyle::button(),
66            background: BackgroundStyle::button(),
67            shadow: BoxShadow::default(),
68        }
69    }
70}
71
72impl View for VButton {
73    fn name_node(&mut self) -> &mut Name {
74        &mut self.name
75    }
76
77    fn node_node(&mut self) -> &mut Node {
78        &mut self.node
79    }
80}
81
82impl StackView for VButton {}
83
84impl BackgroundView for VButton {
85    fn background_node(&mut self) -> &mut BackgroundStyle {
86        &mut self.background
87    }
88}
89
90impl BorderView for VButton {
91    fn border_node(&mut self) -> &mut BorderStyle {
92        &mut self.border
93    }
94}
95
96impl BoxShadowView for VButton {
97    fn box_shadow_node(&mut self) -> &mut BoxShadow {
98        &mut self.shadow
99    }
100}
101
102impl PositionView for VButton {}