From c298cf61f2360eac0ec6a260fad11425b405f49f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 12 Jan 2024 11:01:49 +0100 Subject: [PATCH] Rename `Align` to `Alignment` --- crates/typst/src/eval/ops.rs | 8 +- crates/typst/src/foundations/content.rs | 4 +- crates/typst/src/foundations/fields.rs | 6 +- crates/typst/src/foundations/str.rs | 8 +- crates/typst/src/layout/align.rs | 108 ++++++++++++------------ crates/typst/src/layout/flow.rs | 4 +- crates/typst/src/layout/grid/layout.rs | 6 +- crates/typst/src/layout/grid/mod.rs | 11 +-- crates/typst/src/layout/mod.rs | 2 +- crates/typst/src/layout/page.rs | 30 +++---- crates/typst/src/layout/place.rs | 15 ++-- crates/typst/src/layout/sides.rs | 14 +-- crates/typst/src/layout/transform.rs | 12 +-- crates/typst/src/lib.rs | 18 ++-- crates/typst/src/math/equation.rs | 4 +- crates/typst/src/model/enum.rs | 8 +- crates/typst/src/model/figure.rs | 20 +++-- crates/typst/src/model/list.rs | 6 +- crates/typst/src/model/quote.rs | 4 +- crates/typst/src/model/table.rs | 8 +- crates/typst/src/text/raw.rs | 6 +- 21 files changed, 155 insertions(+), 147 deletions(-) diff --git a/crates/typst/src/eval/ops.rs b/crates/typst/src/eval/ops.rs index 76456afe4..9c20ea0a9 100644 --- a/crates/typst/src/eval/ops.rs +++ b/crates/typst/src/eval/ops.rs @@ -7,7 +7,7 @@ use ecow::eco_format; use crate::diag::{bail, At, SourceResult, StrResult}; use crate::eval::{access_dict, Access, Eval, Vm}; use crate::foundations::{format_str, Datetime, IntoValue, Regex, Repr, Value}; -use crate::layout::{Align, Length, Rel}; +use crate::layout::{Alignment, Length, Rel}; use crate::syntax::ast::{self, AstNode}; use crate::text::TextElem; use crate::util::Numeric; @@ -148,7 +148,7 @@ pub fn pos(value: Value) -> StrResult { mismatch!("cannot apply unary '+' to {}", value) } Dyn(d) => { - if d.is::() { + if d.is::() { mismatch!("cannot apply unary '+' to {}", d) } else { mismatch!("cannot apply '+' to {}", d) @@ -238,7 +238,9 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult { (Dyn(a), Dyn(b)) => { // Alignments can be summed. - if let (Some(&a), Some(&b)) = (a.downcast::(), b.downcast::()) { + if let (Some(&a), Some(&b)) = + (a.downcast::(), b.downcast::()) + { return Ok((a + b)?.into_value()); } diff --git a/crates/typst/src/foundations/content.rs b/crates/typst/src/foundations/content.rs index 9e7457ea7..3d40c7035 100644 --- a/crates/typst/src/foundations/content.rs +++ b/crates/typst/src/foundations/content.rs @@ -16,7 +16,7 @@ use crate::foundations::{ NativeElement, Recipe, Repr, Selector, Str, Style, Styles, Value, }; use crate::introspection::{Location, Meta, MetaElem}; -use crate::layout::{Align, AlignElem, Axes, Length, MoveElem, PadElem, Rel, Sides}; +use crate::layout::{AlignElem, Alignment, Axes, Length, MoveElem, PadElem, Rel, Sides}; use crate::model::{Destination, EmphElem, StrongElem}; use crate::syntax::Span; use crate::text::UnderlineElem; @@ -491,7 +491,7 @@ impl Content { } /// Set alignments for this content. - pub fn aligned(self, align: Align) -> Self { + pub fn aligned(self, align: Alignment) -> Self { self.styled(AlignElem::set_alignment(align)) } diff --git a/crates/typst/src/foundations/fields.rs b/crates/typst/src/foundations/fields.rs index 01f2348a3..422f30b88 100644 --- a/crates/typst/src/foundations/fields.rs +++ b/crates/typst/src/foundations/fields.rs @@ -4,7 +4,7 @@ use ecow::{eco_format, EcoString}; use crate::diag::StrResult; use crate::foundations::{IntoValue, Type, Value, Version}; -use crate::layout::{Align, Length, Rel}; +use crate::layout::{Alignment, Length, Rel}; use crate::visualize::Stroke; /// Try to access a field on a value. @@ -45,7 +45,7 @@ pub(crate) fn field(value: &Value, field: &str) -> StrResult { } _ => return missing(), } - } else if let Some(align) = dynamic.downcast::() { + } else if let Some(align) = dynamic.downcast::() { match field { "x" => align.x().into_value(), "y" => align.y().into_value(), @@ -83,7 +83,7 @@ pub fn fields_on(ty: Type) -> &'static [&'static str] { &["ratio", "length"] } else if ty == Type::of::() { &["paint", "thickness", "cap", "join", "dash", "miter-limit"] - } else if ty == Type::of::() { + } else if ty == Type::of::() { &["x", "y"] } else { &[] diff --git a/crates/typst/src/foundations/str.rs b/crates/typst/src/foundations/str.rs index ab4180495..57eac74d8 100644 --- a/crates/typst/src/foundations/str.rs +++ b/crates/typst/src/foundations/str.rs @@ -13,7 +13,7 @@ use crate::foundations::{ cast, dict, func, repr, scope, ty, Array, Bytes, Dict, Func, IntoValue, Label, Repr, Type, Value, Version, }; -use crate::layout::Align; +use crate::layout::Alignment; use crate::syntax::{Span, Spanned}; /// Create a new [`Str`] from a format string. @@ -933,9 +933,9 @@ pub enum StrSide { cast! { StrSide, - v: Align => match v { - Align::START => Self::Start, - Align::END => Self::End, + v: Alignment => match v { + Alignment::START => Self::Start, + Alignment::END => Self::End, _ => bail!("expected either `start` or `end`"), }, } diff --git a/crates/typst/src/layout/align.rs b/crates/typst/src/layout/align.rs index d831292b6..052ac49fe 100644 --- a/crates/typst/src/layout/align.rs +++ b/crates/typst/src/layout/align.rs @@ -38,7 +38,7 @@ pub struct AlignElem { #[positional] #[fold] #[default] - pub alignment: Align, + pub alignment: Alignment, /// The content to align. #[required] @@ -96,17 +96,17 @@ impl Show for AlignElem { /// #left.x \ /// #left.y (none) /// ``` -#[ty(scope, name = "alignment")] +#[ty(scope)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum Align { - H(HAlign), - V(VAlign), - Both(HAlign, VAlign), +pub enum Alignment { + H(HAlignment), + V(VAlignment), + Both(HAlignment, VAlignment), } -impl Align { +impl Alignment { /// The horizontal component. - pub const fn x(self) -> Option { + pub const fn x(self) -> Option { match self { Self::H(x) | Self::Both(x, _) => Some(x), Self::V(_) => None, @@ -114,7 +114,7 @@ impl Align { } /// The vertical component. - pub const fn y(self) -> Option { + pub const fn y(self) -> Option { match self { Self::V(y) | Self::Both(_, y) => Some(y), Self::H(_) => None, @@ -131,15 +131,15 @@ impl Align { } #[scope] -impl Align { - pub const START: Self = Align::H(HAlign::Start); - pub const LEFT: Self = Align::H(HAlign::Left); - pub const CENTER: Self = Align::H(HAlign::Center); - pub const RIGHT: Self = Align::H(HAlign::Right); - pub const END: Self = Align::H(HAlign::End); - pub const TOP: Self = Align::V(VAlign::Top); - pub const HORIZON: Self = Align::V(VAlign::Horizon); - pub const BOTTOM: Self = Align::V(VAlign::Bottom); +impl Alignment { + pub const START: Self = Alignment::H(HAlignment::Start); + pub const LEFT: Self = Alignment::H(HAlignment::Left); + pub const CENTER: Self = Alignment::H(HAlignment::Center); + pub const RIGHT: Self = Alignment::H(HAlignment::Right); + pub const END: Self = Alignment::H(HAlignment::End); + pub const TOP: Self = Alignment::V(VAlignment::Top); + pub const HORIZON: Self = Alignment::V(VAlignment::Horizon); + pub const BOTTOM: Self = Alignment::V(VAlignment::Bottom); /// The axis this alignment belongs to. /// - `{"horizontal"}` for `start`, `left`, `center`, `right`, and `end` @@ -168,7 +168,7 @@ impl Align { /// #(left + bottom).inv() /// ``` #[func(title = "Inverse")] - pub const fn inv(self) -> Align { + pub const fn inv(self) -> Alignment { match self { Self::H(h) => Self::H(h.inv()), Self::V(v) => Self::V(v.inv()), @@ -177,13 +177,13 @@ impl Align { } } -impl Default for Align { +impl Default for Alignment { fn default() -> Self { - HAlign::default() + VAlign::default() + HAlignment::default() + VAlignment::default() } } -impl Add for Align { +impl Add for Alignment { type Output = StrResult; fn add(self, rhs: Self) -> Self::Output { @@ -204,7 +204,7 @@ impl Add for Align { } } -impl Repr for Align { +impl Repr for Alignment { fn repr(&self) -> EcoString { match self { Self::H(x) => x.repr(), @@ -214,7 +214,7 @@ impl Repr for Align { } } -impl Fold for Align { +impl Fold for Alignment { type Output = Self; fn fold(self, outer: Self::Output) -> Self::Output { @@ -226,7 +226,7 @@ impl Fold for Align { } } -impl Resolve for Align { +impl Resolve for Alignment { type Output = Axes; fn resolve(self, styles: StyleChain) -> Self::Output { @@ -234,7 +234,7 @@ impl Resolve for Align { } } -impl From for Align { +impl From for Alignment { fn from(side: Side) -> Self { match side { Side::Left => Self::LEFT, @@ -246,12 +246,12 @@ impl From for Align { } cast! { - type Align, + type Alignment, } /// Where to align something horizontally. #[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash)] -pub enum HAlign { +pub enum HAlignment { #[default] Start, Left, @@ -260,7 +260,7 @@ pub enum HAlign { End, } -impl HAlign { +impl HAlignment { /// The inverse horizontal alignment. pub const fn inv(self) -> Self { match self { @@ -284,7 +284,7 @@ impl HAlign { } } -impl Repr for HAlign { +impl Repr for HAlignment { fn repr(&self) -> EcoString { match self { Self::Start => "start".into(), @@ -296,21 +296,21 @@ impl Repr for HAlign { } } -impl Add for HAlign { - type Output = Align; +impl Add for HAlignment { + type Output = Alignment; - fn add(self, rhs: VAlign) -> Self::Output { - Align::Both(self, rhs) + fn add(self, rhs: VAlignment) -> Self::Output { + Alignment::Both(self, rhs) } } -impl From for Align { - fn from(align: HAlign) -> Self { +impl From for Alignment { + fn from(align: HAlignment) -> Self { Self::H(align) } } -impl Resolve for HAlign { +impl Resolve for HAlignment { type Output = FixedAlign; fn resolve(self, styles: StyleChain) -> Self::Output { @@ -319,24 +319,24 @@ impl Resolve for HAlign { } cast! { - HAlign, - self => Align::H(self).into_value(), - align: Align => match align { - Align::H(v) => v, + HAlignment, + self => Alignment::H(self).into_value(), + align: Alignment => match align { + Alignment::H(v) => v, v => bail!("expected `start`, `left`, `center`, `right`, or `end`, found {}", v.repr()), } } /// Where to align something vertically. #[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub enum VAlign { +pub enum VAlignment { #[default] Top, Horizon, Bottom, } -impl VAlign { +impl VAlignment { /// The inverse vertical alignment. pub const fn inv(self) -> Self { match self { @@ -356,7 +356,7 @@ impl VAlign { } } -impl Repr for VAlign { +impl Repr for VAlignment { fn repr(&self) -> EcoString { match self { Self::Top => "top".into(), @@ -366,25 +366,25 @@ impl Repr for VAlign { } } -impl Add for VAlign { - type Output = Align; +impl Add for VAlignment { + type Output = Alignment; - fn add(self, rhs: HAlign) -> Self::Output { - Align::Both(rhs, self) + fn add(self, rhs: HAlignment) -> Self::Output { + Alignment::Both(rhs, self) } } -impl From for Align { - fn from(align: VAlign) -> Self { +impl From for Alignment { + fn from(align: VAlignment) -> Self { Self::V(align) } } cast! { - VAlign, - self => Align::V(self).into_value(), - align: Align => match align { - Align::V(v) => v, + VAlignment, + self => Alignment::V(self).into_value(), + align: Alignment => match align { + Alignment::V(v) => v, v => bail!("expected `top`, `horizon`, or `bottom`, found {}", v.repr()), } } diff --git a/crates/typst/src/layout/flow.rs b/crates/typst/src/layout/flow.rs index 6e678db4b..fd9350acf 100644 --- a/crates/typst/src/layout/flow.rs +++ b/crates/typst/src/layout/flow.rs @@ -6,7 +6,7 @@ use crate::foundations::{elem, Content, NativeElement, Resolve, Smart, StyleChai use crate::introspection::{Meta, MetaElem}; use crate::layout::{ Abs, AlignElem, Axes, BlockElem, ColbreakElem, ColumnsElem, FixedAlign, Fr, Fragment, - Frame, FrameItem, Layout, PlaceElem, Point, Regions, Rel, Size, Spacing, VAlign, + Frame, FrameItem, Layout, PlaceElem, Point, Regions, Rel, Size, Spacing, VAlignment, VElem, }; use crate::model::{FootnoteElem, FootnoteEntry, ParElem}; @@ -309,7 +309,7 @@ impl<'a> FlowLayouter<'a> { let x_align = alignment.map_or(FixedAlign::Center, |align| { align.x().unwrap_or_default().resolve(styles) }); - let y_align = alignment.map(|align| align.y().map(VAlign::fix)); + let y_align = alignment.map(|align| align.y().map(VAlignment::fix)); let frame = placed.layout(engine, styles, self.regions)?.into_frame(); let item = FlowItem::Placed { frame, x_align, y_align, delta, float, clearance }; self.layout_item(engine, item) diff --git a/crates/typst/src/layout/grid/layout.rs b/crates/typst/src/layout/grid/layout.rs index b58e73c86..a7e259d01 100644 --- a/crates/typst/src/layout/grid/layout.rs +++ b/crates/typst/src/layout/grid/layout.rs @@ -5,7 +5,7 @@ use crate::foundations::{ StyleChain, Value, }; use crate::layout::{ - Abs, Align, Axes, Dir, Fr, Fragment, Frame, FrameItem, Layout, Length, Point, + Abs, Alignment, Axes, Dir, Fr, Fragment, Frame, FrameItem, Layout, Length, Point, Regions, Rel, Sides, Size, Sizing, }; use crate::syntax::Span; @@ -119,7 +119,7 @@ pub trait ResolvableCell { x: usize, y: usize, fill: &Option, - align: Smart, + align: Smart, inset: Sides>, styles: StyleChain, ) -> Cell; @@ -212,7 +212,7 @@ impl CellGrid { gutter: Axes<&[Sizing]>, cells: &[T], fill: &Celled>, - align: &Celled>, + align: &Celled>, inset: Sides>, engine: &mut Engine, styles: StyleChain, diff --git a/crates/typst/src/layout/grid/mod.rs b/crates/typst/src/layout/grid/mod.rs index 4d66fd4a7..3b7c8553f 100644 --- a/crates/typst/src/layout/grid/mod.rs +++ b/crates/typst/src/layout/grid/mod.rs @@ -13,7 +13,8 @@ use crate::foundations::{ Value, }; use crate::layout::{ - Abs, Align, AlignElem, Axes, Fragment, Layout, Length, Regions, Rel, Sides, Sizing, + Abs, AlignElem, Alignment, Axes, Fragment, Layout, Length, Regions, Rel, Sides, + Sizing, }; use crate::visualize::{Paint, Stroke}; @@ -169,7 +170,7 @@ pub struct GridElem { /// ) /// ``` #[borrowed] - pub align: Celled>, + pub align: Celled>, /// How to [stroke]($stroke) the cells. /// @@ -299,7 +300,7 @@ pub struct GridCell { fill: Smart>, /// The cell's alignment override. - align: Smart, + align: Smart, /// The cell's inset override. inset: Smart>>>, @@ -322,7 +323,7 @@ impl ResolvableCell for GridCell { _: usize, _: usize, fill: &Option, - align: Smart, + align: Smart, inset: Sides>, styles: StyleChain, ) -> Cell { @@ -364,7 +365,7 @@ impl From for GridCell { pub fn show_grid_cell( mut body: Content, inset: Smart>>>, - align: Smart, + align: Smart, ) -> SourceResult { let inset = inset.unwrap_or_default().map(Option::unwrap_or_default); diff --git a/crates/typst/src/layout/mod.rs b/crates/typst/src/layout/mod.rs index d37e605e6..ec20d26cf 100644 --- a/crates/typst/src/layout/mod.rs +++ b/crates/typst/src/layout/mod.rs @@ -95,7 +95,7 @@ pub fn define(global: &mut Scope) { global.define_type::>(); global.define_type::(); global.define_type::(); - global.define_type::(); + global.define_type::(); global.define_elem::(); global.define_elem::(); global.define_elem::(); diff --git a/crates/typst/src/layout/page.rs b/crates/typst/src/layout/page.rs index 888e63efb..a99920a8d 100644 --- a/crates/typst/src/layout/page.rs +++ b/crates/typst/src/layout/page.rs @@ -11,8 +11,8 @@ use crate::foundations::{ }; use crate::introspection::{Counter, CounterKey, ManualPageCounter, Meta}; use crate::layout::{ - Abs, Align, AlignElem, Axes, ColumnsElem, Dir, Fragment, Frame, HAlign, Layout, - Length, Point, Ratio, Regions, Rel, Sides, Size, VAlign, + Abs, AlignElem, Alignment, Axes, ColumnsElem, Dir, Fragment, Frame, HAlignment, + Layout, Length, Point, Ratio, Regions, Rel, Sides, Size, VAlignment, }; use crate::model::Numbering; @@ -221,17 +221,17 @@ pub struct PageElem { /// /// #lorem(30) /// ``` - #[default(HAlign::Center + VAlign::Bottom)] + #[default(HAlignment::Center + VAlignment::Bottom)] #[parse({ - let option: Option> = args.named("number-align")?; + let option: Option> = args.named("number-align")?; if let Some(Spanned { v: align, span }) = option { - if align.y() == Some(VAlign::Horizon) { + if align.y() == Some(VAlignment::Horizon) { bail!(span, "page number cannot be `horizon`-aligned"); } } option.map(|spanned| spanned.v) })] - pub number_align: Align, + pub number_align: Alignment, /// The page's header. Fills the top margin of each page. /// @@ -440,7 +440,7 @@ impl PageElem { counter })); - if matches!(number_align.y(), Some(VAlign::Top)) { + if matches!(number_align.y(), Some(VAlignment::Top)) { header = if header.is_some() { header } else { numbering_marginal }; } else { footer = if footer.is_some() { footer } else { numbering_marginal }; @@ -476,16 +476,16 @@ impl PageElem { let ascent = header_ascent.relative_to(margin.top); pos = Point::with_x(margin.left); area = Size::new(pw, margin.top - ascent); - align = Align::BOTTOM; + align = Alignment::BOTTOM; } else if ptr::eq(marginal, &footer) { let descent = footer_descent.relative_to(margin.bottom); pos = Point::new(margin.left, size.y - margin.bottom + descent); area = Size::new(pw, margin.bottom - descent); - align = Align::TOP; + align = Alignment::TOP; } else { pos = Point::zero(); area = size; - align = HAlign::Center + VAlign::Horizon; + align = HAlignment::Center + VAlignment::Horizon; }; let pod = Regions::one(area, Axes::splat(true)); @@ -650,12 +650,12 @@ impl Binding { cast! { Binding, self => match self { - Self::Left => Align::LEFT.into_value(), - Self::Right => Align::RIGHT.into_value(), + Self::Left => Alignment::LEFT.into_value(), + Self::Right => Alignment::RIGHT.into_value(), }, - v: Align => match v { - Align::LEFT => Self::Left, - Align::RIGHT => Self::Right, + v: Alignment => match v { + Alignment::LEFT => Self::Left, + Alignment::RIGHT => Self::Right, _ => bail!("must be `left` or `right`"), }, } diff --git a/crates/typst/src/layout/place.rs b/crates/typst/src/layout/place.rs index b06bffa71..87dd22167 100644 --- a/crates/typst/src/layout/place.rs +++ b/crates/typst/src/layout/place.rs @@ -3,7 +3,9 @@ use crate::engine::Engine; use crate::foundations::{ elem, Behave, Behaviour, Content, NativeElement, Smart, StyleChain, }; -use crate::layout::{Align, Axes, Em, Fragment, Layout, Length, Regions, Rel, VAlign}; +use crate::layout::{ + Alignment, Axes, Em, Fragment, Layout, Length, Regions, Rel, VAlignment, +}; /// Places content at an absolute position. /// @@ -36,8 +38,8 @@ pub struct PlaceElem { /// that axis will be ignored, instead, the item will be placed in the /// origin of the axis. #[positional] - #[default(Smart::Custom(Align::START))] - pub alignment: Smart, + #[default(Smart::Custom(Alignment::START))] + pub alignment: Smart, /// Whether the placed element has floating layout. /// @@ -101,8 +103,9 @@ impl Layout for PlaceElem { let alignment = self.alignment(styles); if float - && alignment - .map_or(false, |align| matches!(align.y(), None | Some(VAlign::Horizon))) + && alignment.map_or(false, |align| { + matches!(align.y(), None | Some(VAlignment::Horizon)) + }) { bail!(self.span(), "floating placement must be `auto`, `top`, or `bottom`"); } else if !float && alignment.is_auto() { @@ -114,7 +117,7 @@ impl Layout for PlaceElem { let child = self .body() .clone() - .aligned(alignment.unwrap_or_else(|| Align::CENTER)); + .aligned(alignment.unwrap_or_else(|| Alignment::CENTER)); let pod = Regions::one(base, Axes::splat(false)); let frame = child.layout(engine, styles, pod)?.into_frame(); diff --git a/crates/typst/src/layout/sides.rs b/crates/typst/src/layout/sides.rs index 01b1f426c..8d472c4ed 100644 --- a/crates/typst/src/layout/sides.rs +++ b/crates/typst/src/layout/sides.rs @@ -5,7 +5,7 @@ use crate::diag::{bail, StrResult}; use crate::foundations::{ cast, CastInfo, Dict, Fold, FromValue, IntoValue, Reflect, Resolve, StyleChain, Value, }; -use crate::layout::{Abs, Align, Axes, Axis, Corner, Rel, Size}; +use crate::layout::{Abs, Alignment, Axes, Axis, Corner, Rel, Size}; use crate::util::Get; /// A container with left, top, right and bottom components. @@ -306,12 +306,12 @@ impl Side { cast! { Side, - self => Align::from(self).into_value(), - align: Align => match align { - Align::LEFT => Self::Left, - Align::RIGHT => Self::Right, - Align::TOP => Self::Top, - Align::BOTTOM => Self::Bottom, + self => Alignment::from(self).into_value(), + align: Alignment => match align { + Alignment::LEFT => Self::Left, + Alignment::RIGHT => Self::Right, + Alignment::TOP => Self::Top, + Alignment::BOTTOM => Self::Bottom, _ => bail!("cannot convert this alignment to a side"), }, } diff --git a/crates/typst/src/layout/transform.rs b/crates/typst/src/layout/transform.rs index 4d2878a93..e0887193f 100644 --- a/crates/typst/src/layout/transform.rs +++ b/crates/typst/src/layout/transform.rs @@ -2,8 +2,8 @@ use crate::diag::SourceResult; use crate::engine::Engine; use crate::foundations::{elem, Content, Resolve, StyleChain}; use crate::layout::{ - Abs, Align, Angle, Axes, FixedAlign, Fragment, Frame, HAlign, Layout, Length, Point, - Ratio, Regions, Rel, Size, VAlign, + Abs, Alignment, Angle, Axes, FixedAlign, Fragment, Frame, HAlignment, Layout, Length, + Point, Ratio, Regions, Rel, Size, VAlignment, }; /// Moves content without affecting layout. @@ -95,8 +95,8 @@ pub struct RotateElem { /// #box(rotate(30deg, origin: bottom + right, square())) /// ``` #[fold] - #[default(HAlign::Center + VAlign::Horizon)] - pub origin: Align, + #[default(HAlignment::Center + VAlignment::Horizon)] + pub origin: Alignment, /// Whether the rotation impacts the layout. /// @@ -183,8 +183,8 @@ pub struct ScaleElem { /// B#box(scale(75%, origin: bottom + left)[B])B /// ``` #[fold] - #[default(HAlign::Center + VAlign::Horizon)] - pub origin: Align, + #[default(HAlignment::Center + VAlignment::Horizon)] + pub origin: Alignment, /// Whether the scaling impacts the layout. /// diff --git a/crates/typst/src/lib.rs b/crates/typst/src/lib.rs index 447b8b449..bf900d94a 100644 --- a/crates/typst/src/lib.rs +++ b/crates/typst/src/lib.rs @@ -70,7 +70,7 @@ use crate::foundations::{ Array, Bytes, Content, Datetime, Dict, Module, Scope, StyleChain, Styles, }; use crate::introspection::{Introspector, Locator}; -use crate::layout::{Align, Dir, LayoutRoot}; +use crate::layout::{Alignment, Dir, LayoutRoot}; use crate::model::Document; use crate::syntax::{FileId, PackageSpec, Source, Span}; use crate::text::{Font, FontBook}; @@ -342,12 +342,12 @@ fn prelude(global: &mut Scope) { global.define("rtl", Dir::RTL); global.define("ttb", Dir::TTB); global.define("btt", Dir::BTT); - global.define("start", Align::START); - global.define("left", Align::LEFT); - global.define("center", Align::CENTER); - global.define("right", Align::RIGHT); - global.define("end", Align::END); - global.define("top", Align::TOP); - global.define("horizon", Align::HORIZON); - global.define("bottom", Align::BOTTOM); + global.define("start", Alignment::START); + global.define("left", Alignment::LEFT); + global.define("center", Alignment::CENTER); + global.define("right", Alignment::RIGHT); + global.define("end", Alignment::END); + global.define("top", Alignment::TOP); + global.define("horizon", Alignment::HORIZON); + global.define("bottom", Alignment::BOTTOM); } diff --git a/crates/typst/src/math/equation.rs b/crates/typst/src/math/equation.rs index 04e408040..17d645715 100644 --- a/crates/typst/src/math/equation.rs +++ b/crates/typst/src/math/equation.rs @@ -8,7 +8,7 @@ use crate::foundations::{ }; use crate::introspection::{Count, Counter, CounterUpdate, Locatable}; use crate::layout::{ - Abs, Align, AlignElem, Axes, Dir, Em, FixedAlign, Fragment, Frame, Layout, Point, + Abs, AlignElem, Alignment, Axes, Dir, Em, FixedAlign, Fragment, Frame, Layout, Point, Regions, Size, }; use crate::math::{LayoutMath, MathContext}; @@ -127,7 +127,7 @@ impl Finalize for EquationElem { fn finalize(&self, realized: Content, style: StyleChain) -> Content { let mut realized = realized; if self.block(style) { - realized = realized.styled(AlignElem::set_alignment(Align::CENTER)); + realized = realized.styled(AlignElem::set_alignment(Alignment::CENTER)); } realized .styled(TextElem::set_weight(FontWeight::from_number(450))) diff --git a/crates/typst/src/model/enum.rs b/crates/typst/src/model/enum.rs index 7f3ffae1a..ad0789f07 100644 --- a/crates/typst/src/model/enum.rs +++ b/crates/typst/src/model/enum.rs @@ -6,8 +6,8 @@ use crate::foundations::{ cast, elem, scope, Array, Content, Fold, NativeElement, Smart, StyleChain, }; use crate::layout::{ - Align, Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlign, Layout, - Length, Regions, Sizing, Spacing, VAlign, + Alignment, Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlignment, + Layout, Length, Regions, Sizing, Spacing, VAlignment, }; use crate::model::{Numbering, NumberingPattern, ParElem}; use crate::text::TextElem; @@ -178,8 +178,8 @@ pub struct EnumElem { /// 16. Sixteen /// 32. Thirty two /// ```` - #[default(HAlign::End + VAlign::Top)] - pub number_align: Align, + #[default(HAlignment::End + VAlignment::Top)] + pub number_align: Alignment, /// The numbered list's items. /// diff --git a/crates/typst/src/model/figure.rs b/crates/typst/src/model/figure.rs index 1b57ea2c7..ad77f1710 100644 --- a/crates/typst/src/model/figure.rs +++ b/crates/typst/src/model/figure.rs @@ -13,7 +13,9 @@ use crate::foundations::{ use crate::introspection::{ Count, Counter, CounterKey, CounterUpdate, Locatable, Location, }; -use crate::layout::{Align, BlockElem, Em, HAlign, Length, PlaceElem, VAlign, VElem}; +use crate::layout::{ + Alignment, BlockElem, Em, HAlignment, Length, PlaceElem, VAlignment, VElem, +}; use crate::model::{Numbering, NumberingPattern, Outlinable, Refable, Supplement}; use crate::syntax::Spanned; use crate::text::{Lang, Region, TextElem}; @@ -129,7 +131,7 @@ pub struct FigureElem { /// ) /// #lorem(60) /// ``` - pub placement: Option>, + pub placement: Option>, /// The figure's caption. pub caption: Option, @@ -307,7 +309,7 @@ impl Show for FigureElem { // Build the caption, if any. if let Some(caption) = self.caption(styles) { let v = VElem::weak(self.gap(styles).into()).pack(); - realized = if caption.position(styles) == VAlign::Bottom { + realized = if caption.position(styles) == VAlignment::Bottom { realized + v + caption.pack() } else { caption.pack() + v + realized @@ -319,14 +321,14 @@ impl Show for FigureElem { .with_body(Some(realized)) .spanned(self.span()) .pack() - .aligned(Align::CENTER); + .aligned(Alignment::CENTER); // Wrap in a float. if let Some(align) = self.placement(styles) { realized = PlaceElem::new(realized) .spanned(self.span()) .with_float(true) - .with_alignment(align.map(|align| HAlign::Center + align)) + .with_alignment(align.map(|align| HAlignment::Center + align)) .pack(); } @@ -450,17 +452,17 @@ pub struct FigureCaption { /// ) /// ) /// ``` - #[default(VAlign::Bottom)] + #[default(VAlignment::Bottom)] #[parse({ - let option: Option> = args.named("position")?; + let option: Option> = args.named("position")?; if let Some(Spanned { v: align, span }) = option { - if align == VAlign::Horizon { + if align == VAlignment::Horizon { bail!(span, "expected `top` or `bottom`"); } } option.map(|spanned| spanned.v) })] - pub position: VAlign, + pub position: VAlignment, /// The separator which will appear between the number and body. /// diff --git a/crates/typst/src/model/list.rs b/crates/typst/src/model/list.rs index 520657bb2..4e02f60bd 100644 --- a/crates/typst/src/model/list.rs +++ b/crates/typst/src/model/list.rs @@ -5,8 +5,8 @@ use crate::foundations::{ Value, }; use crate::layout::{ - Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlign, Layout, Length, - Regions, Sizing, Spacing, VAlign, + Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlignment, Layout, + Length, Regions, Sizing, Spacing, VAlignment, }; use crate::model::ParElem; use crate::text::TextElem; @@ -156,7 +156,7 @@ impl Layout for ListElem { .marker(styles) .resolve(engine, depth)? // avoid '#set align' interference with the list - .aligned(HAlign::Start + VAlign::Top); + .aligned(HAlignment::Start + VAlignment::Top); let mut cells = vec![]; for item in self.children() { diff --git a/crates/typst/src/model/quote.rs b/crates/typst/src/model/quote.rs index 4324280ae..920a2a976 100644 --- a/crates/typst/src/model/quote.rs +++ b/crates/typst/src/model/quote.rs @@ -4,7 +4,7 @@ use crate::foundations::{ cast, elem, Content, Finalize, Label, NativeElement, Show, Smart, StyleChain, Synthesize, }; -use crate::layout::{Align, BlockElem, Em, HElem, PadElem, Spacing, VElem}; +use crate::layout::{Alignment, BlockElem, Em, HElem, PadElem, Spacing, VElem}; use crate::model::{CitationForm, CiteElem}; use crate::text::{SmartQuoteElem, SpaceElem, TextElem}; @@ -191,7 +191,7 @@ impl Show for QuoteElem { // Use v(0.9em, weak: true) bring the attribution closer to the // quote. let weak_v = VElem::weak(Spacing::Rel(Em::new(0.9).into())).pack(); - realized += weak_v + Content::sequence(seq).aligned(Align::END); + realized += weak_v + Content::sequence(seq).aligned(Alignment::END); } realized = PadElem::new(realized).pack(); diff --git a/crates/typst/src/model/table.rs b/crates/typst/src/model/table.rs index 169289aa0..81c71462f 100644 --- a/crates/typst/src/model/table.rs +++ b/crates/typst/src/model/table.rs @@ -4,7 +4,7 @@ use crate::foundations::{ cast, elem, scope, Content, Fold, NativeElement, Show, Smart, StyleChain, }; use crate::layout::{ - show_grid_cell, Abs, Align, Axes, Cell, CellGrid, Celled, Fragment, GridLayouter, + show_grid_cell, Abs, Alignment, Axes, Cell, CellGrid, Celled, Fragment, GridLayouter, Layout, Length, Regions, Rel, ResolvableCell, Sides, TrackSizings, }; use crate::model::Figurable; @@ -118,7 +118,7 @@ pub struct TableElem { /// ) /// ``` #[borrowed] - pub align: Celled>, + pub align: Celled>, /// How to [stroke]($stroke) the cells. /// @@ -268,7 +268,7 @@ pub struct TableCell { fill: Smart>, /// The cell's alignment override. - align: Smart, + align: Smart, /// The cell's inset override. inset: Smart>>>, @@ -291,7 +291,7 @@ impl ResolvableCell for TableCell { _: usize, _: usize, fill: &Option, - align: Smart, + align: Smart, inset: Sides>, styles: StyleChain, ) -> Cell { diff --git a/crates/typst/src/text/raw.rs b/crates/typst/src/text/raw.rs index 583155cd0..c842e417a 100644 --- a/crates/typst/src/text/raw.rs +++ b/crates/typst/src/text/raw.rs @@ -15,7 +15,7 @@ use crate::foundations::{ cast, elem, scope, Args, Array, Bytes, Content, Finalize, Fold, NativeElement, PlainText, Show, Smart, StyleChain, Styles, Synthesize, Value, }; -use crate::layout::{BlockElem, Em, HAlign}; +use crate::layout::{BlockElem, Em, HAlignment}; use crate::model::Figurable; use crate::syntax::{split_newlines, LinkedNode, Spanned}; use crate::text::{ @@ -172,8 +172,8 @@ pub struct RawElem { /// code = "centered" /// ``` /// ```` - #[default(HAlign::Start)] - pub align: HAlign, + #[default(HAlignment::Start)] + pub align: HAlignment, /// One or multiple additional syntax definitions to load. The syntax /// definitions should be in the