diff options
| author | Martin Haug <mhaug@live.de> | 2022-06-04 12:57:45 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-06-04 12:57:45 +0200 |
| commit | 4640585fbdf72df993dbed46799844aa78996cce (patch) | |
| tree | 38a09389885a61068970441d6d27178a2ae4f115 /src/library/structure | |
| parent | a937462491a63f5cff3551b5bb8bc45fb350f0b6 (diff) | |
First iteration of outline items
Diffstat (limited to 'src/library/structure')
| -rw-r--r-- | src/library/structure/heading.rs | 12 | ||||
| -rw-r--r-- | src/library/structure/list.rs | 20 | ||||
| -rw-r--r-- | src/library/structure/table.rs | 16 |
3 files changed, 38 insertions, 10 deletions
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs index a0973b90..285793dd 100644 --- a/src/library/structure/heading.rs +++ b/src/library/structure/heading.rs @@ -1,6 +1,7 @@ use crate::library::layout::BlockSpacing; use crate::library::prelude::*; use crate::library::text::{FontFamily, TextNode, TextSize}; +use crate::model::StyleEntry; /// A section heading. #[derive(Debug, Hash)] @@ -65,7 +66,13 @@ impl HeadingNode { impl Show for HeadingNode { fn unguard(&self, sel: Selector) -> ShowNode { - Self { body: self.body.unguard(sel), ..*self }.pack() + 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() } fn encode(&self, _: StyleChain) -> Dict { @@ -91,7 +98,8 @@ impl Show for HeadingNode { }; } - let mut map = StyleMap::new(); + let mut map = StyleMap::with_role(Role::Heading(self.level.get())); + map.set(TextNode::SIZE, resolve!(Self::SIZE)); if let Smart::Custom(family) = resolve!(Self::FAMILY) { diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs index 84603eb3..563426b4 100644 --- a/src/library/structure/list.rs +++ b/src/library/structure/list.rs @@ -2,10 +2,11 @@ use std::fmt::Write; use unscanny::Scanner; -use crate::library::layout::{BlockSpacing, GridNode, TrackSizing}; +use crate::library::layout::{BlockSpacing, GridNode, GridSemantics, TrackSizing}; use crate::library::prelude::*; use crate::library::text::ParNode; use crate::library::utility::Numbering; +use crate::model::StyleEntry; /// An unordered (bulleted) or ordered (numbered) list. #[derive(Debug, Hash)] @@ -76,9 +77,12 @@ 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.unguard(sel)), + body: Box::new(item.body.clone().styled_with_map(map.clone())), ..*item }), ..*self @@ -108,9 +112,12 @@ 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(map.clone()).pack()); + cells.push(label.resolve(ctx, L, number)?.styled_with_map(label_map).pack()); cells.push(LayoutNode::default()); cells.push((*item.body).clone().styled_with_map(map.clone()).pack()); number += 1; @@ -134,6 +141,7 @@ impl<const L: ListKind> Show for ListNode<L> { ]), gutter: Spec::with_y(vec![TrackSizing::Relative(gutter.into())]), cells, + semantic: GridSemantics::List, })) } @@ -155,7 +163,9 @@ impl<const L: ListKind> Show for ListNode<L> { } } - Ok(realized.spaced(above, below)) + Ok(realized + .styled_with_map(StyleMap::with_role(Role::List(L == ORDERED))) + .spaced(above, below)) } } diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs index cd70db30..60115612 100644 --- a/src/library/structure/table.rs +++ b/src/library/structure/table.rs @@ -1,5 +1,6 @@ -use crate::library::layout::{BlockSpacing, GridNode, TrackSizing}; +use crate::library::layout::{BlockSpacing, GridNode, GridSemantics, TrackSizing}; use crate::library::prelude::*; +use crate::model::StyleEntry; /// A table of items. #[derive(Debug, Hash)] @@ -49,10 +50,17 @@ 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.unguard(sel)).collect(), + cells: self + .cells + .iter() + .map(|cell| cell.clone().styled_with_map(map.clone())) + .collect(), } .pack() } @@ -100,7 +108,9 @@ impl Show for TableNode { tracks: self.tracks.clone(), gutter: self.gutter.clone(), cells, - })) + semantic: GridSemantics::Table, + }) + .styled_with_map(StyleMap::with_role(Role::Table))) } fn finalize( |
