diff options
| author | Martin Haug <mhaug@live.de> | 2022-06-08 12:30:10 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-06-08 12:30:10 +0200 |
| commit | 6d8b65c4b24206a1482ea143791d7a1c410a4313 (patch) | |
| tree | e11046d9b92928969b904a63cc6f59540b95d0a7 /src/library/structure | |
| parent | 4640585fbdf72df993dbed46799844aa78996cce (diff) | |
More consistent role application
Diffstat (limited to 'src/library/structure')
| -rw-r--r-- | src/library/structure/heading.rs | 9 | ||||
| -rw-r--r-- | src/library/structure/list.rs | 20 | ||||
| -rw-r--r-- | src/library/structure/table.rs | 7 |
3 files changed, 13 insertions, 23 deletions
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs index 285793dd..a376bf09 100644 --- a/src/library/structure/heading.rs +++ b/src/library/structure/heading.rs @@ -66,13 +66,8 @@ impl HeadingNode { impl Show for HeadingNode { fn unguard(&self, sel: Selector) -> ShowNode { - let mut map = StyleMap::with_role(Role::Heading(self.level.get())); - map.push(StyleEntry::Unguard(sel)); - Self { - body: self.body.clone().styled_with_map(map), - ..*self - } - .pack() + let body = self.body.unguard(sel).role(Role::Heading(self.level.get())); + Self { body, ..*self }.pack() } fn encode(&self, _: StyleChain) -> Dict { diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs index 563426b4..1c0e251f 100644 --- a/src/library/structure/list.rs +++ b/src/library/structure/list.rs @@ -77,12 +77,9 @@ impl<const L: ListKind> ListNode<L> { impl<const L: ListKind> Show for ListNode<L> { fn unguard(&self, sel: Selector) -> ShowNode { - let mut map = StyleMap::with_role(Role::ListItemBody); - map.push(StyleEntry::Unguard(sel)); - Self { items: self.items.map(|item| ListItem { - body: Box::new(item.body.clone().styled_with_map(map.clone())), + body: Box::new(item.body.unguard(sel).role(Role::ListItemBody)), ..*item }), ..*self @@ -113,11 +110,14 @@ impl<const L: ListKind> Show for ListNode<L> { for (item, map) in self.items.iter() { number = item.number.unwrap_or(number); - let mut label_map = map.clone(); - label_map.push(StyleEntry::Role(Role::ListLabel)); - cells.push(LayoutNode::default()); - cells.push(label.resolve(ctx, L, number)?.styled_with_map(label_map).pack()); + cells.push( + label + .resolve(ctx, L, number)? + .styled_with_map(map.clone()) + .role(Role::ListLabel) + .pack(), + ); cells.push(LayoutNode::default()); cells.push((*item.body).clone().styled_with_map(map.clone()).pack()); number += 1; @@ -163,9 +163,7 @@ impl<const L: ListKind> Show for ListNode<L> { } } - Ok(realized - .styled_with_map(StyleMap::with_role(Role::List(L == ORDERED))) - .spaced(above, below)) + Ok(realized.role(Role::List(L == ORDERED)).spaced(above, below)) } } diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs index 60115612..118e48ca 100644 --- a/src/library/structure/table.rs +++ b/src/library/structure/table.rs @@ -50,16 +50,13 @@ impl TableNode { impl Show for TableNode { fn unguard(&self, sel: Selector) -> ShowNode { - let mut map = StyleMap::with_role(Role::TableCell); - map.push(StyleEntry::Unguard(sel)); - Self { tracks: self.tracks.clone(), gutter: self.gutter.clone(), cells: self .cells .iter() - .map(|cell| cell.clone().styled_with_map(map.clone())) + .map(|cell| cell.unguard(sel).role(Role::TableCell)) .collect(), } .pack() @@ -110,7 +107,7 @@ impl Show for TableNode { cells, semantic: GridSemantics::Table, }) - .styled_with_map(StyleMap::with_role(Role::Table))) + .role(Role::Table)) } fn finalize( |
