summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-09-27 13:40:56 +0200
committerLaurenz <laurmaedje@gmail.com>2021-09-27 13:45:18 +0200
commite10b3d838a75ea351f8477e07f2e1e647f4539dc (patch)
tree286183d4b7492ecf95b7a8b0a9c245bb85191db5 /src/library
parentff37a2893dc7f0a29faa7cc57ccb4d746f483bed (diff)
Fix panic due to bad alignments in stack function
Diffstat (limited to 'src/library')
-rw-r--r--src/library/layout.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs
index 8f645869..e958f3a3 100644
--- a/src/library/layout.rs
+++ b/src/library/layout.rs
@@ -192,11 +192,6 @@ pub fn stack(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
let children: Vec<Template> = args.all().collect();
Ok(Value::Template(Template::from_block(move |state| {
- let children = children
- .iter()
- .map(|child| StackChild::Any(child.to_stack(state).into(), state.aligns))
- .collect();
-
let mut dirs = Gen::new(None, dir).unwrap_or(state.dirs);
// If the directions become aligned, fix up the inline direction since
@@ -205,6 +200,19 @@ pub fn stack(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
dirs.inline = state.dirs.block;
}
+ // Use the current alignments for all children, but take care to apply
+ // them to the correct axes (by swapping them if the stack axes are
+ // different from the state axes).
+ let mut aligns = state.aligns;
+ if dirs.block.axis() == state.dirs.inline.axis() {
+ aligns = Gen::new(aligns.block, aligns.inline);
+ }
+
+ let children = children
+ .iter()
+ .map(|child| StackChild::Any(child.to_stack(state).into(), aligns))
+ .collect();
+
StackNode { dirs, children }
})))
}
@@ -233,9 +241,6 @@ pub fn grid(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
);
Ok(Value::Template(Template::from_block(move |state| {
- let children =
- children.iter().map(|child| child.to_stack(&state).into()).collect();
-
// If the directions become aligned, try to fix up the direction which
// is not user-defined.
let mut dirs = Gen::new(column_dir, row_dir).unwrap_or(state.dirs);
@@ -253,6 +258,9 @@ pub fn grid(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
};
}
+ let children =
+ children.iter().map(|child| child.to_stack(&state).into()).collect();
+
GridNode {
dirs,
tracks: tracks.clone(),