diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-25 20:51:16 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-25 20:51:16 +0100 |
| commit | 393d74f9bb0d4c71a69108d5be261103c39f47f3 (patch) | |
| tree | a1d4219de2d8fbec1a16ac3760a95e0b7c9529c5 /src/library/align.rs | |
| parent | 304d9dd1107504f3925c2593dd279ea6616defab (diff) | |
Layout improvements
Diffstat (limited to 'src/library/align.rs')
| -rw-r--r-- | src/library/align.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/library/align.rs b/src/library/align.rs index f788b325..6f079b7b 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -34,28 +34,29 @@ impl Layout for AlignNode { pod.expand.x &= self.aligns.x.is_none(); pod.expand.y &= self.aligns.y.is_none(); + // Layout the child. let mut frames = self.child.layout(ctx, &pod); - for (Constrained { item: frame, cts }, (current, _)) in + + for (Constrained { item: frame, cts }, (current, base)) in frames.iter_mut().zip(regions.iter()) { - let canvas = Size::new( + // The possibly larger size in which we align the frame. + let new = Size::new( if regions.expand.x { current.w } else { frame.size.w }, if regions.expand.y { current.h } else { frame.size.h }, ); let aligns = self.aligns.unwrap_or(Spec::new(Align::Left, Align::Top)); - let offset = Point::new( - aligns.x.resolve(canvas.w - frame.size.w), - aligns.y.resolve(canvas.h - frame.size.h), - ); - - let frame = Rc::make_mut(frame); - frame.size = canvas; - frame.baseline += offset.y; - frame.translate(offset); + Rc::make_mut(frame).resize(new, aligns); + // Set constraints. cts.expand = regions.expand; - cts.exact = current.to_spec().map(Some); + cts.base.x.and_set(Some(base.w)); + cts.base.y.and_set(Some(base.h)); + cts.exact = Spec::new( + regions.expand.x.then(|| current.w), + regions.expand.y.then(|| current.h), + ); } frames |
