diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-20 20:19:30 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-20 20:19:30 +0100 |
| commit | 898728f260923a91444eb23b522d0abf01a4299b (patch) | |
| tree | 64fdd3f78e16e6428e765a8e2d99c3cd910bd9df /src/layout/mod.rs | |
| parent | 6cb9fe9064a037224b6560b69b441b72e787fa94 (diff) | |
Square, circle and ellipse 🔵
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index ae4ab89d..360c9d84 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -58,8 +58,7 @@ impl PageRun { /// Layout the page run. pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<Frame> { let areas = Areas::repeat(self.size, Spec::uniform(Expand::Fill)); - let layouted = self.child.layout(ctx, &areas); - layouted.into_frames() + self.child.layout(ctx, &areas).into_frames() } } @@ -89,29 +88,59 @@ pub struct Areas { pub last: Option<Size>, /// Whether the frames resulting from layouting into this areas should be /// shrunk to fit their content or expanded to fill the area. + /// + /// This property is handled partially by the par layouter and fully by the + /// stack layouter. pub expand: Spec<Expand>, + /// The aspect ratio the resulting frame should respect. + /// + /// This property is only handled by the stack layouter. + pub aspect: Option<f64>, } impl Areas { - /// Create a new length-1 sequence of areas with just one `area`. - pub fn once(size: Size, expand: Spec<Expand>) -> Self { + /// Create a new sequence of areas that repeats `area` indefinitely. + pub fn repeat(size: Size, expand: Spec<Expand>) -> Self { Self { current: size, full: size, backlog: vec![], - last: None, + last: Some(size), expand, + aspect: None, } } - /// Create a new sequence of areas that repeats `area` indefinitely. - pub fn repeat(size: Size, expand: Spec<Expand>) -> Self { + /// Create a new length-1 sequence of areas with just one `area`. + pub fn once(size: Size, full: Size, expand: Spec<Expand>) -> Self { Self { current: size, - full: size, + full, backlog: vec![], - last: Some(size), + last: None, expand, + aspect: None, + } + } + + /// Builder-style method for setting the aspect ratio. + pub fn with_aspect(mut self, aspect: Option<f64>) -> Self { + self.aspect = aspect; + self + } + + /// Map all areas. + pub fn map<F>(&self, mut f: F) -> Self + where + F: FnMut(Size) -> Size, + { + Self { + current: f(self.current), + full: f(self.full), + backlog: self.backlog.iter().copied().map(|s| f(s)).collect(), + last: self.last.map(f), + expand: self.expand, + aspect: self.aspect, } } |
