1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use bevy_reflect::Reflect;
/// Struct defining a [`Sprite`](crate::Sprite) border with padding values
#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
pub struct BorderRect {
/// Pixel padding to the left
pub left: f32,
/// Pixel padding to the right
pub right: f32,
/// Pixel padding to the top
pub top: f32,
/// Pixel padding to the bottom
pub bottom: f32,
}
impl BorderRect {
/// Creates a new border as a square, with identical pixel padding values on every direction
#[must_use]
#[inline]
pub const fn square(value: f32) -> Self {
Self {
left: value,
right: value,
top: value,
bottom: value,
}
}
/// Creates a new border as a rectangle, with:
/// - `horizontal` for left and right pixel padding
/// - `vertical` for top and bottom pixel padding
#[must_use]
#[inline]
pub const fn rectangle(horizontal: f32, vertical: f32) -> Self {
Self {
left: horizontal,
right: horizontal,
top: vertical,
bottom: vertical,
}
}
}
impl From<f32> for BorderRect {
fn from(v: f32) -> Self {
Self::square(v)
}
}
impl From<[f32; 4]> for BorderRect {
fn from([left, right, top, bottom]: [f32; 4]) -> Self {
Self {
left,
right,
top,
bottom,
}
}
}