diff options
| author | Martin <mhaug@live.de> | 2021-04-07 13:50:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-07 13:50:21 +0200 |
| commit | df58a4d89b67783b1ffc5c3b7282302d59db8c70 (patch) | |
| tree | 2bdc3a7ad1704ccee7c14972df1fa3cb9c77097a /src/layout/stack.rs | |
| parent | 318eb9021edc493f5181247dbb7963de34126688 (diff) | |
| parent | 3d2ee54848db80a8ede7e00fd5a53bc059138122 (diff) | |
Merge pull request #19 from typst/shape-runs 🔀
Text work
Diffstat (limited to 'src/layout/stack.rs')
| -rw-r--r-- | src/layout/stack.rs | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 79fde72d..b69936ba 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -28,7 +28,13 @@ impl Layout for StackNode { match *child { StackChild::Spacing(amount) => layouter.push_spacing(amount), StackChild::Any(ref node, aligns) => { - for frame in node.layout(ctx, &layouter.areas) { + let mut frames = node.layout(ctx, &layouter.areas).into_iter(); + if let Some(frame) = frames.next() { + layouter.push_frame(frame, aligns); + } + + for frame in frames { + layouter.finish_area(); layouter.push_frame(frame, aligns); } } @@ -116,32 +122,39 @@ impl StackLayouter { size = Size::new(width, width / aspect); } - size.switch(self.main) + size }; - let mut output = Frame::new(full_size.switch(self.main).to_size()); + let mut output = Frame::new(full_size, full_size.height); + let mut first = true; + let full_size = full_size.switch(self.main); for (before, frame, aligns) in std::mem::take(&mut self.frames) { let child_size = frame.size.switch(self.main); // Align along the main axis. - let main = aligns.main.resolve(if self.dirs.main.is_positive() { - let after_with_self = self.size.main - before; - before .. full_size.main - after_with_self - } else { - let before_with_self = before + child_size.main; - let after = self.size.main - (before + child_size.main); - full_size.main - before_with_self .. after - }); + let main = aligns.main.resolve( + self.dirs.main, + if self.dirs.main.is_positive() { + before .. before + full_size.main - self.size.main + } else { + self.size.main - (before + child_size.main) + .. full_size.main - (before + child_size.main) + }, + ); // Align along the cross axis. - let cross = aligns.cross.resolve(if self.dirs.cross.is_positive() { - Length::ZERO .. full_size.cross - child_size.cross - } else { - full_size.cross - child_size.cross .. Length::ZERO - }); + let cross = aligns.cross.resolve( + self.dirs.cross, + Length::ZERO .. full_size.cross - child_size.cross, + ); let pos = Gen::new(main, cross).switch(self.main).to_point(); + if first { + output.baseline = pos.y + frame.baseline; + first = false; + } + output.push_frame(pos, frame); } |
