use std::ops::{Deref, DerefMut};
use strum_macros::EnumString;
use crate::layout::{LayoutAxisX, LayoutAxisY};
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct Point<T> {
pub x: T,
pub y: T,
}
impl<T> Point<T> {
pub const fn new(x: T, y: T) -> Point<T> {
Point { x, y }
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct Size<T> {
pub width: T,
pub height: T,
}
impl<T> Size<T> {
pub const fn new(width: T, height: T) -> Size<T> {
Size { width, height }
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, EnumString)]
pub enum Dimension<T> {
#[strum(serialize = "undefined")]
Undefined,
#[strum(serialize = "auto")]
Auto,
#[strum(disabled)]
Points(T),
#[strum(disabled)]
Percentage(T),
}
impl<T> Default for Dimension<T> {
fn default() -> Self {
Dimension::Undefined
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct ByCorner<T> {
pub all: LayoutAxisY<LayoutAxisX<T>>,
}
impl<T> ByCorner<T> {
pub fn map<F, O>(self, mut op: F) -> ByCorner<O>
where
F: FnMut(T) -> O,
{
ByCorner {
all: LayoutAxisY {
top: match self.all.top {
LayoutAxisX::DirectionDependent { leading, trailing } => {
LayoutAxisX::DirectionDependent {
leading: op(leading),
trailing: op(trailing),
}
}
LayoutAxisX::DirectionIndependent { left, right } => {
LayoutAxisX::DirectionIndependent {
left: op(left),
right: op(right),
}
}
},
bottom: match self.all.bottom {
LayoutAxisX::DirectionDependent { leading, trailing } => {
LayoutAxisX::DirectionDependent {
leading: op(leading),
trailing: op(trailing),
}
}
LayoutAxisX::DirectionIndependent { left, right } => {
LayoutAxisX::DirectionIndependent {
left: op(left),
right: op(right),
}
}
},
},
}
}
}
impl<T> Deref for ByCorner<T> {
type Target = LayoutAxisY<LayoutAxisX<T>>;
fn deref(&self) -> &Self::Target {
&self.all
}
}
impl<T> DerefMut for ByCorner<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.all
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct ByDirection<T> {
pub horizontal: T,
pub vertical: T,
}
impl<T> ByDirection<T>
where
T: Copy,
{
pub fn with_both(value: T) -> ByDirection<T> {
ByDirection {
horizontal: value,
vertical: value,
}
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct ByEdge<T> {
pub horizontal: LayoutAxisX<T>,
pub vertical: LayoutAxisY<T>,
}