diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-01-24 12:44:04 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-01-24 12:44:04 +0100 |
| commit | 03fddaf3aea778057aedd74dbcb27bae971ec22f (patch) | |
| tree | 37e3136e29e0e5d69ec8f56e43d156739d2931ab /src/library/maps/alignment.rs | |
| parent | 78da2bdd5d77d1b8572e5e9da119bfa68127a3fa (diff) | |
Non-fatal argument parsing 🌋
Diffstat (limited to 'src/library/maps/alignment.rs')
| -rw-r--r-- | src/library/maps/alignment.rs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/library/maps/alignment.rs b/src/library/maps/alignment.rs deleted file mode 100644 index 8654e280..00000000 --- a/src/library/maps/alignment.rs +++ /dev/null @@ -1,77 +0,0 @@ -use super::*; -use AlignmentKey::*; - - -/// An argument key which describes a target alignment. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum AlignmentKey { - Align(Alignment), - Left, - Top, - Right, - Bottom, -} - -impl AlignmentKey { - /// The generic axis this alignment key corresponds to in the given system - /// of layouting axes. `None` if the alignment is generic. - pub fn axis(self, axes: LayoutAxes) -> Option<GenericAxis> { - match self { - Left | Right => Some(Horizontal.to_generic(axes)), - Top | Bottom => Some(Vertical.to_generic(axes)), - Align(_) => None, - } - } - - /// The generic version of this alignment in the given system of layouting - /// axes. - /// - /// Returns an error if the alignment is invalid for the given axis. - pub fn to_generic(self, axes: LayoutAxes, axis: GenericAxis) -> LayoutResult<Alignment> { - let specific = axis.to_specific(axes); - let start = match axes.get(axis).is_positive() { - true => Origin, - false => End, - }; - - Ok(match (self, specific) { - (Align(alignment), _) => alignment, - (Left, Horizontal) | (Top, Vertical) => start, - (Right, Horizontal) | (Bottom, Vertical) => start.inv(), - - _ => error!( - "invalid alignment `{}` for {} axis", - format!("{:?}", self).to_lowercase(), - format!("{:?}", axis).to_lowercase() - ) - }) - } - - /// The specific version of this alignment in the given system of layouting - /// axes. - pub fn to_specific(self, axes: LayoutAxes, axis: SpecificAxis) -> AlignmentKey { - let direction = axes.get_specific(axis); - if let Align(alignment) = self { - match (direction, alignment) { - (LeftToRight, Origin) | (RightToLeft, End) => Left, - (LeftToRight, End) | (RightToLeft, Origin) => Right, - (TopToBottom, Origin) | (BottomToTop, End) => Top, - (TopToBottom, End) | (BottomToTop, Origin) => Bottom, - (_, Center) => self, - } - } else { - self - } - } -} - -key!(AlignmentKey, "alignment", - "origin" => Align(Origin), - "center" => Align(Center), - "end" => Align(End), - - "left" => Left, - "top" => Top, - "right" => Right, - "bottom" => Bottom, -); |
