swoop_ui/
border.rs

1use bevy_color::prelude::*;
2use bevy_ecs::prelude::*;
3use bevy_ui::prelude::*;
4
5use crate::View;
6
7/// Provides border configuration for a UI container
8pub trait BorderView: View {
9    /// Returns a mutable reference to the current border style
10    fn border_node(&mut self) -> &mut BorderStyle;
11
12    /// Sets the border size
13    fn border(mut self, border: UiRect) -> Self {
14        self.node_node().border = border;
15        self
16    }
17
18    /// Sets the border color
19    fn border_color(mut self, border_color: impl Into<Color>) -> Self {
20        self.border_node().border_color.0 = border_color.into();
21        self
22    }
23
24    /// Sets the border radius
25    fn border_radius(mut self, border_radius: BorderRadius) -> Self {
26        self.border_node().border_radius = border_radius;
27        self
28    }
29}
30
31/// Describes the style for rendering borders around a UI container
32#[derive(Bundle, Debug, Clone)]
33pub struct BorderStyle {
34    /// The corner radius for the border
35    border_radius: BorderRadius,
36    /// The color of the border
37    border_color: BorderColor,
38}
39
40impl BorderStyle {
41    pub fn button() -> Self {
42        Self {
43            border_radius: BorderRadius::all(Val::Px(10.0)),
44            border_color: BorderColor::default(),
45        }
46    }
47}
48
49impl Default for BorderStyle {
50    fn default() -> Self {
51        Self {
52            border_radius: BorderRadius::ZERO,
53            border_color: BorderColor(Srgba::NONE.into()),
54        }
55    }
56}