swoop_ui/text/
swoop_text.rs

1use bevy_color::prelude::*;
2use bevy_ecs::prelude::*;
3use bevy_math::prelude::*;
4use bevy_ui::prelude::*;
5
6use crate::View;
7use crate::background::BackgroundStyle;
8use crate::border::{BorderStyle, BorderView};
9use crate::prelude::{BackgroundView, PositionView};
10use crate::shadow::{BoxShadowView, TextShadowView};
11
12use super::{TextStyle, TextView};
13
14pub type SText = SwoopText;
15
16/// A styled text view bundle that supports layout, borders, background,
17/// shadows, and positioning within the UI system.
18///
19/// This component integrates common UI traits to provide a rich,
20/// CSS-inspired view abstraction.
21#[derive(Bundle, Debug, Clone)]
22pub struct SwoopText {
23    /// Name for debugging or entity identification.
24    name: Name,
25
26    /// Layout and sizing node (e.g., width, height, margin).
27    node: Node,
28
29    /// Border styling (width, color, radius, etc.).
30    border: BorderStyle,
31
32    /// Background styling (color, image, etc.).
33    background: BackgroundStyle,
34
35    /// Outer box shadow styling (e.g., drop shadow).
36    box_shadow: BoxShadow,
37
38    /// Text content, color, font, size
39    text: TextStyle,
40
41    /// Inner text shadow styling.
42    text_shadow: TextShadow,
43}
44
45impl Default for SwoopText {
46    /// Returns a `SwoopText` instance with default visual styles.
47    fn default() -> Self {
48        Self {
49            name: Name::new("SwoopText"),
50            node: Node {
51                ..Default::default()
52            },
53            border: BorderStyle::default(),
54            background: BackgroundStyle::default(),
55            box_shadow: BoxShadow::default(),
56            text: TextStyle::default(),
57            text_shadow: TextShadow {
58                offset: Vec2::ZERO,
59                color: Srgba::NONE.into(),
60            },
61        }
62    }
63}
64
65impl View for SwoopText {
66    fn name_node(&mut self) -> &mut Name {
67        &mut self.name
68    }
69
70    fn node_node(&mut self) -> &mut Node {
71        &mut self.node
72    }
73}
74
75impl BorderView for SwoopText {
76    fn border_node(&mut self) -> &mut BorderStyle {
77        &mut self.border
78    }
79}
80
81impl BackgroundView for SwoopText {
82    fn background_node(&mut self) -> &mut BackgroundStyle {
83        &mut self.background
84    }
85}
86
87impl BoxShadowView for SwoopText {
88    fn box_shadow_node(&mut self) -> &mut BoxShadow {
89        &mut self.box_shadow
90    }
91}
92
93impl TextView for SwoopText {
94    fn text_node(&mut self) -> &mut super::TextStyle {
95        &mut self.text
96    }
97}
98
99impl TextShadowView for SwoopText {
100    fn text_shadow_node(&mut self) -> &mut TextShadow {
101        &mut self.text_shadow
102    }
103}
104
105impl PositionView for SwoopText {}