diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-02-04 19:22:23 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-02-04 19:22:23 +0100 |
| commit | e63ce52ae0d929506a1fa238477f039d14d53813 (patch) | |
| tree | 74dd8ce425dc368021c6495273acbdf2e736be68 /src/layout/model.rs | |
| parent | 5c11aa72239ecbdd9577f027bdc7e9468d68414e (diff) | |
Merge `Parsed` and `Layouted` types into `Pass` with `Feedback` 🌝🎢🌚
Diffstat (limited to 'src/layout/model.rs')
| -rw-r--r-- | src/layout/model.rs | 32 |
1 files changed, 10 insertions, 22 deletions
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; |
