summaryrefslogtreecommitdiff
path: root/src/model/layout.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-10-17 19:26:24 +0200
committerLaurenz <laurmaedje@gmail.com>2022-10-17 20:04:22 +0200
commite21822665591dc19766275da1e185215a6b945ef (patch)
tree7788e211c3c33c8b5a8ad7d5eb7574e33631eb16 /src/model/layout.rs
parent4fd031a256b2ecfe524859d5599fafb386395572 (diff)
Merge some modules
Diffstat (limited to 'src/model/layout.rs')
-rw-r--r--src/model/layout.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/model/layout.rs b/src/model/layout.rs
index 8064afff..09888ba5 100644
--- a/src/model/layout.rs
+++ b/src/model/layout.rs
@@ -8,8 +8,8 @@ use std::sync::Arc;
use comemo::{Prehashed, Tracked};
use super::{Barrier, NodeId, Resolve, StyleChain, StyleEntry};
+use super::{Builder, Content, RawAlign, RawLength, Scratch};
use crate::diag::SourceResult;
-use crate::eval::{RawAlign, RawLength};
use crate::frame::{Element, Frame};
use crate::geom::{
Align, Geometry, Length, Paint, Point, Relative, Sides, Size, Spec, Stroke,
@@ -18,6 +18,21 @@ use crate::library::graphics::MoveNode;
use crate::library::layout::{AlignNode, PadNode};
use crate::World;
+/// Layout content into a collection of pages.
+///
+/// Relayouts until all pinned locations are converged.
+#[comemo::memoize]
+pub fn layout(world: Tracked<dyn World>, content: &Content) -> SourceResult<Vec<Frame>> {
+ let styles = StyleChain::with_root(&world.config().styles);
+ let scratch = Scratch::default();
+
+ let mut builder = Builder::new(world, &scratch, true);
+ builder.accept(content, styles)?;
+
+ let (doc, shared) = builder.into_doc(styles)?;
+ doc.layout(world, shared)
+}
+
/// A node that can be layouted into a sequence of regions.
///
/// Layouting returns one frame per used region.