diff options
Diffstat (limited to 'src/geom/align.rs')
| -rw-r--r-- | src/geom/align.rs | 67 |
1 files changed, 20 insertions, 47 deletions
diff --git a/src/geom/align.rs b/src/geom/align.rs index 42fc493e..dca35891 100644 --- a/src/geom/align.rs +++ b/src/geom/align.rs @@ -128,16 +128,27 @@ impl Debug for GenAlign { } } -cast_from_value! { - GenAlign: "alignment", +cast! { + type GenAlign: "alignment", } -cast_from_value! { - Axes<GenAlign>: "2d alignment", +cast! { + type Axes<GenAlign>: "2d alignment", } -cast_from_value! { +cast! { + Axes<Align>, + self => self.map(GenAlign::from).into_value(), +} + +cast! { Axes<Option<GenAlign>>, + self => match (self.x, self.y) { + (Some(x), Some(y)) => Axes::new(x, y).into_value(), + (Some(x), None) => x.into_value(), + (None, Some(y)) => y.into_value(), + (None, None) => Value::None, + }, align: GenAlign => { let mut aligns = Axes::default(); aligns.set(align.axis(), Some(align)); @@ -146,19 +157,6 @@ cast_from_value! { aligns: Axes<GenAlign> => aligns.map(Some), } -cast_to_value! { - v: Axes<Align> => v.map(GenAlign::from).into() -} - -cast_to_value! { - v: Axes<Option<GenAlign>> => match (v.x, v.y) { - (Some(x), Some(y)) => Axes::new(x, y).into(), - (Some(x), None) => x.into(), - (None, Some(y)) => y.into(), - (None, None) => Value::None, - } -} - impl From<Axes<GenAlign>> for Axes<Option<GenAlign>> { fn from(axes: Axes<GenAlign>) -> Self { axes.map(Some) @@ -213,8 +211,9 @@ impl Fold for Align { #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub struct HorizontalAlign(pub GenAlign); -cast_from_value! { +cast! { HorizontalAlign, + self => self.0.into_value(), align: GenAlign => { if align.axis() != Axis::X { Err("alignment must be horizontal")?; @@ -223,17 +222,14 @@ cast_from_value! { }, } -cast_to_value! { - v: HorizontalAlign => v.0.into() -} - /// Utility struct to restrict a passed alignment value to the vertical axis on /// cast. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub struct VerticalAlign(pub GenAlign); -cast_from_value! { +cast! { VerticalAlign, + self => self.0.into_value(), align: GenAlign => { if align.axis() != Axis::Y { Err("alignment must be vertical")?; @@ -241,26 +237,3 @@ cast_from_value! { Self(align) }, } - -cast_to_value! { - v: VerticalAlign => v.0.into() -} - -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub enum LeftRightAlternator { - Left, - Right, -} - -impl Iterator for LeftRightAlternator { - type Item = LeftRightAlternator; - - fn next(&mut self) -> Option<Self::Item> { - let r = Some(*self); - match self { - Self::Left => *self = Self::Right, - Self::Right => *self = Self::Left, - } - r - } -} |
