summaryrefslogtreecommitdiff
path: root/src/geom/align.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
commit25b5bd117529cd04bb789e1988eb3a3db8025a0e (patch)
tree2fbb4650903123da047a1f1f11a0abda95286e12 /src/geom/align.rs
parent6ab7760822ccd24b4ef126d4737d41f1be15fe19 (diff)
Fully untyped model
Diffstat (limited to 'src/geom/align.rs')
-rw-r--r--src/geom/align.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/geom/align.rs b/src/geom/align.rs
index 1e9bde52..b14e6775 100644
--- a/src/geom/align.rs
+++ b/src/geom/align.rs
@@ -115,3 +115,51 @@ impl Debug for GenAlign {
}
}
}
+
+cast_from_value! {
+ GenAlign: "alignment",
+}
+
+cast_from_value! {
+ Axes<GenAlign>: "2d alignment",
+}
+
+cast_from_value! {
+ Axes<Option<GenAlign>>,
+ align: GenAlign => {
+ let mut aligns = Axes::default();
+ aligns.set(align.axis(), Some(align));
+ aligns
+ },
+ aligns: Axes<GenAlign> => aligns.map(Some),
+}
+
+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 Resolve for GenAlign {
+ type Output = Align;
+
+ fn resolve(self, styles: StyleChain) -> Self::Output {
+ let dir = item!(dir)(styles);
+ match self {
+ Self::Start => dir.start().into(),
+ Self::End => dir.end().into(),
+ Self::Specific(align) => align,
+ }
+ }
+}
+
+impl Fold for GenAlign {
+ type Output = Self;
+
+ fn fold(self, _: Self::Output) -> Self::Output {
+ self
+ }
+}