diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-09 18:16:59 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-09 18:20:02 +0100 |
| commit | 010cc2effc2fd0e1c4e52d5c914cb4d74506bc0a (patch) | |
| tree | e50060d271f076b00945e5569e7f8ffef2c28e9f /library/src/math/mod.rs | |
| parent | 12a59963b08b68cc39dcded4d3d3e6a6631c2732 (diff) | |
New block spacing model
Diffstat (limited to 'library/src/math/mod.rs')
| -rw-r--r-- | library/src/math/mod.rs | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index ae3c4a9a..bcf09c04 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -5,9 +5,8 @@ mod tex; use std::fmt::Write; use self::tex::{layout_tex, Texify}; -use crate::layout::BlockSpacing; use crate::prelude::*; -use crate::text::{FallbackList, FontFamily, TextNode}; +use crate::text::FontFamily; /// A piece of a mathematical formula. #[derive(Debug, Clone, Hash)] @@ -18,15 +17,8 @@ pub struct MathNode { pub display: bool, } -#[node(Show, Finalize, LayoutInline, Texify)] +#[node(Show, LayoutInline, Texify)] impl MathNode { - /// The spacing above display math. - #[property(resolve, shorthand(around))] - pub const ABOVE: Option<BlockSpacing> = Some(Ratio::one().into()); - /// The spacing below display math. - #[property(resolve, shorthand(around))] - pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into()); - fn field(&self, name: &str) -> Option<Value> { match name { "display" => Some(Value::Bool(self.display)), @@ -40,27 +32,13 @@ impl Show for MathNode { self.clone().pack() } - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { - Ok(self.clone().pack()) - } -} - -impl Finalize for MathNode { - fn finalize( - &self, - _: Tracked<dyn World>, - styles: StyleChain, - mut realized: Content, - ) -> SourceResult<Content> { - realized = realized.styled( - TextNode::FAMILY, - FallbackList(vec![FontFamily::new("NewComputerModernMath")]), - ); + 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); if self.display { - realized = realized - .aligned(Axes::with_x(Some(Align::Center.into()))) - .spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW)) + realized = realized.aligned(Axes::with_x(Some(Align::Center.into()))) } Ok(realized) |
