Fix terms show rule (#3325)

This commit is contained in:
Laurenz 2024-02-04 12:25:28 +01:00 committed by GitHub
parent a8f764ab48
commit 71ed779599
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 11 deletions

View File

@ -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)));
}
Content::sequence(seq)
.styled(ParElem::set_hanging_indent(hanging_indent + indent))
let mut padding = Sides::default();
if TextElem::dir_in(styles) == Dir::LTR {
padding.left = pad.into();
} else {
padding.right = pad.into();
}
StackElem::new(children)
.with_spacing(Some(gutter))
.pack()
.padded(padding)
.layout(engine, styles, regions)
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,11 @@
#set page(width: 200pt)
#set par(first-line-indent: 0.5cm)
- #lorem(10)
- #lorem(10)
+ #lorem(10)
+ #lorem(10)
/ Term 1: #lorem(10)
/ Term 2: #lorem(10)

View File

@ -22,6 +22,8 @@
An important energy source
for vegetarians.
And healthy!
---
// Test style change.
#set text(8pt)
@ -30,6 +32,12 @@
#set terms(hanging-indent: 30pt)
/ Second list: #lorem(5)
---
// Test RTL.
#set text(8pt, dir: rtl)
/ פרי: דבר טעים, אכיל. ומקור אנרגיה חשוב לצמחונים.
---
// Test grid like show rule.
#show terms: it => table(