diff options
| author | Pg Biel <9021226+PgBiel@users.noreply.github.com> | 2023-05-11 11:32:46 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-11 16:32:46 +0200 |
| commit | b5ad2468adafca40448035c80fdabab4b5f75a0f (patch) | |
| tree | 2b0d1ea4d29df9c21fb714d539dca7a8703452b9 /src | |
| parent | d19a4124de60b043e36e76dfe20fca193deb6a41 (diff) | |
Improve alignment of text inside raw blocks (#1034)
Diffstat (limited to 'src')
| -rw-r--r-- | src/geom/align.rs | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/geom/align.rs b/src/geom/align.rs index 69f32bee..a15ec4e6 100644 --- a/src/geom/align.rs +++ b/src/geom/align.rs @@ -106,6 +106,18 @@ impl From<Align> for GenAlign { } } +impl From<HorizontalAlign> for GenAlign { + fn from(align: HorizontalAlign) -> Self { + align.0 + } +} + +impl From<VerticalAlign> for GenAlign { + fn from(align: VerticalAlign) -> Self { + align.0 + } +} + impl Debug for GenAlign { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { @@ -184,7 +196,45 @@ impl Fold for GenAlign { } } -#[derive(Copy, Clone, Eq, PartialEq, Debug)] +/// Utility struct to restrict a passed alignment value to the horizontal axis +/// on cast. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub struct HorizontalAlign(pub GenAlign); + +cast_from_value! { + HorizontalAlign, + align: GenAlign => { + if align.axis() != Axis::X { + Err("alignment must be horizontal")?; + } + Self(align) + }, +} + +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! { + VerticalAlign, + align: GenAlign => { + if align.axis() != Axis::Y { + Err("alignment must be vertical")?; + } + Self(align) + }, +} + +cast_to_value! { + v: VerticalAlign => v.0.into() +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum LeftRightAlternator { Left, Right, |
