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 /src/model/content.rs | |
| parent | 9b8c1dc19fcda399f00e486460b4cc521d1a460b (diff) | |
Show everything!
Diffstat (limited to 'src/model/content.rs')
| -rw-r--r-- | src/model/content.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/model/content.rs b/src/model/content.rs index 3cae99b2..15ea33cb 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -20,7 +20,7 @@ use crate::World; /// - anything written between square brackets in Typst /// - any constructor function #[derive(Clone, Hash)] -pub struct Content(Arc<dyn Bounds>); +pub struct Content(Arc<dyn Bounds>, Vec<RecipeId>); impl Content { /// Create empty content. @@ -112,16 +112,16 @@ impl Content { } /// Style this content with a style entry. - pub fn styled_with_entry(mut self, entry: Style) -> Self { + pub fn styled_with_entry(mut self, style: Style) -> Self { if let Some(styled) = self.try_downcast_mut::<StyledNode>() { - styled.map.apply(entry); + styled.map.apply(style); self } else if let Some(styled) = self.downcast::<StyledNode>() { let mut map = styled.map.clone(); - map.apply(entry); + map.apply(style); StyledNode { sub: styled.sub.clone(), map }.pack() } else { - StyledNode { sub: self, map: entry.into() }.pack() + StyledNode { sub: self, map: style.into() }.pack() } } @@ -139,9 +139,20 @@ impl Content { StyledNode { sub: self, map: styles }.pack() } - /// Reenable a specific show rule recipe. - pub fn unguard(&self, id: RecipeId) -> Self { - self.clone().styled_with_entry(Style::Unguard(id)) + /// Disable a show rule recipe. + pub fn guard(mut self, id: RecipeId) -> Self { + self.1.push(id); + self + } + + /// Whether no show rule was executed for this node so far. + pub fn pristine(&self) -> bool { + self.1.is_empty() + } + + /// Check whether a show rule recipe is disabled. + pub fn guarded(&self, id: RecipeId) -> bool { + self.1.contains(&id) } } @@ -241,7 +252,7 @@ pub trait Node: 'static { where Self: Debug + Hash + Sync + Send + Sized + 'static, { - Content(Arc::new(self)) + Content(Arc::new(self), vec![]) } /// Construct a node from the arguments. |
