diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-11 14:42:20 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-11 14:42:20 +0200 |
| commit | 4017b5a9f67e06145129d75de452c8a42e2d2f5a (patch) | |
| tree | 8ce9c6f80faa75ed62d4f7fbe31d3ceee6e8d4ba /src/layout | |
| parent | 4dbd9285c91d59d527f4324df4aaf239ecb007ca (diff) | |
Push some nodes directly into the stack
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/fixed.rs | 4 | ||||
| -rw-r--r-- | src/layout/mod.rs | 20 | ||||
| -rw-r--r-- | src/layout/par.rs | 4 | ||||
| -rw-r--r-- | src/layout/stack.rs | 22 |
4 files changed, 30 insertions, 20 deletions
diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index 7c28e8e5..233c27f3 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -19,8 +19,8 @@ impl Layout for FixedNode { self.height.map_or(current.height, |h| h.resolve(base.height)), ); - let fixed = Spec::new(self.width.is_some(), self.height.is_some()); - let regions = Regions::one(size, fixed); + let expand = Spec::new(self.width.is_some(), self.height.is_some()); + let regions = Regions::one(size, expand); self.child.layout(ctx, ®ions) } } diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 9d8549e6..4153fc3c 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -64,8 +64,8 @@ impl PageRun { // 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 regions = Regions::repeat(self.size, fixed); + let expand = Spec::new(width.is_finite(), height.is_finite()); + let regions = Regions::repeat(self.size, expand); self.child.layout(ctx, ®ions) } } @@ -214,34 +214,34 @@ pub struct Regions { pub backlog: Vec<Size>, /// The final region that is repeated once the backlog is drained. pub last: Option<Size>, - /// Whether layouting into these regions should produce frames of the exact - /// size of `current` instead of shrinking to fit the content. + /// Whether nodes should expand to fill the regions instead of shrinking to + /// fit the content. /// /// This property is only handled by nodes that have the ability to control /// their own size. - pub fixed: Spec<bool>, + pub expand: Spec<bool>, } impl Regions { /// Create a new region sequence with exactly one region. - pub fn one(size: Size, fixed: Spec<bool>) -> Self { + pub fn one(size: Size, expand: Spec<bool>) -> Self { Self { current: size, base: size, backlog: vec![], last: None, - fixed, + expand, } } /// Create a new sequence of same-size regions that repeats indefinitely. - pub fn repeat(size: Size, fixed: Spec<bool>) -> Self { + pub fn repeat(size: Size, expand: Spec<bool>) -> Self { Self { current: size, base: size, backlog: vec![], last: Some(size), - fixed, + expand, } } @@ -255,7 +255,7 @@ impl Regions { base: f(self.base), backlog: self.backlog.iter().copied().map(|s| f(s)).collect(), last: self.last.map(f), - fixed: self.fixed, + expand: self.expand, } } diff --git a/src/layout/par.rs b/src/layout/par.rs index d51bad3e..24185458 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -92,7 +92,7 @@ impl Debug for ParChild { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { Self::Spacing(amount) => write!(f, "Spacing({:?})", amount), - Self::Text(text, _, align) => write!(f, "Text({:?}, {:?})", text, align), + Self::Text(text, align, _) => write!(f, "Text({:?}, {:?})", text, align), Self::Any(any, align) => { f.debug_tuple("Any").field(any).field(align).finish() } @@ -304,7 +304,7 @@ impl<'a> LineStack<'a> { } fn finish_region(&mut self, ctx: &LayoutContext) { - if self.regions.fixed.horizontal { + if self.regions.expand.horizontal { self.size.width = self.regions.current.width; } diff --git a/src/layout/stack.rs b/src/layout/stack.rs index e4c0708d..7049f60c 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -44,6 +44,8 @@ struct StackLayouter<'a> { stack: &'a StackNode, /// The axis of the main direction. main: SpecAxis, + /// Whether the stack should expand to fill the region. + expand: Spec<bool>, /// The region to layout into. regions: Regions, /// Offset, alignment and frame for all children that fit into the current @@ -62,19 +64,27 @@ struct StackLayouter<'a> { impl<'a> StackLayouter<'a> { fn new(stack: &'a StackNode, mut regions: Regions) -> Self { + let main = stack.dirs.main.axis(); + let full = regions.current; + let expand = regions.expand; + + // Disable expansion on the main axis for children. + *regions.expand.get_mut(main) = false; + if let Some(aspect) = stack.aspect { regions.apply_aspect_ratio(aspect); } Self { stack, - main: stack.dirs.main.axis(), + main, + expand, + regions, finished: vec![], frames: vec![], - full: regions.current, + full, used: Gen::zero(), ruler: Align::Start, - regions, } } @@ -138,13 +148,13 @@ impl<'a> StackLayouter<'a> { fn finish_region(&mut self) { let used = self.used.to_size(self.main); - let fixed = self.regions.fixed; + let expand = self.expand; // Determine the stack's size dependening on whether the region is // fixed. let mut stack_size = Size::new( - if fixed.horizontal { self.full.width } else { used.width }, - if fixed.vertical { self.full.height } else { used.height }, + if expand.horizontal { self.full.width } else { used.width }, + if expand.vertical { self.full.height } else { used.height }, ); // Make sure the stack's size satisfies the aspect ratio. |
