swoop_ui/shadow.rs
1use bevy_color::prelude::*;
2use bevy_math::prelude::*;
3use bevy_ui::prelude::*;
4
5use crate::View;
6
7/// A trait for setting and modifying UI container shadow styles.
8pub trait BoxShadowView: View {
9 /// Returns a mutable reference to the internal shadow style list.
10 fn box_shadow_node(&mut self) -> &mut BoxShadow;
11
12 /// Replaces all existing shadows with the provided list.
13 fn shadow(mut self, shadows: Vec<ShadowStyle>) -> Self {
14 self.box_shadow_node().0 = shadows;
15 self
16 }
17
18 /// Appends a new shadow to the current list.
19 fn add_shadow(mut self, shadow: ShadowStyle) -> Self {
20 self.box_shadow_node().0.push(shadow);
21 self
22 }
23}
24
25/// A trait for views that support text shadow styling.
26///
27/// Provides methods to configure shadow offset and color for text-based views.
28pub trait TextShadowView: View {
29 /// Returns a mutable reference to the underlying `TextShadow` node,
30 /// which stores shadow-related styling information.
31 fn text_shadow_node(&mut self) -> &mut TextShadow;
32
33 /// Sets the offset of the text shadow.
34 ///
35 /// # Arguments
36 /// * `offset` - A `Vec2` specifying the horizontal and vertical offset of the shadow.
37 ///
38 /// # Example
39 /// ```
40 /// view.text_shadow_offset(Vec2::new(2.0, -2.0));
41 /// ```
42 fn text_shadow_offset(mut self, offset: Vec2) -> Self {
43 self.text_shadow_node().offset = offset;
44 self
45 }
46
47 /// Sets the color of the text shadow.
48 ///
49 /// # Arguments
50 /// * `color` - A color value (e.g., `Color::rgba(...)`) that defines the shadow’s appearance.
51 ///
52 /// # Example
53 /// ```
54 /// view.text_shadow_color(Color::BLACK.with_a(0.5));
55 /// ```
56 fn text_shadow_color(mut self, color: impl Into<Color>) -> Self {
57 self.text_shadow_node().color = color.into();
58 self
59 }
60}