summaryrefslogtreecommitdiff
path: root/src/library/align.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-06-26 13:06:37 +0200
committerLaurenz <laurmaedje@gmail.com>2021-06-26 13:06:37 +0200
commit285c2f617b74e182be69decea46bbd0afdb0f604 (patch)
tree41bdb5d19bc80c165df6e55e829051f0812f7c3d /src/library/align.rs
parent63cf36149635156013f0324b660bf4d362beb87f (diff)
Cleanse library
- Remove doc-comments for Typst functions from library - Reduce number of library source files
Diffstat (limited to 'src/library/align.rs')
-rw-r--r--src/library/align.rs128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/library/align.rs b/src/library/align.rs
deleted file mode 100644
index c0ed0416..00000000
--- a/src/library/align.rs
+++ /dev/null
@@ -1,128 +0,0 @@
-use super::*;
-
-/// `align`: Configure the alignment along the layouting axes.
-///
-/// # Positional parameters
-/// - Alignments: variadic, of type `alignment`.
-/// - Body: optional, of type `template`.
-///
-/// # Named parameters
-/// - Horizontal alignment: `horizontal`, of type `alignment`.
-/// - Vertical alignment: `vertical`, of type `alignment`.
-///
-/// # Return value
-/// A template that changes the alignment along the layouting axes. The effect
-/// is scoped to the body if present.
-///
-/// # Relevant types and constants
-/// - Type `alignment`
-/// - `start`
-/// - `center`
-/// - `end`
-/// - `left`
-/// - `right`
-/// - `top`
-/// - `bottom`
-pub fn align(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
- let first = args.eat::<AlignValue>(ctx);
- let second = args.eat::<AlignValue>(ctx);
- let mut horizontal = args.named::<AlignValue>(ctx, "horizontal");
- let mut vertical = args.named::<AlignValue>(ctx, "vertical");
- let body = args.eat::<TemplateValue>(ctx);
-
- 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);
- }
- _ => {}
- }
- }
-
- Value::template("align", move |ctx| {
- let snapshot = ctx.state.clone();
-
- if let Some(horizontal) = horizontal {
- ctx.state.aligns.cross = horizontal.to_align(ctx.state.lang.dir);
- }
-
- if let Some(vertical) = vertical {
- ctx.state.aligns.main = vertical.to_align(Dir::TTB);
- if ctx.state.aligns.main != snapshot.aligns.main {
- ctx.parbreak();
- }
- }
-
- if let Some(body) = &body {
- body.exec(ctx);
- ctx.state = snapshot;
- }
- })
-}
-
-/// An alignment specifier passed to `align`.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
-pub(super) enum AlignValue {
- Start,
- Center,
- End,
- Left,
- Right,
- Top,
- Bottom,
-}
-
-impl AlignValue {
- fn axis(self) -> Option<SpecAxis> {
- match self {
- Self::Start => None,
- Self::Center => None,
- Self::End => None,
- Self::Left => Some(SpecAxis::Horizontal),
- Self::Right => Some(SpecAxis::Horizontal),
- Self::Top => Some(SpecAxis::Vertical),
- Self::Bottom => Some(SpecAxis::Vertical),
- }
- }
-
- fn to_align(self, dir: Dir) -> Align {
- let side = |is_at_positive_start| {
- if dir.is_positive() == is_at_positive_start {
- Align::Start
- } else {
- Align::End
- }
- };
-
- match self {
- Self::Start => Align::Start,
- Self::Center => Align::Center,
- Self::End => Align::End,
- Self::Left => side(true),
- Self::Right => side(false),
- Self::Top => side(true),
- Self::Bottom => side(false),
- }
- }
-}
-
-impl Display for AlignValue {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- f.pad(match self {
- Self::Start => "start",
- Self::Center => "center",
- Self::End => "end",
- Self::Left => "left",
- Self::Right => "right",
- Self::Top => "top",
- Self::Bottom => "bottom",
- })
- }
-}
-
-castable! {
- AlignValue: "alignment",
-}