mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
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,
|
cast, elem, scope, Array, Content, NativeElement, Packed, Smart, StyleChain,
|
||||||
};
|
};
|
||||||
use crate::layout::{
|
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::model::ParElem;
|
||||||
|
use crate::text::TextElem;
|
||||||
use crate::util::Numeric;
|
use crate::util::Numeric;
|
||||||
|
|
||||||
/// A list of terms and their descriptions.
|
/// A list of terms and their descriptions.
|
||||||
@ -125,21 +127,31 @@ impl LayoutMultiple for Packed<TermsElem> {
|
|||||||
.unwrap_or_else(|| *BlockElem::below_in(styles).amount())
|
.unwrap_or_else(|| *BlockElem::below_in(styles).amount())
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut seq = vec![];
|
let pad = hanging_indent + indent;
|
||||||
for (i, child) in self.children().iter().enumerate() {
|
let unpad = (!hanging_indent.is_zero())
|
||||||
if i > 0 {
|
.then(|| HElem::new((-hanging_indent).into()).pack());
|
||||||
seq.push(VElem::new(gutter).with_weakness(1).pack());
|
|
||||||
}
|
let mut children = vec![];
|
||||||
if !indent.is_zero() {
|
for child in self.children().iter() {
|
||||||
seq.push(HElem::new(indent.into()).pack());
|
let mut seq = vec![];
|
||||||
}
|
seq.extend(unpad.clone());
|
||||||
seq.push(child.term().clone().strong());
|
seq.push(child.term().clone().strong());
|
||||||
seq.push((*separator).clone());
|
seq.push((*separator).clone());
|
||||||
seq.push(child.description().clone());
|
seq.push(child.description().clone());
|
||||||
|
children.push(StackChild::Block(Content::sequence(seq)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Content::sequence(seq)
|
let mut padding = Sides::default();
|
||||||
.styled(ParElem::set_hanging_indent(hanging_indent + indent))
|
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)
|
.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
|
An important energy source
|
||||||
for vegetarians.
|
for vegetarians.
|
||||||
|
|
||||||
|
And healthy!
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test style change.
|
// Test style change.
|
||||||
#set text(8pt)
|
#set text(8pt)
|
||||||
@ -30,6 +32,12 @@
|
|||||||
#set terms(hanging-indent: 30pt)
|
#set terms(hanging-indent: 30pt)
|
||||||
/ Second list: #lorem(5)
|
/ Second list: #lorem(5)
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test RTL.
|
||||||
|
#set text(8pt, dir: rtl)
|
||||||
|
|
||||||
|
/ פרי: דבר טעים, אכיל. ומקור אנרגיה חשוב לצמחונים.
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test grid like show rule.
|
// Test grid like show rule.
|
||||||
#show terms: it => table(
|
#show terms: it => table(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user