Path: blob/main/crates/bevy_sprite/src/texture_slice/border_rect.rs
6600 views
use bevy_reflect::{std_traits::ReflectDefault, Reflect};12/// Defines the extents of the border of a rectangle.3///4/// This struct is used to represent thickness or offsets from the edges5/// of a rectangle (left, right, top, and bottom), with values increasing inwards.6#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]7#[reflect(Clone, PartialEq, Default)]8pub struct BorderRect {9/// Extent of the border along the left edge10pub left: f32,11/// Extent of the border along the right edge12pub right: f32,13/// Extent of the border along the top edge14pub top: f32,15/// Extent of the border along the bottom edge16pub bottom: f32,17}1819impl BorderRect {20/// An empty border with zero thickness along each edge21pub const ZERO: Self = Self::all(0.);2223/// Creates a border with the same `extent` along each edge24#[must_use]25#[inline]26pub const fn all(extent: f32) -> Self {27Self {28left: extent,29right: extent,30top: extent,31bottom: extent,32}33}3435/// Creates a new border with the `left` and `right` extents equal to `horizontal`, and `top` and `bottom` extents equal to `vertical`.36#[must_use]37#[inline]38pub const fn axes(horizontal: f32, vertical: f32) -> Self {39Self {40left: horizontal,41right: horizontal,42top: vertical,43bottom: vertical,44}45}46}4748impl From<f32> for BorderRect {49fn from(extent: f32) -> Self {50Self::all(extent)51}52}5354impl From<[f32; 4]> for BorderRect {55fn from([left, right, top, bottom]: [f32; 4]) -> Self {56Self {57left,58right,59top,60bottom,61}62}63}646566