diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-08 15:01:55 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-08 15:01:55 +0200 |
| commit | 977ac77e6a3298be2644a8231e93acbef9f7f396 (patch) | |
| tree | 9c40765b862bc583275f692113fe36924c323ccc /src/eval/raw.rs | |
| parent | e1d7edb7c1845e6df6f5e23e3baf7bc88159eade (diff) | |
Start & end alignment
Diffstat (limited to 'src/eval/raw.rs')
| -rw-r--r-- | src/eval/raw.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/eval/raw.rs b/src/eval/raw.rs new file mode 100644 index 00000000..337638f9 --- /dev/null +++ b/src/eval/raw.rs @@ -0,0 +1,49 @@ +use std::fmt::{self, Debug, Formatter}; + +use super::{Resolve, StyleChain}; +use crate::geom::{Align, SpecAxis}; +use crate::library::text::ParNode; + +/// The unresolved alignment representation. +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +pub enum RawAlign { + /// Align at the start side of the text direction. + Start, + /// Align at the end side of the text direction. + End, + /// Align at a specific alignment. + Specific(Align), +} + +impl Resolve for RawAlign { + type Output = Align; + + fn resolve(self, styles: StyleChain) -> Self::Output { + let dir = styles.get(ParNode::DIR); + match self { + Self::Start => dir.start().into(), + Self::End => dir.end().into(), + Self::Specific(align) => align, + } + } +} + +impl RawAlign { + /// The axis this alignment belongs to. + pub const fn axis(self) -> SpecAxis { + match self { + Self::Start | Self::End => SpecAxis::Horizontal, + Self::Specific(align) => align.axis(), + } + } +} + +impl Debug for RawAlign { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Self::Start => f.pad("left"), + Self::End => f.pad("center"), + Self::Specific(align) => align.fmt(f), + } + } +} |
