diff options
Diffstat (limited to 'src/library/boxed.rs')
| -rw-r--r-- | src/library/boxed.rs | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/library/boxed.rs b/src/library/boxed.rs index 2d0d6e6b..3e9a4c7a 100644 --- a/src/library/boxed.rs +++ b/src/library/boxed.rs @@ -1,3 +1,5 @@ +use smallvec::smallvec; + use crate::func::prelude::*; use super::maps::ExtentMap; @@ -19,18 +21,34 @@ function! { } layout(self, mut ctx) { + ctx.repeat = false; ctx.debug = self.debug; - let space = &mut ctx.spaces[0]; - self.map.apply_with(ctx.axes, |axis, p| { - let entity = match axis { - Horizontal => { space.expansion.horizontal = true; &mut space.dimensions.x }, - Vertical => { space.expansion.vertical = true; &mut space.dimensions.y }, - }; + let map = self.map.dedup(ctx.axes)?; + + // Try to layout this box in all spaces. + let mut error = None; + for &space in &ctx.spaces { + let mut ctx = ctx.clone(); + let mut space = space; + + for &axis in &[Horizontal, Vertical] { + if let Some(psize) = map.get(axis) { + let size = psize.concretize(ctx.base.get(axis)); + *ctx.base.get_mut(axis) = size; + *space.dimensions.get_mut(axis) = size; + *space.expansion.get_mut(axis) = true; + } + } - *entity = p.concretize(*entity) - })?; + ctx.spaces = smallvec![space]; + + match layout(&self.body, ctx) { + Ok(layouts) => return Ok(vec![AddMultiple(layouts)]), + Err(err) => error = Some(err), + } + } - vec![AddMultiple(layout_tree(&self.body, ctx)?)] + return Err(error.expect("expected at least one space")); } } |
