From 991e879e1d2ed53125dbff4edba80804ff28f2a9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 17 Oct 2019 19:21:47 +0200 Subject: =?UTF-8?q?Extend=20stack=20layouts=20from=20vertical=20to=20horiz?= =?UTF-8?q?ontal=20flows=20=E2=9E=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/boxed.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/library') diff --git a/src/library/boxed.rs b/src/library/boxed.rs index 975888f4..71a184a6 100644 --- a/src/library/boxed.rs +++ b/src/library/boxed.rs @@ -1,21 +1,39 @@ use super::prelude::*; +use crate::layout::Flow; /// Wraps content into a box. #[derive(Debug, PartialEq)] pub struct BoxFunc { - body: SyntaxTree + body: SyntaxTree, + flow: Flow, } impl Function for BoxFunc { fn parse(header: &FuncHeader, body: Option<&str>, ctx: ParseContext) -> ParseResult where Self: Sized { - if has_arguments(header) { - return err("pagebreak: expected no arguments"); - } + let flow = if header.args.is_empty() { + Flow::Vertical + } else if header.args.len() == 1 { + if let Expression::Ident(ident) = &header.args[0] { + match ident.as_str() { + "vertical" => Flow::Vertical, + "horizontal" => Flow::Horizontal, + f => return err(format!("invalid flow specifier: '{}'", f)), + } + } else { + return err(format!( + "expected alignment specifier, found: '{}'", + header.args[0] + )); + } + } else { + return err("box: expected flow specifier or no arguments"); + }; if let Some(body) = body { Ok(BoxFunc { - body: parse(body, ctx)? + body: parse(body, ctx)?, + flow, }) } else { err("box: expected body") @@ -23,7 +41,11 @@ impl Function for BoxFunc { } fn layout(&self, ctx: LayoutContext) -> LayoutResult { - let layout = layout_tree(&self.body, ctx)?; + let layout = layout_tree(&self.body, LayoutContext { + flow: self.flow, + .. ctx + })?; + Ok(commands![Command::AddMany(layout)]) } } -- cgit v1.2.3