use bevy::reflect::Reflect;
use super::Units;
#[derive(Debug, Default, Reflect, Copy, Clone, PartialEq)]
pub struct Edge {
pub top: Units,
pub right: Units,
pub bottom: Units,
pub left: Units,
}
impl Edge {
pub fn new(
top: impl Into<Units>,
right: impl Into<Units>,
bottom: impl Into<Units>,
left: impl Into<Units>,
) -> Self {
Self {
top: top.into(),
right: right.into(),
bottom: bottom.into(),
left: left.into(),
}
}
pub fn axis(vertical: Units, horizontal: Units) -> Self {
Self {
top: vertical,
right: horizontal,
bottom: vertical,
left: horizontal,
}
}
pub fn all(value: impl Into<Units> + Copy) -> Self {
Self {
top: value.into(),
right: value.into(),
bottom: value.into(),
left: value.into(),
}
}
pub fn into_tuple(self) -> (Units, Units, Units, Units) {
(self.top, self.right, self.bottom, self.left)
}
pub fn bottom(mut self, value: impl Into<Units>) -> Self {
self.bottom = value.into();
self
}
pub fn top(mut self, value: impl Into<Units>) -> Self {
self.top = value.into();
self
}
pub fn left(mut self, value: impl Into<Units>) -> Self {
self.left = value.into();
self
}
pub fn right(mut self, value: impl Into<Units>) -> Self {
self.right = value.into();
self
}
}
impl From<Edge> for (Units, Units, Units, Units) {
fn from(edge: Edge) -> Self {
edge.into_tuple()
}
}
impl From<(Units, Units)> for Edge {
fn from(value: (Units, Units)) -> Self {
Edge::axis(value.0, value.1)
}
}
impl From<(Units, Units, Units, Units)> for Edge {
fn from(value: (Units, Units, Units, Units)) -> Self {
Edge::new(value.0, value.1, value.2, value.3)
}
}