summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-13 12:36:45 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-13 12:36:45 +0200
commite2d17aa9d9491b339e6200c97b52f7ade51fa1d8 (patch)
tree95dfa729cc6cbe44ecbf5135f87a3dd8bb70200a /src/library
parent463e4ebd8234da5e28700e9b22b6ef5f0dfef56f (diff)
Move functions to command-based architecture ✈
Diffstat (limited to 'src/library')
-rw-r--r--src/library/align.rs14
-rw-r--r--src/library/mod.rs2
-rw-r--r--src/library/styles.rs34
3 files changed, 24 insertions, 26 deletions
diff --git a/src/library/align.rs b/src/library/align.rs
index b1e41abb..099daf88 100644
--- a/src/library/align.rs
+++ b/src/library/align.rs
@@ -38,13 +38,15 @@ impl Function for AlignFunc {
Ok(AlignFunc { alignment, body })
}
- fn layout(&self, ctx: LayoutContext) -> LayoutResult<FuncCommands> {
+ fn layout(&self, mut ctx: LayoutContext) -> LayoutResult<FuncCommands> {
if let Some(body) = &self.body {
- // // Override the previous alignment and do the layouting.
- // ctx.space.alignment = self.alignment;
- // layout(body, ctx)
- // .map(|l| Some(Layout::Boxed(l)))
- Ok(FuncCommands::new())
+ ctx.space.alignment = self.alignment;
+ let layouts = layout_tree(body, ctx)?;
+
+ let mut commands = FuncCommands::new();
+ commands.add(Command::AddMany(layouts));
+
+ Ok(commands)
} else {
unimplemented!("context-modifying align func")
}
diff --git a/src/library/mod.rs b/src/library/mod.rs
index acbd11db..848ba847 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -9,7 +9,7 @@ mod styles;
pub mod prelude {
pub use crate::syntax::{SyntaxTree, FuncHeader, Expression};
pub use crate::parsing::{parse, ParseContext, ParseResult, ParseError};
- pub use crate::layout::{layout_tree, layout_text, MultiLayout, Layout, LayoutContext};
+ pub use crate::layout::{layout_tree, LayoutContext, MultiLayout, Layout};
pub use crate::layout::{LayoutResult, LayoutError};
pub use crate::func::{Function, Command, FuncCommands};
diff --git a/src/library/styles.rs b/src/library/styles.rs
index 28cc0e48..85ae4789 100644
--- a/src/library/styles.rs
+++ b/src/library/styles.rs
@@ -1,13 +1,15 @@
//! Basic style functions: bold, italic, monospace.
use super::prelude::*;
-// use toddle::query::FontClass;
-
+use toddle::query::FontClass;
macro_rules! style_func {
- ($(#[$outer:meta])* pub struct $struct:ident { $name:expr },
- $style:ident => $style_change:block) => {
+ (
+ $(#[$outer:meta])*
+ pub struct $struct:ident { $name:expr },
+ $style:ident => $class:ident
+ ) => {
$(#[$outer])*
#[derive(Debug, PartialEq)]
pub struct $struct { body: SyntaxTree }
@@ -27,20 +29,14 @@ macro_rules! style_func {
}
}
- fn layout(&self, ctx: LayoutContext) -> LayoutResult<FuncCommands> {
- // // Change the context.
- // let mut $style = ctx.style.clone();
- // $style_change
+ fn layout(&self, _: LayoutContext) -> LayoutResult<FuncCommands> {
+ let mut commands = FuncCommands::new();
- // // Create a box and put it into a flex layout.
- // let boxed = layout(&self.body, LayoutContext {
- // style: &$style,
- // .. ctx
- // })?;
- // let flex = FlexLayout::from_box(boxed);
+ commands.add(Command::ToggleStyleClass(FontClass::$class));
+ commands.add(Command::Layout(&self.body));
+ commands.add(Command::ToggleStyleClass(FontClass::$class));
- // Ok(Some(Layout::Flex(flex)))
- Ok(FuncCommands::new())
+ Ok(commands)
}
}
};
@@ -49,17 +45,17 @@ macro_rules! style_func {
style_func! {
/// Typesets text in bold.
pub struct BoldFunc { "bold" },
- style => { style.toggle_class(FontClass::Bold) }
+ style => Bold
}
style_func! {
/// Typesets text in italics.
pub struct ItalicFunc { "italic" },
- style => { style.toggle_class(FontClass::Italic) }
+ style => Italic
}
style_func! {
/// Typesets text in monospace.
pub struct MonospaceFunc { "mono" },
- style => { style.toggle_class(FontClass::Monospace) }
+ style => Monospace
}