bevy_sprite/texture_slice/
border_rect.rs1use bevy_reflect::Reflect;
2
3#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
5pub struct BorderRect {
6 pub left: f32,
8 pub right: f32,
10 pub top: f32,
12 pub bottom: f32,
14}
15
16impl BorderRect {
17 pub const ZERO: Self = Self::square(0.);
19
20 #[must_use]
22 #[inline]
23 pub const fn square(value: f32) -> Self {
24 Self {
25 left: value,
26 right: value,
27 top: value,
28 bottom: value,
29 }
30 }
31
32 #[must_use]
36 #[inline]
37 pub const fn rectangle(horizontal: f32, vertical: f32) -> Self {
38 Self {
39 left: horizontal,
40 right: horizontal,
41 top: vertical,
42 bottom: vertical,
43 }
44 }
45}
46
47impl From<f32> for BorderRect {
48 fn from(v: f32) -> Self {
49 Self::square(v)
50 }
51}
52
53impl From<[f32; 4]> for BorderRect {
54 fn from([left, right, top, bottom]: [f32; 4]) -> Self {
55 Self {
56 left,
57 right,
58 top,
59 bottom,
60 }
61 }
62}