diff options
| -rw-r--r-- | src/eval/show.rs | 5 | ||||
| -rw-r--r-- | src/library/list.rs | 97 | ||||
| -rw-r--r-- | tests/typ/style/construct.typ | 2 | ||||
| -rw-r--r-- | tests/typ/style/set-site.typ | 2 |
4 files changed, 61 insertions, 45 deletions
diff --git a/src/eval/show.rs b/src/eval/show.rs index a85c70e2..b0fb8172 100644 --- a/src/eval/show.rs +++ b/src/eval/show.rs @@ -43,10 +43,7 @@ impl ShowNode { impl Show for ShowNode { fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { - ctx.query((self, styles), |ctx, (node, styles)| { - node.0.show(ctx, styles) - }) - .clone() + self.0.show(ctx, styles) } fn pack(self) -> ShowNode { diff --git a/src/library/list.rs b/src/library/list.rs index b757e4b2..baa8a0c9 100644 --- a/src/library/list.rs +++ b/src/library/list.rs @@ -33,9 +33,13 @@ impl<const L: ListKind> ListNode<L> { /// The spacing between the list items of a non-wide list. pub const SPACING: Linear = Linear::zero(); /// The indentation of each item's label. - pub const LABEL_INDENT: Linear = Relative::new(0.0).into(); + pub const INDENT: Linear = Relative::new(0.0).into(); /// The space between the label and the body of each item. pub const BODY_INDENT: Linear = Relative::new(0.5).into(); + /// The extra padding above the list. + pub const ABOVE: Length = Length::zero(); + /// The extra padding below the list. + pub const BELOW: Length = Length::zero(); fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { Ok(Template::show(Self { @@ -52,54 +56,69 @@ impl<const L: ListKind> ListNode<L> { impl<const L: ListKind> Show for ListNode<L> { fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { - if let Some(template) = styles.show( + let template = if let Some(template) = styles.show( self, ctx, self.items.iter().map(|item| Value::Template((*item.body).clone())), )? { - return Ok(template); - } + template + } else { + let mut children = vec![]; + let mut number = self.start; + + let label = styles.get_ref(Self::LABEL); + + for item in &self.items { + number = item.number.unwrap_or(number); + if L == UNORDERED { + number = 1; + } + + children.push(LayoutNode::default()); + children.push(label.resolve(ctx, L, number)?.pack()); + children.push(LayoutNode::default()); + children.push((*item.body).clone().pack()); + number += 1; + } - let mut children = vec![]; - let mut number = self.start; + let em = styles.get(TextNode::SIZE).abs; + let leading = styles.get(ParNode::LEADING); + let spacing = if self.wide { + styles.get(ParNode::SPACING) + } else { + styles.get(Self::SPACING) + }; + + let gutter = (leading + spacing).resolve(em); + let indent = styles.get(Self::INDENT).resolve(em); + let body_indent = styles.get(Self::BODY_INDENT).resolve(em); + + Template::block(GridNode { + tracks: Spec::with_x(vec![ + TrackSizing::Linear(indent.into()), + TrackSizing::Auto, + TrackSizing::Linear(body_indent.into()), + TrackSizing::Auto, + ]), + gutter: Spec::with_y(vec![TrackSizing::Linear(gutter.into())]), + children, + }) + }; - let label = styles.get_ref(Self::LABEL); + let mut seq = vec![]; + let above = styles.get(Self::ABOVE); + if !above.is_zero() { + seq.push(Template::Vertical(above.into())); + } - for item in &self.items { - number = item.number.unwrap_or(number); - if L == UNORDERED { - number = 1; - } + seq.push(template); - children.push(LayoutNode::default()); - children.push(label.resolve(ctx, L, number)?.pack()); - children.push(LayoutNode::default()); - children.push((*item.body).clone().pack()); - number += 1; + let below = styles.get(Self::BELOW); + if !below.is_zero() { + seq.push(Template::Vertical(below.into())); } - let em = styles.get(TextNode::SIZE).abs; - let leading = styles.get(ParNode::LEADING); - let spacing = if self.wide { - styles.get(ParNode::SPACING) - } else { - styles.get(Self::SPACING) - }; - - let gutter = (leading + spacing).resolve(em); - let label_indent = styles.get(Self::LABEL_INDENT).resolve(em); - let body_indent = styles.get(Self::BODY_INDENT).resolve(em); - - Ok(Template::block(GridNode { - tracks: Spec::with_x(vec![ - TrackSizing::Linear(label_indent.into()), - TrackSizing::Auto, - TrackSizing::Linear(body_indent.into()), - TrackSizing::Auto, - ]), - gutter: Spec::with_y(vec![TrackSizing::Linear(gutter.into())]), - children, - })) + Ok(Template::sequence(seq)) } } diff --git a/tests/typ/style/construct.typ b/tests/typ/style/construct.typ index 78a74881..8bc348a9 100644 --- a/tests/typ/style/construct.typ +++ b/tests/typ/style/construct.typ @@ -30,4 +30,4 @@ A #rect(fill: yellow, padding: 5pt, rect()) B --- // The inner list should not be indented extra. -[#set text(100%);#list(label-indent: 20pt, list[A])] +[#set text(100%);#list(indent: 20pt, list[A])] diff --git a/tests/typ/style/set-site.typ b/tests/typ/style/set-site.typ index 20d35f04..dc9c9e02 100644 --- a/tests/typ/style/set-site.typ +++ b/tests/typ/style/set-site.typ @@ -15,7 +15,7 @@ Hello *{x}* ] - Fruit -[#set list(label-indent: 10pt) +[#set list(indent: 10pt) #fruit] - No more fruit |
