summaryrefslogtreecommitdiff
path: root/src/library/align.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-10-31 15:52:16 +0100
committerLaurenz <laurmaedje@gmail.com>2021-10-31 15:52:35 +0100
commit5b344b663a3d224134923eea0d67ebf44c069b07 (patch)
tree34a5fb464a38b9d4cb11294379b3ddf351dfce21 /src/library/align.rs
parentfeff013abb17f31bc5305fe77fe67cf615c19ff2 (diff)
Reorganize modules
Instead of separating functionality into layout and library, everything lives in the library now. This way, related things live side by side and there are no duplicate file names in the two directories.
Diffstat (limited to 'src/library/align.rs')
-rw-r--r--src/library/align.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/library/align.rs b/src/library/align.rs
new file mode 100644
index 00000000..c6f96a13
--- /dev/null
+++ b/src/library/align.rs
@@ -0,0 +1,51 @@
+use super::prelude::*;
+
+/// `align`: Configure the alignment along the layouting axes.
+pub fn align(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
+ let first = args.find::<Align>();
+ let second = args.find::<Align>();
+ let body = args.find::<Template>();
+
+ let mut horizontal = args.named("horizontal")?;
+ let mut vertical = args.named("vertical")?;
+
+ for value in first.into_iter().chain(second) {
+ match value.axis() {
+ Some(SpecAxis::Horizontal) | None if horizontal.is_none() => {
+ horizontal = Some(value);
+ }
+ Some(SpecAxis::Vertical) | None if vertical.is_none() => {
+ vertical = Some(value);
+ }
+ _ => {}
+ }
+ }
+
+ let realign = |template: &mut Template| {
+ template.modify(move |style| {
+ if let Some(horizontal) = horizontal {
+ style.aligns.inline = horizontal;
+ }
+
+ if let Some(vertical) = vertical {
+ style.aligns.block = vertical;
+ }
+ });
+
+ if vertical.is_some() {
+ template.parbreak();
+ }
+ };
+
+ Ok(if let Some(body) = body {
+ let mut template = Template::new();
+ template.save();
+ realign(&mut template);
+ template += body;
+ template.restore();
+ Value::Template(template)
+ } else {
+ realign(&mut ctx.template);
+ Value::None
+ })
+}