use std::ops::Not; use crate::layout::{Vec2, vec2}; #[derive(Copy, Clone, Eq, PartialEq)] pub enum Axis { X, Y, } impl Not for Axis { type Output = Self; fn not(self) -> Self::Output { match self { Self::X => Self::Y, Self::Y => Self::X, } } } #[derive(Clone, Copy, Eq, PartialEq)] pub struct Dir { pub axis: Axis, pub sign: Sign, } impl Dir { pub const fn new(axis: Axis, dir: Sign) -> Self { Self { axis, sign: dir } } pub const LEFT: Self = Self::new(Axis::X, Sign::Neg); pub const RIGHT: Self = Self::new(Axis::X, Sign::Pos); pub const UP: Self = Self::new(Axis::Y, Sign::Neg); pub const DOWN: Self = Self::new(Axis::Y, Sign::Pos); } #[derive(Clone, Copy, Eq, PartialEq)] pub enum Sign { Neg, Pos, } impl Vec2 { pub fn axis(&self, axis: Axis) -> f32 { match axis { Axis::X => self.x, Axis::Y => self.y, } } pub fn axis_mut(&mut self, axis: Axis) -> &mut f32 { match axis { Axis::X => &mut self.x, Axis::Y => &mut self.y, } } pub const fn from_axis(axis: Axis, aligned: f32, ortho: f32) -> Self { Self { x: match axis { Axis::X => aligned, Axis::Y => ortho, }, y: match axis { Axis::Y => aligned, Axis::X => ortho, }, } } } #[derive(Clone, Copy, PartialEq, Eq)] pub enum Align { TopLeft, Top, TopRight, Left, Center, Right, BotLeft, Bot, BotRight, } impl Align { pub const fn rel(&self) -> Vec2 { match self { Self::TopLeft => vec2(0.0, 0.0), Self::Top => vec2(0.5, 0.0), Self::TopRight => vec2(1.0, 0.0), Self::Left => vec2(0.0, 0.5), Self::Center => vec2(0.5, 0.5), Self::Right => vec2(1.0, 0.5), Self::BotLeft => vec2(0.0, 1.0), Self::Bot => vec2(0.5, 1.0), Self::BotRight => vec2(1.0, 1.0), } } }