#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum Direction {
Horizontal,
Vertical,
}
impl Direction {
pub fn axis(self) -> Axis {
match self {
Self::Horizontal => Axis::Inline,
Self::Vertical => Axis::Block,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum Axis {
Inline,
Block,
}
impl Axis {
pub fn direction(self) -> Direction {
match self {
Self::Inline => Direction::Horizontal,
Self::Block => Direction::Vertical,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum Alignment {
Start,
Center,
End,
Stretch,
}
impl Alignment {
pub fn is_stretched(self) -> bool {
matches!(self, Self::Stretch)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum Justification {
Start,
Center,
End,
SpaceBetween,
SpaceAround,
SpaceEvenly,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum Placement {
Top,
Right,
Bottom,
Left,
Center,
}
impl Placement {
pub fn is_edge(self) -> bool {
!matches!(self, Self::Center)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum Flow {
Row,
Column,
Wrap,
Grid,
Overlay,
}
impl Flow {
pub fn direction(self) -> Option<Direction> {
match self {
Self::Row => Some(Direction::Horizontal),
Self::Column => Some(Direction::Vertical),
Self::Wrap | Self::Grid | Self::Overlay => None,
}
}
}
#[cfg(test)]
mod tests {
use super::{Alignment, Axis, Direction, Flow, Placement};
#[test]
fn maps_direction_and_axis() {
assert_eq!(Direction::Horizontal.axis(), Axis::Inline);
assert_eq!(Axis::Block.direction(), Direction::Vertical);
}
#[test]
fn exposes_layout_helpers() {
assert!(Alignment::Stretch.is_stretched());
assert!(!Alignment::Center.is_stretched());
assert!(Placement::Top.is_edge());
assert!(!Placement::Center.is_edge());
assert_eq!(Flow::Column.direction(), Some(Direction::Vertical));
assert_eq!(Flow::Grid.direction(), None);
}
}