Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_sprite/src/texture_slice/border_rect.rs
6600 views
1
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
2
3
/// Defines the extents of the border of a rectangle.
4
///
5
/// This struct is used to represent thickness or offsets from the edges
6
/// of a rectangle (left, right, top, and bottom), with values increasing inwards.
7
#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
8
#[reflect(Clone, PartialEq, Default)]
9
pub struct BorderRect {
10
/// Extent of the border along the left edge
11
pub left: f32,
12
/// Extent of the border along the right edge
13
pub right: f32,
14
/// Extent of the border along the top edge
15
pub top: f32,
16
/// Extent of the border along the bottom edge
17
pub bottom: f32,
18
}
19
20
impl BorderRect {
21
/// An empty border with zero thickness along each edge
22
pub const ZERO: Self = Self::all(0.);
23
24
/// Creates a border with the same `extent` along each edge
25
#[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
/// Creates a new border with the `left` and `right` extents equal to `horizontal`, and `top` and `bottom` extents equal to `vertical`.
37
#[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
49
impl From<f32> for BorderRect {
50
fn from(extent: f32) -> Self {
51
Self::all(extent)
52
}
53
}
54
55
impl 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
66