diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-18 15:33:06 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-19 22:40:42 +0100 |
| commit | 1937d746abf19a5c1142db546912dbed0e6711fb (patch) | |
| tree | 287a7462720698347361be5d34d61cf7bf3dce45 /library | |
| parent | 9b8c1dc19fcda399f00e486460b4cc521d1a460b (diff) | |
Show everything!
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/layout/mod.rs | 34 | ||||
| -rw-r--r-- | library/src/math/mod.rs | 11 | ||||
| -rw-r--r-- | library/src/prelude.rs | 4 | ||||
| -rw-r--r-- | library/src/structure/heading.rs | 4 | ||||
| -rw-r--r-- | library/src/structure/list.rs | 29 | ||||
| -rw-r--r-- | library/src/structure/reference.rs | 4 | ||||
| -rw-r--r-- | library/src/structure/table.rs | 19 | ||||
| -rw-r--r-- | library/src/text/deco.rs | 4 | ||||
| -rw-r--r-- | library/src/text/link.rs | 8 | ||||
| -rw-r--r-- | library/src/text/mod.rs | 8 | ||||
| -rw-r--r-- | library/src/text/raw.rs | 4 | ||||
| -rw-r--r-- | library/src/text/shift.rs | 4 |
12 files changed, 24 insertions, 109 deletions
diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index bcc5bf6d..daa7b8a1 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -32,7 +32,7 @@ use typst::diag::SourceResult; use typst::frame::Frame; use typst::geom::*; use typst::model::{ - capability, Content, Node, SequenceNode, Show, Style, StyleChain, StyleVecBuilder, + capability, Content, Node, SequenceNode, Style, StyleChain, StyleVecBuilder, StyledNode, }; use typst::World; @@ -87,7 +87,7 @@ impl LayoutBlock for Content { regions: &Regions, styles: StyleChain, ) -> SourceResult<Vec<Frame>> { - if !self.has::<dyn Show>() || !styles.applicable(self) { + if !styles.applicable(self) { if let Some(node) = self.to::<dyn LayoutBlock>() { let barrier = Style::Barrier(self.id()); let styles = barrier.chain(&styles); @@ -126,7 +126,7 @@ impl LayoutInline for Content { assert!(regions.backlog.is_empty()); assert!(regions.last.is_none()); - if !self.has::<dyn Show>() || !styles.applicable(self) { + if !styles.applicable(self) { if let Some(node) = self.to::<dyn LayoutInline>() { let barrier = Style::Barrier(self.id()); let styles = barrier.chain(&styles); @@ -312,16 +312,17 @@ impl<'a> Builder<'a> { content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<()> { - if content.is::<TextNode>() { - if let Some(realized) = styles.apply(self.world, content)? { - let stored = self.scratch.content.alloc(realized); - return self.accept(stored, styles); - } - } else if let Some(styled) = content.downcast::<StyledNode>() { + if let Some(styled) = content.downcast::<StyledNode>() { return self.styled(styled, styles); - } else if let Some(seq) = content.downcast::<SequenceNode>() { + } + + if let Some(seq) = content.downcast::<SequenceNode>() { return self.sequence(seq, styles); - } else if content.has::<dyn Show>() && self.show(content, styles)? { + } + + if let Some(realized) = styles.show(self.world, content)? { + let stored = self.scratch.content.alloc(realized); + self.accept(stored, styles)?; return Ok(()); } @@ -361,17 +362,6 @@ impl<'a> Builder<'a> { Ok(()) } - fn show(&mut self, content: &Content, styles: StyleChain<'a>) -> SourceResult<bool> { - let Some(realized) = styles.apply(self.world, content)? else { - return Ok(false); - }; - - let stored = self.scratch.content.alloc(realized); - self.accept(stored, styles)?; - - Ok(true) - } - fn styled( &mut self, styled: &'a StyledNode, diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index 7772c0af..fb53b52d 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -28,15 +28,16 @@ impl MathNode { } impl Show for MathNode { - fn unguard_parts(&self, _: RecipeId) -> Content { - self.clone().pack() - } - fn show(&self, _: Tracked<dyn World>, styles: StyleChain) -> SourceResult<Content> { let mut map = StyleMap::new(); map.set_family(FontFamily::new("NewComputerModernMath"), styles); - let mut realized = self.clone().pack().styled_with_map(map); + let mut realized = self + .clone() + .pack() + .guard(RecipeId::Base(NodeId::of::<Self>())) + .styled_with_map(map); + if self.display { realized = realized.aligned(Axes::with_x(Some(Align::Center.into()))) } diff --git a/library/src/prelude.rs b/library/src/prelude.rs index b7095aee..c6bbe676 100644 --- a/library/src/prelude.rs +++ b/library/src/prelude.rs @@ -16,8 +16,8 @@ pub use typst::geom::*; #[doc(no_inline)] pub use typst::model::{ array, capability, castable, dict, dynamic, format_str, node, Args, Array, Cast, - Content, Dict, Finalize, Fold, Func, Node, RecipeId, Resolve, Show, Smart, Str, - StyleChain, StyleMap, StyleVec, Value, Vm, + Content, Dict, Finalize, Fold, Func, Node, NodeId, RecipeId, Resolve, Show, Smart, + Str, StyleChain, StyleMap, StyleVec, Value, Vm, }; #[doc(no_inline)] pub use typst::syntax::{Span, Spanned}; diff --git a/library/src/structure/heading.rs b/library/src/structure/heading.rs index e069e3a9..d99e2db8 100644 --- a/library/src/structure/heading.rs +++ b/library/src/structure/heading.rs @@ -34,10 +34,6 @@ impl HeadingNode { } impl Show for HeadingNode { - fn unguard_parts(&self, id: RecipeId) -> Content { - Self { body: self.body.unguard(id), ..*self }.pack() - } - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(BlockNode(self.body.clone()).pack()) } diff --git a/library/src/structure/list.rs b/library/src/structure/list.rs index 8de22f64..aa844232 100644 --- a/library/src/structure/list.rs +++ b/library/src/structure/list.rs @@ -6,7 +6,7 @@ use crate::prelude::*; use crate::text::{ParNode, SpaceNode, TextNode}; /// An unordered (bulleted) or ordered (numbered) list. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct ListNode<const L: ListKind = LIST> { /// If true, the items are separated by leading instead of list spacing. pub tight: bool, @@ -20,7 +20,7 @@ pub type EnumNode = ListNode<ENUM>; /// A description list. pub type DescNode = ListNode<DESC>; -#[node(Show, LayoutBlock)] +#[node(LayoutBlock)] impl<const L: ListKind> ListNode<L> { /// How the list is labelled. #[property(referenced)] @@ -77,20 +77,6 @@ impl<const L: ListKind> ListNode<L> { } } -impl<const L: ListKind> Show for ListNode<L> { - fn unguard_parts(&self, id: RecipeId) -> Content { - Self { - items: self.items.map(|item| item.unguard(id)), - ..*self - } - .pack() - } - - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { - Ok(self.clone().pack()) - } -} - impl<const L: ListKind> LayoutBlock for ListNode<L> { fn layout_block( &self, @@ -178,17 +164,6 @@ impl ListItem { } } - fn unguard(&self, sel: RecipeId) -> Self { - match self { - Self::List(body) => Self::List(Box::new(body.unguard(sel))), - Self::Enum(number, body) => Self::Enum(*number, Box::new(body.unguard(sel))), - Self::Desc(item) => Self::Desc(Box::new(DescItem { - term: item.term.unguard(sel), - body: item.body.unguard(sel), - })), - } - } - /// Encode the item into a value. fn encode(&self) -> Value { match self { diff --git a/library/src/structure/reference.rs b/library/src/structure/reference.rs index 7004f49e..4f672707 100644 --- a/library/src/structure/reference.rs +++ b/library/src/structure/reference.rs @@ -20,10 +20,6 @@ impl RefNode { } impl Show for RefNode { - fn unguard_parts(&self, _: RecipeId) -> Content { - Self(self.0.clone()).pack() - } - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(TextNode::packed(format_eco!("@{}", self.0))) } diff --git a/library/src/structure/table.rs b/library/src/structure/table.rs index 72ea3da5..eaadc3a1 100644 --- a/library/src/structure/table.rs +++ b/library/src/structure/table.rs @@ -2,7 +2,7 @@ use crate::layout::{GridNode, TrackSizing, TrackSizings}; use crate::prelude::*; /// A table of items. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct TableNode { /// Defines sizing for content rows and columns. pub tracks: Axes<Vec<TrackSizing>>, @@ -12,7 +12,7 @@ pub struct TableNode { pub cells: Vec<Content>, } -#[node(Show, LayoutBlock)] +#[node(LayoutBlock)] impl TableNode { /// How to fill the cells. #[property(referenced)] @@ -50,21 +50,6 @@ impl TableNode { } } -impl Show for TableNode { - fn unguard_parts(&self, id: RecipeId) -> Content { - Self { - tracks: self.tracks.clone(), - gutter: self.gutter.clone(), - cells: self.cells.iter().map(|cell| cell.unguard(id)).collect(), - } - .pack() - } - - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { - Ok(self.clone().pack()) - } -} - impl LayoutBlock for TableNode { fn layout_block( &self, diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs index bc7a312d..7db7fa1b 100644 --- a/library/src/text/deco.rs +++ b/library/src/text/deco.rs @@ -47,10 +47,6 @@ impl<const L: DecoLine> DecoNode<L> { } impl<const L: DecoLine> Show for DecoNode<L> { - fn unguard_parts(&self, id: RecipeId) -> Content { - Self(self.0.unguard(id)).pack() - } - fn show(&self, _: Tracked<dyn World>, styles: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled( TextNode::DECO, diff --git a/library/src/text/link.rs b/library/src/text/link.rs index acd37df6..45e7c7ec 100644 --- a/library/src/text/link.rs +++ b/library/src/text/link.rs @@ -50,14 +50,6 @@ impl LinkNode { } impl Show for LinkNode { - fn unguard_parts(&self, id: RecipeId) -> Content { - Self { - dest: self.dest.clone(), - body: self.body.unguard(id), - } - .pack() - } - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(self.body.clone()) } diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs index 6cf1e1c5..d36f8db5 100644 --- a/library/src/text/mod.rs +++ b/library/src/text/mod.rs @@ -528,10 +528,6 @@ impl StrongNode { } impl Show for StrongNode { - fn unguard_parts(&self, id: RecipeId) -> Content { - Self(self.0.unguard(id)).pack() - } - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::BOLD, Toggle)) } @@ -556,10 +552,6 @@ impl EmphNode { } impl Show for EmphNode { - fn unguard_parts(&self, id: RecipeId) -> Content { - Self(self.0.unguard(id)).pack() - } - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::ITALIC, Toggle)) } diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs index d7dae244..f13fd394 100644 --- a/library/src/text/raw.rs +++ b/library/src/text/raw.rs @@ -43,10 +43,6 @@ impl RawNode { } impl Show for RawNode { - fn unguard_parts(&self, _: RecipeId) -> Content { - Self { text: self.text.clone(), ..*self }.pack() - } - fn show(&self, _: Tracked<dyn World>, styles: StyleChain) -> SourceResult<Content> { let lang = styles.get(Self::LANG).as_ref().map(|s| s.to_lowercase()); let foreground = THEME diff --git a/library/src/text/shift.rs b/library/src/text/shift.rs index a91285bf..32f110c6 100644 --- a/library/src/text/shift.rs +++ b/library/src/text/shift.rs @@ -43,10 +43,6 @@ impl<const S: ShiftKind> ShiftNode<S> { } impl<const S: ShiftKind> Show for ShiftNode<S> { - fn unguard_parts(&self, _: RecipeId) -> Content { - Self(self.0.clone()).pack() - } - fn show( &self, world: Tracked<dyn World>, |
