bevy_sprite/texture_slice/
border_rect.rs1use bevy_reflect::{std_traits::ReflectDefault, Reflect};
2
3#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
8#[reflect(Clone, PartialEq, Default)]
9pub struct BorderRect {
10 pub left: f32,
12 pub right: f32,
14 pub top: f32,
16 pub bottom: f32,
18}
19
20impl BorderRect {
21 pub const ZERO: Self = Self::all(0.);
23
24 #[must_use]
26 #[inline]
27 pub const fn all(extent: f32) -> Self {
28 Self {
29 left: extent,
30 right: extent,
31 top: extent,
32 bottom: extent,
33 }
34 }
35
36 #[must_use]
38 #[inline]
39 pub const fn axes(horizontal: f32, vertical: f32) -> Self {
40 Self {
41 left: horizontal,
42 right: horizontal,
43 top: vertical,
44 bottom: vertical,
45 }
46 }
47}
48
49impl From<f32> for BorderRect {
50 fn from(extent: f32) -> Self {
51 Self::all(extent)
52 }
53}
54
55impl From<[f32; 4]> for BorderRect {
56 fn from([left, right, top, bottom]: [f32; 4]) -> Self {
57 Self {
58 left,
59 right,
60 top,
61 bottom,
62 }
63 }
64}
65
66impl core::ops::Add for BorderRect {
67 type Output = Self;
68
69 fn add(mut self, rhs: Self) -> Self::Output {
70 self.left += rhs.left;
71 self.right += rhs.right;
72 self.top += rhs.top;
73 self.bottom += rhs.bottom;
74 self
75 }
76}
77
78impl core::ops::Sub for BorderRect {
79 type Output = Self;
80
81 fn sub(mut self, rhs: Self) -> Self::Output {
82 self.left -= rhs.left;
83 self.right -= rhs.right;
84 self.top -= rhs.top;
85 self.bottom -= rhs.bottom;
86 self
87 }
88}
89
90impl core::ops::Mul<f32> for BorderRect {
91 type Output = Self;
92
93 fn mul(mut self, rhs: f32) -> Self::Output {
94 self.left *= rhs;
95 self.right *= rhs;
96 self.top *= rhs;
97 self.bottom *= rhs;
98 self
99 }
100}
101
102impl core::ops::Div<f32> for BorderRect {
103 type Output = Self;
104
105 fn div(mut self, rhs: f32) -> Self::Output {
106 self.left /= rhs;
107 self.right /= rhs;
108 self.top /= rhs;
109 self.bottom /= rhs;
110 self
111 }
112}