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/library/layout | |
| parent | e1d7edb7c1845e6df6f5e23e3baf7bc88159eade (diff) | |
Start & end alignment
Diffstat (limited to 'src/library/layout')
| -rw-r--r-- | src/library/layout/align.rs | 28 | ||||
| -rw-r--r-- | src/library/layout/flow.rs | 5 | ||||
| -rw-r--r-- | src/library/layout/place.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/stack.rs | 3 |
4 files changed, 12 insertions, 26 deletions
diff --git a/src/library/layout/align.rs b/src/library/layout/align.rs index b08e5fce..699a908c 100644 --- a/src/library/layout/align.rs +++ b/src/library/layout/align.rs @@ -5,7 +5,7 @@ use crate::library::text::ParNode; #[derive(Debug, Hash)] pub struct AlignNode { /// How to align the node horizontally and vertically. - pub aligns: Spec<Option<Align>>, + pub aligns: Spec<Option<RawAlign>>, /// The node to be aligned. pub child: LayoutNode, } @@ -42,30 +42,14 @@ impl Layout for AlignNode { // Align in the target size. The target size depends on whether we // should expand. let target = regions.expand.select(region, frame.size); - let default = Spec::new(Align::Left, Align::Top); - let aligns = self.aligns.unwrap_or(default); + let aligns = self + .aligns + .map(|align| align.resolve(styles)) + .unwrap_or(Spec::new(Align::Left, Align::Top)); + Arc::make_mut(frame).resize(target, aligns); } Ok(frames) } } - -dynamic! { - Align: "alignment", -} - -dynamic! { - Spec<Align>: "2d alignment", -} - -castable! { - Spec<Option<Align>>, - Expected: "1d or 2d alignment", - @align: Align => { - let mut aligns = Spec::default(); - aligns.set(align.axis(), Some(*align)); - aligns - }, - @aligns: Spec<Align> => aligns.map(Some), -} diff --git a/src/library/layout/flow.rs b/src/library/layout/flow.rs index ffda6925..a53b0304 100644 --- a/src/library/layout/flow.rs +++ b/src/library/layout/flow.rs @@ -189,6 +189,7 @@ impl FlowLayouter { // Vertical align node alignment is respected by the flow node. node.downcast::<AlignNode>() .and_then(|aligned| aligned.aligns.y) + .map(|align| align.resolve(styles)) .unwrap_or(Align::Top), ); @@ -238,8 +239,8 @@ impl FlowLayouter { } FlowItem::Frame(frame, aligns) => { ruler = ruler.max(aligns.y); - let x = aligns.x.resolve(size.x - frame.size.x); - let y = offset + ruler.resolve(size.y - self.used.y); + let x = aligns.x.position(size.x - frame.size.x); + let y = offset + ruler.position(size.y - self.used.y); let pos = Point::new(x, y); offset += frame.size.y; output.push_frame(pos, frame); diff --git a/src/library/layout/place.rs b/src/library/layout/place.rs index 2d4ebc4d..eefa6a9b 100644 --- a/src/library/layout/place.rs +++ b/src/library/layout/place.rs @@ -8,9 +8,9 @@ pub struct PlaceNode(pub LayoutNode); #[node] impl PlaceNode { fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { - let aligns = args.find()?.unwrap_or(Spec::with_x(Some(Align::Left))); let tx = args.named("dx")?.unwrap_or_default(); let ty = args.named("dy")?.unwrap_or_default(); + let aligns = args.find()?.unwrap_or(Spec::with_x(Some(RawAlign::Start))); let body: LayoutNode = args.expect("body")?; Ok(Content::block(Self( body.moved(Point::new(tx, ty)).aligned(aligns), diff --git a/src/library/layout/stack.rs b/src/library/layout/stack.rs index b0e2e160..312757f3 100644 --- a/src/library/layout/stack.rs +++ b/src/library/layout/stack.rs @@ -175,6 +175,7 @@ impl StackLayouter { let align = node .downcast::<AlignNode>() .and_then(|node| node.aligns.get(self.axis)) + .map(|align| align.resolve(styles)) .unwrap_or(self.dir.start().into()); let frames = node.layout(ctx, &self.regions, styles)?; @@ -229,7 +230,7 @@ impl StackLayouter { // Align along the block axis. let parent = size.get(self.axis); let child = frame.size.get(self.axis); - let block = ruler.resolve(parent - self.used.main) + let block = ruler.position(parent - self.used.main) + if self.dir.is_positive() { cursor } else { |
