summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/document.rs8
-rw-r--r--src/layout/fixed.rs5
-rw-r--r--src/layout/mod.rs19
-rw-r--r--src/layout/node.rs9
-rw-r--r--src/layout/pad.rs5
-rw-r--r--src/layout/par.rs5
-rw-r--r--src/layout/spacing.rs3
-rw-r--r--src/layout/stack.rs5
-rw-r--r--src/layout/text.rs3
9 files changed, 21 insertions, 41 deletions
diff --git a/src/layout/document.rs b/src/layout/document.rs
index a91dbbe9..b233ffd8 100644
--- a/src/layout/document.rs
+++ b/src/layout/document.rs
@@ -9,10 +9,10 @@ pub struct Document {
impl Document {
/// Layout the document.
- pub async fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
+ pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
let mut layouts = vec![];
for run in &self.runs {
- layouts.extend(run.layout(ctx).await);
+ layouts.extend(run.layout(ctx));
}
layouts
}
@@ -31,9 +31,9 @@ pub struct Pages {
impl Pages {
/// Layout the page run.
- pub async fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
+ pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
let areas = Areas::repeat(self.size);
- let layouted = self.child.layout(ctx, &areas).await;
+ let layouted = self.child.layout(ctx, &areas);
layouted.into_iter().filter_map(Layouted::into_boxed).collect()
}
}
diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs
index 78a512e6..df099731 100644
--- a/src/layout/fixed.rs
+++ b/src/layout/fixed.rs
@@ -12,9 +12,8 @@ pub struct Fixed {
pub child: LayoutNode,
}
-#[async_trait(?Send)]
impl Layout for Fixed {
- async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
+ fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
let Area { rem, full } = areas.current;
let size = Size::new(
self.width.map(|w| w.eval(full.width)).unwrap_or(rem.width),
@@ -22,7 +21,7 @@ impl Layout for Fixed {
);
let areas = Areas::once(size);
- self.child.layout(ctx, &areas).await
+ self.child.layout(ctx, &areas)
}
}
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index a6ef4300..643f1a43 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -9,8 +9,6 @@ mod spacing;
mod stack;
mod text;
-use async_trait::async_trait;
-
use crate::font::SharedFontLoader;
use crate::geom::*;
use crate::shaping::Shaped;
@@ -25,9 +23,9 @@ pub use stack::*;
pub use text::*;
/// Layout a document and return the produced layouts.
-pub async fn layout(document: &Document, loader: SharedFontLoader) -> Vec<BoxLayout> {
+pub fn layout(document: &Document, loader: SharedFontLoader) -> Vec<BoxLayout> {
let mut ctx = LayoutContext { loader };
- document.layout(&mut ctx).await
+ document.layout(&mut ctx)
}
/// The context for layouting.
@@ -38,20 +36,9 @@ pub struct LayoutContext {
}
/// Layout a node.
-#[async_trait(?Send)]
pub trait Layout {
/// Layout the node in the given layout context.
- ///
- /// This signature looks pretty horrible due to async in trait methods, but
- /// it's actually just the following:
- /// ```rust,ignore
- /// async fn layout(
- /// &self,
- /// ctx: &mut LayoutContext,
- /// constraints: LayoutConstraints,
- /// ) -> Vec<LayoutItem>;
- /// ```
- async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted>;
+ fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted>;
}
/// A sequence of areas to layout into.
diff --git a/src/layout/node.rs b/src/layout/node.rs
index 31213b9d..4cba3d4f 100644
--- a/src/layout/node.rs
+++ b/src/layout/node.rs
@@ -24,13 +24,12 @@ impl LayoutNode {
}
}
-#[async_trait(?Send)]
impl Layout for LayoutNode {
- async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
+ fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
match self {
- Self::Spacing(spacing) => spacing.layout(ctx, areas).await,
- Self::Text(text) => text.layout(ctx, areas).await,
- Self::Dyn(boxed) => boxed.layout(ctx, areas).await,
+ Self::Spacing(spacing) => spacing.layout(ctx, areas),
+ Self::Text(text) => text.layout(ctx, areas),
+ Self::Dyn(boxed) => boxed.layout(ctx, areas),
}
}
}
diff --git a/src/layout/pad.rs b/src/layout/pad.rs
index 2574fa16..2994dd59 100644
--- a/src/layout/pad.rs
+++ b/src/layout/pad.rs
@@ -10,9 +10,8 @@ pub struct Pad {
pub child: LayoutNode,
}
-#[async_trait(?Send)]
impl Layout for Pad {
- async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
+ fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
let shrink = |size| size - self.padding.eval(size).size();
let areas = Areas {
current: Area {
@@ -23,7 +22,7 @@ impl Layout for Pad {
last: areas.last.map(shrink),
};
- let mut layouted = self.child.layout(ctx, &areas).await;
+ let mut layouted = self.child.layout(ctx, &areas);
for item in &mut layouted {
if let Layouted::Boxed(boxed, _) = item {
diff --git a/src/layout/par.rs b/src/layout/par.rs
index 729c077f..e77bb4e7 100644
--- a/src/layout/par.rs
+++ b/src/layout/par.rs
@@ -18,12 +18,11 @@ pub struct Par {
pub children: Vec<LayoutNode>,
}
-#[async_trait(?Send)]
impl Layout for Par {
- async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
+ fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
let mut layouter = ParLayouter::new(self, areas.clone());
for child in &self.children {
- for layouted in child.layout(ctx, &layouter.areas).await {
+ for layouted in child.layout(ctx, &layouter.areas) {
match layouted {
Layouted::Spacing(spacing) => layouter.spacing(spacing),
Layouted::Boxed(boxed, aligns) => layouter.boxed(boxed, aligns.cross),
diff --git a/src/layout/spacing.rs b/src/layout/spacing.rs
index 427cb7b0..f64c7968 100644
--- a/src/layout/spacing.rs
+++ b/src/layout/spacing.rs
@@ -14,9 +14,8 @@ pub struct Spacing {
pub softness: Softness,
}
-#[async_trait(?Send)]
impl Layout for Spacing {
- async fn layout(&self, _: &mut LayoutContext, _: &Areas) -> Vec<Layouted> {
+ fn layout(&self, _: &mut LayoutContext, _: &Areas) -> Vec<Layouted> {
vec![Layouted::Spacing(self.amount)]
}
}
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 2f3ceed8..9aeb80aa 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -16,12 +16,11 @@ pub struct Stack {
pub children: Vec<LayoutNode>,
}
-#[async_trait(?Send)]
impl Layout for Stack {
- async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
+ fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> {
let mut layouter = StackLayouter::new(self, areas.clone());
for child in &self.children {
- for layouted in child.layout(ctx, &layouter.areas).await {
+ for layouted in child.layout(ctx, &layouter.areas) {
match layouted {
Layouted::Spacing(spacing) => layouter.spacing(spacing),
Layouted::Boxed(boxed, aligns) => layouter.boxed(boxed, aligns),
diff --git a/src/layout/text.rs b/src/layout/text.rs
index a4156fd3..5e047069 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -23,9 +23,8 @@ pub struct Text {
pub aligns: Gen<Align>,
}
-#[async_trait(?Send)]
impl Layout for Text {
- async fn layout(&self, ctx: &mut LayoutContext, _: &Areas) -> Vec<Layouted> {
+ fn layout(&self, ctx: &mut LayoutContext, _: &Areas) -> Vec<Layouted> {
let mut loader = ctx.loader.borrow_mut();
vec![Layouted::Boxed(
shaping::shape(