diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-16 22:14:27 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-16 22:39:21 +0200 |
| commit | 30f16bbf6431ca0c174ca0a1abaa6a13ef50ab06 (patch) | |
| tree | f5a5c0adad15840ebe24b39e77ff467862067c91 /src/layout/mod.rs | |
| parent | 9f6137d8a829fe8f34554623495fa620252a0184 (diff) | |
Add Value type and replace dyn-nodes with call-exprs 🏗
- In addition to syntax trees there are now `Value`s, which syntax trees can be evaluated into (e.g. the tree is `5+5` and the value is `10`)
- Parsing is completely pure, function calls are not parsed into nodes, but into simple call expressions, which are resolved later
- Functions aren't dynamic nodes anymore, but simply functions which receive their arguments as a table and the layouting context
- Functions may return any `Value`
- Layouting is powered by functions which return the new `Commands` value, which informs the layouting engine what to do
- When a function returns a non-`Commands` value, the layouter simply dumps the value into the document in monospace
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 5f5a4859..837c19ec 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -10,9 +10,7 @@ mod tree; /// Basic types used across the layouting engine. pub mod prelude { pub use super::primitive::*; - pub use super::{ - BoxLayout, layout, Layout, LayoutContext, LayoutSpace, MultiLayout, - }; + pub use super::{BoxLayout, layout, LayoutContext, LayoutSpace, MultiLayout}; pub use Dir::*; pub use GenAlign::*; pub use GenAxis::*; @@ -23,13 +21,11 @@ pub mod prelude { pub use primitive::*; pub use tree::layout_tree as layout; -use async_trait::async_trait; - +use crate::compute::scope::Scope; use crate::font::SharedFontLoader; use crate::geom::{Margins, Size}; use crate::style::{LayoutStyle, PageStyle, TextStyle}; use crate::syntax::tree::SyntaxTree; -use crate::Pass; use elements::LayoutElements; use prelude::*; @@ -48,18 +44,13 @@ pub struct BoxLayout { pub elements: LayoutElements, } -/// Command-based layouting. -#[async_trait(?Send)] -pub trait Layout { - /// Create a sequence of layouting commands to execute. - async fn layout<'a>(&'a self, ctx: LayoutContext<'_>) -> Pass<Commands<'a>>; -} - /// The context for layouting. -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct LayoutContext<'a> { /// The font loader to query fonts from when typesetting text. pub loader: &'a SharedFontLoader, + /// The function scope. + pub scope: &'a Scope, /// The style for pages and text. pub style: &'a LayoutStyle, /// The unpadded size of this container (the base 100% for relative sizes). @@ -118,11 +109,11 @@ impl LayoutSpace { } /// A sequence of layouting commands. -pub type Commands<'a> = Vec<Command<'a>>; +pub type Commands = Vec<Command>; /// Commands executable by the layouting engine. -#[derive(Debug, Clone)] -pub enum Command<'a> { +#[derive(Debug, Clone, PartialEq)] +pub enum Command { /// Layout the given tree in the current context (i.e. not nested). The /// content of the tree is not laid out into a separate box and then added, /// but simply laid out flatly in the active layouting process. @@ -130,7 +121,7 @@ pub enum Command<'a> { /// This has the effect that the content fits nicely into the active line /// layouting, enabling functions to e.g. change the style of some piece of /// text while keeping it part of the current paragraph. - LayoutSyntaxTree(&'a SyntaxTree), + LayoutSyntaxTree(SyntaxTree), /// Add a finished layout. Add(BoxLayout), |
