diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-02-04 12:25:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-04 11:25:28 +0000 |
| commit | 71ed7795995642ee34e6272c550538897cd11d50 (patch) | |
| tree | 2ff5ecb9b948cd04a607e44b66ce4d8d096d4c79 /crates | |
| parent | a8f764ab484de735b3099870204fa613f4f2a2db (diff) | |
Fix terms show rule (#3325)
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst/src/model/terms.rs | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/crates/typst/src/model/terms.rs b/crates/typst/src/model/terms.rs index 44451be1..983012bd 100644 --- a/crates/typst/src/model/terms.rs +++ b/crates/typst/src/model/terms.rs @@ -4,9 +4,11 @@ use crate::foundations::{ cast, elem, scope, Array, Content, NativeElement, Packed, Smart, StyleChain, }; use crate::layout::{ - BlockElem, Em, Fragment, HElem, LayoutMultiple, Length, Regions, Spacing, VElem, + BlockElem, Dir, Em, Fragment, HElem, LayoutMultiple, Length, Regions, Sides, Spacing, + StackChild, StackElem, }; use crate::model::ParElem; +use crate::text::TextElem; use crate::util::Numeric; /// A list of terms and their descriptions. @@ -125,21 +127,31 @@ impl LayoutMultiple for Packed<TermsElem> { .unwrap_or_else(|| *BlockElem::below_in(styles).amount()) }; - let mut seq = vec![]; - for (i, child) in self.children().iter().enumerate() { - if i > 0 { - seq.push(VElem::new(gutter).with_weakness(1).pack()); - } - if !indent.is_zero() { - seq.push(HElem::new(indent.into()).pack()); - } + let pad = hanging_indent + indent; + let unpad = (!hanging_indent.is_zero()) + .then(|| HElem::new((-hanging_indent).into()).pack()); + + let mut children = vec![]; + for child in self.children().iter() { + let mut seq = vec![]; + seq.extend(unpad.clone()); seq.push(child.term().clone().strong()); seq.push((*separator).clone()); seq.push(child.description().clone()); + children.push(StackChild::Block(Content::sequence(seq))); + } + + let mut padding = Sides::default(); + if TextElem::dir_in(styles) == Dir::LTR { + padding.left = pad.into(); + } else { + padding.right = pad.into(); } - Content::sequence(seq) - .styled(ParElem::set_hanging_indent(hanging_indent + indent)) + StackElem::new(children) + .with_spacing(Some(gutter)) + .pack() + .padded(padding) .layout(engine, styles, regions) } } |
