diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-04 18:18:55 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-04 18:18:55 +0200 |
| commit | 6672f8f7dfcb38bbda3ec92bdf95341c05e9a782 (patch) | |
| tree | 90ec0d7a36554f9096e5f077ac7828fb6813fca0 /src/layout/mod.rs | |
| parent | 262a8fa36a09527b4e257c175b12c8437279cf66 (diff) | |
Remove Typesetter in favor of typeset function 🎯
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index c9abb165..8156f596 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1,13 +1,17 @@ //! Layouting of syntax trees into box layouts. -pub mod elements; -pub mod line; pub mod primitive; -pub mod stack; + +mod elements; +mod line; +mod stack; mod tree; +pub use elements::*; +pub use line::*; pub use primitive::*; -pub use tree::layout_tree as layout; +pub use stack::*; +pub use tree::*; use crate::geom::{Insets, Point, Rect, RectExt, Sides, Size, SizeExt}; @@ -15,8 +19,33 @@ use crate::eval::Scope; use crate::font::SharedFontLoader; use crate::style::{LayoutStyle, PageStyle, TextStyle}; use crate::syntax::SynTree; - -use elements::LayoutElements; +use crate::Pass; + +/// Layout a syntax tree and return the produced layout. +pub async fn layout( + tree: &SynTree, + style: &LayoutStyle, + scope: &Scope, + loader: SharedFontLoader, +) -> Pass<MultiLayout> { + let space = LayoutSpace { + size: style.page.size, + insets: style.page.insets(), + expansion: LayoutExpansion::new(true, true), + }; + tree::layout_tree(&tree, LayoutContext { + loader, + scope, + style, + base: space.usable(), + spaces: vec![space], + repeat: true, + sys: LayoutSystem::new(Dir::LTR, Dir::TTB), + align: LayoutAlign::new(GenAlign::Start, GenAlign::Start), + root: true, + }) + .await +} /// A collection of layouts. pub type MultiLayout = Vec<BoxLayout>; @@ -36,7 +65,7 @@ pub struct BoxLayout { #[derive(Debug, Clone)] pub struct LayoutContext<'a> { /// The font loader to query fonts from when typesetting text. - pub loader: &'a SharedFontLoader, + pub loader: SharedFontLoader, /// The function scope. pub scope: &'a Scope, /// The style for pages and text. |
