summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-02-04 19:22:23 +0100
committerLaurenz <laurmaedje@gmail.com>2020-02-04 19:22:23 +0100
commite63ce52ae0d929506a1fa238477f039d14d53813 (patch)
tree74dd8ce425dc368021c6495273acbdf2e736be68 /src/layout
parent5c11aa72239ecbdd9577f027bdc7e9468d68414e (diff)
Merge `Parsed` and `Layouted` types into `Pass` with `Feedback` 🌝🎢🌚
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/mod.rs3
-rw-r--r--src/layout/model.rs32
2 files changed, 11 insertions, 24 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 8c120c6b..b29d87e3 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -18,8 +18,7 @@ pub_use_mod!(model);
/// Basic types used across the layouting engine.
pub mod prelude {
pub use super::{
- LayoutContext, layout, LayoutSpace,
- Layouted, Commands,
+ LayoutContext, layout, LayoutSpace, Commands,
LayoutAxes, LayoutAlignment, LayoutExpansion
};
pub use super::GenericAxis::{self, *};
diff --git a/src/layout/model.rs b/src/layout/model.rs
index d23968d8..343205ec 100644
--- a/src/layout/model.rs
+++ b/src/layout/model.rs
@@ -6,12 +6,12 @@ use std::future::Future;
use std::pin::Pin;
use smallvec::smallvec;
+use crate::{Pass, Feedback};
use crate::GlobalFontLoader;
-use crate::error::Errors;
use crate::style::{LayoutStyle, PageStyle, TextStyle};
use crate::size::{Size, Size2D};
use crate::syntax::{Model, SyntaxModel, Node};
-use crate::syntax::span::{Spanned, Span, offset_spans};
+use crate::syntax::span::{Span, Spanned};
use super::line::{LineLayouter, LineContext};
use super::text::{layout_text, TextContext};
use super::*;
@@ -23,7 +23,7 @@ pub struct ModelLayouter<'a> {
ctx: LayoutContext<'a>,
layouter: LineLayouter,
style: LayoutStyle,
- errors: Errors,
+ feedback: Feedback,
}
/// The context for layouting.
@@ -51,15 +51,6 @@ pub struct LayoutContext<'a> {
pub debug: bool,
}
-/// The result of layouting: Some layouted things and a list of errors.
-#[derive(Debug, Clone, Eq, PartialEq)]
-pub struct Layouted<T> {
- /// The result of the layouting process.
- pub output: T,
- /// Errors that arose in the process of layouting.
- pub errors: Errors,
-}
-
/// A sequence of layouting commands.
pub type Commands<'a> = Vec<Command<'a>>;
@@ -107,7 +98,7 @@ pub enum Command<'a> {
}
/// Layout a syntax model into a list of boxes.
-pub async fn layout(model: &SyntaxModel, ctx: LayoutContext<'_>) -> Layouted<MultiLayout> {
+pub async fn layout(model: &SyntaxModel, ctx: LayoutContext<'_>) -> Pass<MultiLayout> {
let mut layouter = ModelLayouter::new(ctx);
layouter.layout_syntax_model(model).await;
layouter.finish()
@@ -132,7 +123,7 @@ impl<'a> ModelLayouter<'a> {
}),
style: ctx.style.clone(),
ctx,
- errors: vec![],
+ feedback: Feedback::new(),
}
}
@@ -151,7 +142,7 @@ impl<'a> ModelLayouter<'a> {
}).await;
// Add the errors generated by the model to the error list.
- self.errors.extend(offset_spans(layouted.errors, model.span.start));
+ self.feedback.extend_offset(model.span.start, layouted.feedback);
for command in layouted.output {
self.execute_command(command, model.span).await;
@@ -195,11 +186,8 @@ impl<'a> ModelLayouter<'a> {
}) }
/// Compute the finished list of boxes.
- pub fn finish(self) -> Layouted<MultiLayout> {
- Layouted {
- output: self.layouter.finish(),
- errors: self.errors,
- }
+ pub fn finish(self) -> Pass<MultiLayout> {
+ Pass::new(self.layouter.finish(), self.feedback)
}
/// Execute a command issued by a model. When the command is errorful, the
@@ -225,7 +213,7 @@ impl<'a> ModelLayouter<'a> {
BreakParagraph => self.layout_paragraph(),
BreakPage => {
if self.ctx.nested {
- self.errors.push(err!(span;
+ self.feedback.errors.push(err!(span;
"page break cannot be issued from nested context"));
} else {
self.layouter.finish_space(true)
@@ -238,7 +226,7 @@ impl<'a> ModelLayouter<'a> {
}
SetPageStyle(style) => {
if self.ctx.nested {
- self.errors.push(err!(span;
+ self.feedback.errors.push(err!(span;
"page style cannot be changed from nested context"));
} else {
self.style.page = style;