diff options
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 6f28fcb9..dad378f5 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -54,7 +54,11 @@ pub struct PageRun { 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)); + // When one of the lengths is infinite the page fits its content along + // that axis. + let Size { width, height } = self.size; + let fixed = Spec::new(width.is_finite(), height.is_finite()); + let areas = Areas::repeat(self.size, fixed); self.child.layout(ctx, &areas) } } @@ -146,12 +150,11 @@ pub struct Areas { pub backlog: Vec<Size>, /// The final area that is repeated when the backlog is empty. 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. + /// Whether the frames resulting from layouting into this areas should + /// expand to the fixed size defined by `current`. /// - /// This property is handled partially by the par layouter and fully by the - /// stack layouter. - pub expand: Spec<Expand>, + /// If this is false, the frame will shrink to fit its content. + pub fixed: Spec<bool>, /// The aspect ratio the resulting frame should respect. /// /// This property is only handled by the stack layouter. @@ -159,26 +162,26 @@ pub struct Areas { } impl Areas { - /// 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, fixed: Spec<bool>) -> Self { Self { current: size, - full: size, + full, backlog: vec![], - last: Some(size), - expand, + last: None, + fixed, aspect: None, } } - /// Create a new length-1 sequence of areas with just one `area`. - pub fn once(size: Size, full: Size, expand: Spec<Expand>) -> Self { + /// Create a new sequence of areas that repeats `area` indefinitely. + pub fn repeat(size: Size, fixed: Spec<bool>) -> Self { Self { current: size, - full, + full: size, backlog: vec![], - last: None, - expand, + last: Some(size), + fixed, aspect: None, } } @@ -199,7 +202,7 @@ impl Areas { full: f(self.full), backlog: self.backlog.iter().copied().map(|s| f(s)).collect(), last: self.last.map(f), - expand: self.expand, + fixed: self.fixed, aspect: self.aspect, } } @@ -222,24 +225,3 @@ impl Areas { }) } } - -/// Whether to expand or shrink a node along an axis. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub enum Expand { - /// Fit the content. - Fit, - /// Fill the available space. - Fill, -} - -impl Expand { - /// Resolve the expansion to either the `fit` or `fill` length. - /// - /// Prefers `fit` if `fill` is infinite. - pub fn resolve(self, fit: Length, fill: Length) -> Length { - match self { - Self::Fill if fill.is_finite() => fill, - _ => fit, - } - } -} |
