swoop_ui/
border.rs

1use bevy_color::prelude::*;
2use bevy_ecs::prelude::*;
3use bevy_ui::prelude::*;
4
5use crate::{View, ViewPack};
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(Debug, Clone, PartialEq)]
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 ViewPack for BorderStyle {
41    fn pack(self) -> impl Bundle {
42        (self.border_radius, self.border_color)
43    }
44}
45
46impl Default for BorderStyle {
47    fn default() -> Self {
48        Self {
49            border_radius: BorderRadius::ZERO,
50            border_color: BorderColor(Srgba::NONE.into()),
51        }
52    }
53}