summaryrefslogtreecommitdiff
path: root/src/layout/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-05-26 22:03:55 +0200
committerLaurenz <laurmaedje@gmail.com>2019-05-26 22:03:55 +0200
commit0274e9381064fa5942aa15b24a0a092832433859 (patch)
tree6e3db1ab1bf0a4105b0becb9ca0db64c8bd8eddf /src/layout/mod.rs
parentc38e17d91f81632422171b8103ce90baacfdbe22 (diff)
Devise text layouter 📑
Diffstat (limited to 'src/layout/mod.rs')
-rw-r--r--src/layout/mod.rs34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index f2ca3029..1af3156d 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -2,20 +2,42 @@
use crate::doc::{Document, Page, TextAction};
use crate::font::{Font, FontLoader, FontFamily, FontError};
-use crate::syntax::SyntaxTree;
+use crate::syntax::{SyntaxTree, Node};
mod size;
+mod text;
pub use size::Size;
+pub use text::TextLayouter;
/// Layout a syntax tree in a given context.
-#[allow(unused_variables)]
pub fn layout(tree: &SyntaxTree, ctx: &LayoutContext) -> LayoutResult<Layout> {
- Ok(Layout {
- extent: LayoutDimensions { width: Size::zero(), height: Size::zero() },
- actions: vec![],
- })
+ let mut layouter = TextLayouter::new(ctx);
+
+ let mut italic = false;
+ let mut bold = false;
+
+ for node in &tree.nodes {
+ match node {
+ Node::Text(text) => layouter.add_text(text)?,
+ Node::Space => layouter.add_space()?,
+ Node::Newline => layouter.add_paragraph()?,
+
+ Node::ToggleItalics => {
+ italic = !italic;
+ layouter.set_italic(italic);
+ },
+ Node::ToggleBold => {
+ bold = !bold;
+ layouter.set_bold(bold);
+ }
+
+ Node::Func(_) => unimplemented!(),
+ }
+ }
+
+ layouter.finish()
}
/// A collection of layouted content.