summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/line.rs1
-rw-r--r--src/layout/mod.rs43
-rw-r--r--src/layout/tree.rs6
3 files changed, 40 insertions, 10 deletions
diff --git a/src/layout/line.rs b/src/layout/line.rs
index 86531f30..c190c152 100644
--- a/src/layout/line.rs
+++ b/src/layout/line.rs
@@ -8,7 +8,6 @@
//! Internally, the line layouter uses a stack layouter to stack the finished
//! lines on top of each.
-use super::stack::{StackContext, StackLayouter};
use super::*;
/// Performs the line layouting.
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.
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index dfc1c464..df174544 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -1,6 +1,7 @@
//! Layouting of syntax trees.
-use super::line::{LineContext, LineLayouter};
+use std::rc::Rc;
+
use super::*;
use crate::shaping;
use crate::style::LayoutStyle;
@@ -9,7 +10,7 @@ use crate::syntax::{
};
use crate::{DynFuture, Feedback, Pass};
-/// Layout a syntax tree into a collection of boxes.
+/// Layout a syntax tree in a given context.
pub async fn layout_tree(tree: &SynTree, ctx: LayoutContext<'_>) -> Pass<MultiLayout> {
let mut layouter = TreeLayouter::new(ctx);
layouter.layout_tree(tree).await;
@@ -159,6 +160,7 @@ impl<'a> TreeLayouter<'a> {
style: &self.style,
spaces: self.layouter.remaining(),
root: false,
+ loader: Rc::clone(&self.ctx.loader),
..self.ctx
};