summaryrefslogtreecommitdiff
path: root/src/library/boxed.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-17 19:21:47 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-17 19:21:47 +0200
commit991e879e1d2ed53125dbff4edba80804ff28f2a9 (patch)
tree0917f83108feca10ca4207dd9089fe57cf8098d5 /src/library/boxed.rs
parent1987e5861cf2c033e3a540a5ef7c0f7106016929 (diff)
Extend stack layouts from vertical to horizontal flows ➡
Diffstat (limited to 'src/library/boxed.rs')
-rw-r--r--src/library/boxed.rs34
1 files changed, 28 insertions, 6 deletions
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<Self>
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<CommandList> {
- let layout = layout_tree(&self.body, ctx)?;
+ let layout = layout_tree(&self.body, LayoutContext {
+ flow: self.flow,
+ .. ctx
+ })?;
+
Ok(commands![Command::AddMany(layout)])
}
}