Fix terms show rule (#3325)
This commit is contained in:
parent
a8f764ab48
commit
71ed779599
@ -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)
|
||||
}
|
||||
}
|
||||
|
BIN
tests/ref/bugs/1050-terms-indent.png
Normal file
BIN
tests/ref/bugs/1050-terms-indent.png
Normal file
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 |
11
tests/typ/bugs/1050-terms-indent.typ
Normal file
11
tests/typ/bugs/1050-terms-indent.typ
Normal 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)
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user