Rename Align to Alignment

This commit is contained in:
Laurenz 2024-01-12 11:01:49 +01:00
parent bc2a4f802c
commit c298cf61f2
21 changed files with 155 additions and 147 deletions

View File

@ -7,7 +7,7 @@ use ecow::eco_format;
use crate::diag::{bail, At, SourceResult, StrResult}; use crate::diag::{bail, At, SourceResult, StrResult};
use crate::eval::{access_dict, Access, Eval, Vm}; use crate::eval::{access_dict, Access, Eval, Vm};
use crate::foundations::{format_str, Datetime, IntoValue, Regex, Repr, Value}; 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::syntax::ast::{self, AstNode};
use crate::text::TextElem; use crate::text::TextElem;
use crate::util::Numeric; use crate::util::Numeric;
@ -148,7 +148,7 @@ pub fn pos(value: Value) -> StrResult<Value> {
mismatch!("cannot apply unary '+' to {}", value) mismatch!("cannot apply unary '+' to {}", value)
} }
Dyn(d) => { Dyn(d) => {
if d.is::<Align>() { if d.is::<Alignment>() {
mismatch!("cannot apply unary '+' to {}", d) mismatch!("cannot apply unary '+' to {}", d)
} else { } else {
mismatch!("cannot apply '+' to {}", d) mismatch!("cannot apply '+' to {}", d)
@ -238,7 +238,9 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
(Dyn(a), Dyn(b)) => { (Dyn(a), Dyn(b)) => {
// Alignments can be summed. // Alignments can be summed.
if let (Some(&a), Some(&b)) = (a.downcast::<Align>(), b.downcast::<Align>()) { if let (Some(&a), Some(&b)) =
(a.downcast::<Alignment>(), b.downcast::<Alignment>())
{
return Ok((a + b)?.into_value()); return Ok((a + b)?.into_value());
} }

View File

@ -16,7 +16,7 @@ use crate::foundations::{
NativeElement, Recipe, Repr, Selector, Str, Style, Styles, Value, NativeElement, Recipe, Repr, Selector, Str, Style, Styles, Value,
}; };
use crate::introspection::{Location, Meta, MetaElem}; 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::model::{Destination, EmphElem, StrongElem};
use crate::syntax::Span; use crate::syntax::Span;
use crate::text::UnderlineElem; use crate::text::UnderlineElem;
@ -491,7 +491,7 @@ impl Content {
} }
/// Set alignments for this 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)) self.styled(AlignElem::set_alignment(align))
} }

View File

@ -4,7 +4,7 @@ use ecow::{eco_format, EcoString};
use crate::diag::StrResult; use crate::diag::StrResult;
use crate::foundations::{IntoValue, Type, Value, Version}; use crate::foundations::{IntoValue, Type, Value, Version};
use crate::layout::{Align, Length, Rel}; use crate::layout::{Alignment, Length, Rel};
use crate::visualize::Stroke; use crate::visualize::Stroke;
/// Try to access a field on a value. /// Try to access a field on a value.
@ -45,7 +45,7 @@ pub(crate) fn field(value: &Value, field: &str) -> StrResult<Value> {
} }
_ => return missing(), _ => return missing(),
} }
} else if let Some(align) = dynamic.downcast::<Align>() { } else if let Some(align) = dynamic.downcast::<Alignment>() {
match field { match field {
"x" => align.x().into_value(), "x" => align.x().into_value(),
"y" => align.y().into_value(), "y" => align.y().into_value(),
@ -83,7 +83,7 @@ pub fn fields_on(ty: Type) -> &'static [&'static str] {
&["ratio", "length"] &["ratio", "length"]
} else if ty == Type::of::<Stroke>() { } else if ty == Type::of::<Stroke>() {
&["paint", "thickness", "cap", "join", "dash", "miter-limit"] &["paint", "thickness", "cap", "join", "dash", "miter-limit"]
} else if ty == Type::of::<Align>() { } else if ty == Type::of::<Alignment>() {
&["x", "y"] &["x", "y"]
} else { } else {
&[] &[]

View File

@ -13,7 +13,7 @@ use crate::foundations::{
cast, dict, func, repr, scope, ty, Array, Bytes, Dict, Func, IntoValue, Label, Repr, cast, dict, func, repr, scope, ty, Array, Bytes, Dict, Func, IntoValue, Label, Repr,
Type, Value, Version, Type, Value, Version,
}; };
use crate::layout::Align; use crate::layout::Alignment;
use crate::syntax::{Span, Spanned}; use crate::syntax::{Span, Spanned};
/// Create a new [`Str`] from a format string. /// Create a new [`Str`] from a format string.
@ -933,9 +933,9 @@ pub enum StrSide {
cast! { cast! {
StrSide, StrSide,
v: Align => match v { v: Alignment => match v {
Align::START => Self::Start, Alignment::START => Self::Start,
Align::END => Self::End, Alignment::END => Self::End,
_ => bail!("expected either `start` or `end`"), _ => bail!("expected either `start` or `end`"),
}, },
} }

View File

@ -38,7 +38,7 @@ pub struct AlignElem {
#[positional] #[positional]
#[fold] #[fold]
#[default] #[default]
pub alignment: Align, pub alignment: Alignment,
/// The content to align. /// The content to align.
#[required] #[required]
@ -96,17 +96,17 @@ impl Show for AlignElem {
/// #left.x \ /// #left.x \
/// #left.y (none) /// #left.y (none)
/// ``` /// ```
#[ty(scope, name = "alignment")] #[ty(scope)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Align { pub enum Alignment {
H(HAlign), H(HAlignment),
V(VAlign), V(VAlignment),
Both(HAlign, VAlign), Both(HAlignment, VAlignment),
} }
impl Align { impl Alignment {
/// The horizontal component. /// The horizontal component.
pub const fn x(self) -> Option<HAlign> { pub const fn x(self) -> Option<HAlignment> {
match self { match self {
Self::H(x) | Self::Both(x, _) => Some(x), Self::H(x) | Self::Both(x, _) => Some(x),
Self::V(_) => None, Self::V(_) => None,
@ -114,7 +114,7 @@ impl Align {
} }
/// The vertical component. /// The vertical component.
pub const fn y(self) -> Option<VAlign> { pub const fn y(self) -> Option<VAlignment> {
match self { match self {
Self::V(y) | Self::Both(_, y) => Some(y), Self::V(y) | Self::Both(_, y) => Some(y),
Self::H(_) => None, Self::H(_) => None,
@ -131,15 +131,15 @@ impl Align {
} }
#[scope] #[scope]
impl Align { impl Alignment {
pub const START: Self = Align::H(HAlign::Start); pub const START: Self = Alignment::H(HAlignment::Start);
pub const LEFT: Self = Align::H(HAlign::Left); pub const LEFT: Self = Alignment::H(HAlignment::Left);
pub const CENTER: Self = Align::H(HAlign::Center); pub const CENTER: Self = Alignment::H(HAlignment::Center);
pub const RIGHT: Self = Align::H(HAlign::Right); pub const RIGHT: Self = Alignment::H(HAlignment::Right);
pub const END: Self = Align::H(HAlign::End); pub const END: Self = Alignment::H(HAlignment::End);
pub const TOP: Self = Align::V(VAlign::Top); pub const TOP: Self = Alignment::V(VAlignment::Top);
pub const HORIZON: Self = Align::V(VAlign::Horizon); pub const HORIZON: Self = Alignment::V(VAlignment::Horizon);
pub const BOTTOM: Self = Align::V(VAlign::Bottom); pub const BOTTOM: Self = Alignment::V(VAlignment::Bottom);
/// The axis this alignment belongs to. /// The axis this alignment belongs to.
/// - `{"horizontal"}` for `start`, `left`, `center`, `right`, and `end` /// - `{"horizontal"}` for `start`, `left`, `center`, `right`, and `end`
@ -168,7 +168,7 @@ impl Align {
/// #(left + bottom).inv() /// #(left + bottom).inv()
/// ``` /// ```
#[func(title = "Inverse")] #[func(title = "Inverse")]
pub const fn inv(self) -> Align { pub const fn inv(self) -> Alignment {
match self { match self {
Self::H(h) => Self::H(h.inv()), Self::H(h) => Self::H(h.inv()),
Self::V(v) => Self::V(v.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 { fn default() -> Self {
HAlign::default() + VAlign::default() HAlignment::default() + VAlignment::default()
} }
} }
impl Add for Align { impl Add for Alignment {
type Output = StrResult<Self>; type Output = StrResult<Self>;
fn add(self, rhs: Self) -> Self::Output { 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 { fn repr(&self) -> EcoString {
match self { match self {
Self::H(x) => x.repr(), Self::H(x) => x.repr(),
@ -214,7 +214,7 @@ impl Repr for Align {
} }
} }
impl Fold for Align { impl Fold for Alignment {
type Output = Self; type Output = Self;
fn fold(self, outer: Self::Output) -> Self::Output { 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<FixedAlign>; type Output = Axes<FixedAlign>;
fn resolve(self, styles: StyleChain) -> Self::Output { fn resolve(self, styles: StyleChain) -> Self::Output {
@ -234,7 +234,7 @@ impl Resolve for Align {
} }
} }
impl From<Side> for Align { impl From<Side> for Alignment {
fn from(side: Side) -> Self { fn from(side: Side) -> Self {
match side { match side {
Side::Left => Self::LEFT, Side::Left => Self::LEFT,
@ -246,12 +246,12 @@ impl From<Side> for Align {
} }
cast! { cast! {
type Align, type Alignment,
} }
/// Where to align something horizontally. /// Where to align something horizontally.
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash)]
pub enum HAlign { pub enum HAlignment {
#[default] #[default]
Start, Start,
Left, Left,
@ -260,7 +260,7 @@ pub enum HAlign {
End, End,
} }
impl HAlign { impl HAlignment {
/// The inverse horizontal alignment. /// The inverse horizontal alignment.
pub const fn inv(self) -> Self { pub const fn inv(self) -> Self {
match self { match self {
@ -284,7 +284,7 @@ impl HAlign {
} }
} }
impl Repr for HAlign { impl Repr for HAlignment {
fn repr(&self) -> EcoString { fn repr(&self) -> EcoString {
match self { match self {
Self::Start => "start".into(), Self::Start => "start".into(),
@ -296,21 +296,21 @@ impl Repr for HAlign {
} }
} }
impl Add<VAlign> for HAlign { impl Add<VAlignment> for HAlignment {
type Output = Align; type Output = Alignment;
fn add(self, rhs: VAlign) -> Self::Output { fn add(self, rhs: VAlignment) -> Self::Output {
Align::Both(self, rhs) Alignment::Both(self, rhs)
} }
} }
impl From<HAlign> for Align { impl From<HAlignment> for Alignment {
fn from(align: HAlign) -> Self { fn from(align: HAlignment) -> Self {
Self::H(align) Self::H(align)
} }
} }
impl Resolve for HAlign { impl Resolve for HAlignment {
type Output = FixedAlign; type Output = FixedAlign;
fn resolve(self, styles: StyleChain) -> Self::Output { fn resolve(self, styles: StyleChain) -> Self::Output {
@ -319,24 +319,24 @@ impl Resolve for HAlign {
} }
cast! { cast! {
HAlign, HAlignment,
self => Align::H(self).into_value(), self => Alignment::H(self).into_value(),
align: Align => match align { align: Alignment => match align {
Align::H(v) => v, Alignment::H(v) => v,
v => bail!("expected `start`, `left`, `center`, `right`, or `end`, found {}", v.repr()), v => bail!("expected `start`, `left`, `center`, `right`, or `end`, found {}", v.repr()),
} }
} }
/// Where to align something vertically. /// Where to align something vertically.
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum VAlign { pub enum VAlignment {
#[default] #[default]
Top, Top,
Horizon, Horizon,
Bottom, Bottom,
} }
impl VAlign { impl VAlignment {
/// The inverse vertical alignment. /// The inverse vertical alignment.
pub const fn inv(self) -> Self { pub const fn inv(self) -> Self {
match self { match self {
@ -356,7 +356,7 @@ impl VAlign {
} }
} }
impl Repr for VAlign { impl Repr for VAlignment {
fn repr(&self) -> EcoString { fn repr(&self) -> EcoString {
match self { match self {
Self::Top => "top".into(), Self::Top => "top".into(),
@ -366,25 +366,25 @@ impl Repr for VAlign {
} }
} }
impl Add<HAlign> for VAlign { impl Add<HAlignment> for VAlignment {
type Output = Align; type Output = Alignment;
fn add(self, rhs: HAlign) -> Self::Output { fn add(self, rhs: HAlignment) -> Self::Output {
Align::Both(rhs, self) Alignment::Both(rhs, self)
} }
} }
impl From<VAlign> for Align { impl From<VAlignment> for Alignment {
fn from(align: VAlign) -> Self { fn from(align: VAlignment) -> Self {
Self::V(align) Self::V(align)
} }
} }
cast! { cast! {
VAlign, VAlignment,
self => Align::V(self).into_value(), self => Alignment::V(self).into_value(),
align: Align => match align { align: Alignment => match align {
Align::V(v) => v, Alignment::V(v) => v,
v => bail!("expected `top`, `horizon`, or `bottom`, found {}", v.repr()), v => bail!("expected `top`, `horizon`, or `bottom`, found {}", v.repr()),
} }
} }

View File

@ -6,7 +6,7 @@ use crate::foundations::{elem, Content, NativeElement, Resolve, Smart, StyleChai
use crate::introspection::{Meta, MetaElem}; use crate::introspection::{Meta, MetaElem};
use crate::layout::{ use crate::layout::{
Abs, AlignElem, Axes, BlockElem, ColbreakElem, ColumnsElem, FixedAlign, Fr, Fragment, 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, VElem,
}; };
use crate::model::{FootnoteElem, FootnoteEntry, ParElem}; use crate::model::{FootnoteElem, FootnoteEntry, ParElem};
@ -309,7 +309,7 @@ impl<'a> FlowLayouter<'a> {
let x_align = alignment.map_or(FixedAlign::Center, |align| { let x_align = alignment.map_or(FixedAlign::Center, |align| {
align.x().unwrap_or_default().resolve(styles) 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 frame = placed.layout(engine, styles, self.regions)?.into_frame();
let item = FlowItem::Placed { frame, x_align, y_align, delta, float, clearance }; let item = FlowItem::Placed { frame, x_align, y_align, delta, float, clearance };
self.layout_item(engine, item) self.layout_item(engine, item)

View File

@ -5,7 +5,7 @@ use crate::foundations::{
StyleChain, Value, StyleChain, Value,
}; };
use crate::layout::{ 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, Regions, Rel, Sides, Size, Sizing,
}; };
use crate::syntax::Span; use crate::syntax::Span;
@ -119,7 +119,7 @@ pub trait ResolvableCell {
x: usize, x: usize,
y: usize, y: usize,
fill: &Option<Paint>, fill: &Option<Paint>,
align: Smart<Align>, align: Smart<Alignment>,
inset: Sides<Rel<Length>>, inset: Sides<Rel<Length>>,
styles: StyleChain, styles: StyleChain,
) -> Cell; ) -> Cell;
@ -212,7 +212,7 @@ impl CellGrid {
gutter: Axes<&[Sizing]>, gutter: Axes<&[Sizing]>,
cells: &[T], cells: &[T],
fill: &Celled<Option<Paint>>, fill: &Celled<Option<Paint>>,
align: &Celled<Smart<Align>>, align: &Celled<Smart<Alignment>>,
inset: Sides<Rel<Length>>, inset: Sides<Rel<Length>>,
engine: &mut Engine, engine: &mut Engine,
styles: StyleChain, styles: StyleChain,

View File

@ -13,7 +13,8 @@ use crate::foundations::{
Value, Value,
}; };
use crate::layout::{ 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}; use crate::visualize::{Paint, Stroke};
@ -169,7 +170,7 @@ pub struct GridElem {
/// ) /// )
/// ``` /// ```
#[borrowed] #[borrowed]
pub align: Celled<Smart<Align>>, pub align: Celled<Smart<Alignment>>,
/// How to [stroke]($stroke) the cells. /// How to [stroke]($stroke) the cells.
/// ///
@ -299,7 +300,7 @@ pub struct GridCell {
fill: Smart<Option<Paint>>, fill: Smart<Option<Paint>>,
/// The cell's alignment override. /// The cell's alignment override.
align: Smart<Align>, align: Smart<Alignment>,
/// The cell's inset override. /// The cell's inset override.
inset: Smart<Sides<Option<Rel<Length>>>>, inset: Smart<Sides<Option<Rel<Length>>>>,
@ -322,7 +323,7 @@ impl ResolvableCell for GridCell {
_: usize, _: usize,
_: usize, _: usize,
fill: &Option<Paint>, fill: &Option<Paint>,
align: Smart<Align>, align: Smart<Alignment>,
inset: Sides<Rel<Length>>, inset: Sides<Rel<Length>>,
styles: StyleChain, styles: StyleChain,
) -> Cell { ) -> Cell {
@ -364,7 +365,7 @@ impl From<Content> for GridCell {
pub fn show_grid_cell( pub fn show_grid_cell(
mut body: Content, mut body: Content,
inset: Smart<Sides<Option<Rel<Length>>>>, inset: Smart<Sides<Option<Rel<Length>>>>,
align: Smart<Align>, align: Smart<Alignment>,
) -> SourceResult<Content> { ) -> SourceResult<Content> {
let inset = inset.unwrap_or_default().map(Option::unwrap_or_default); let inset = inset.unwrap_or_default().map(Option::unwrap_or_default);

View File

@ -95,7 +95,7 @@ pub fn define(global: &mut Scope) {
global.define_type::<Rel<Length>>(); global.define_type::<Rel<Length>>();
global.define_type::<Fr>(); global.define_type::<Fr>();
global.define_type::<Dir>(); global.define_type::<Dir>();
global.define_type::<Align>(); global.define_type::<Alignment>();
global.define_elem::<PageElem>(); global.define_elem::<PageElem>();
global.define_elem::<PagebreakElem>(); global.define_elem::<PagebreakElem>();
global.define_elem::<VElem>(); global.define_elem::<VElem>();

View File

@ -11,8 +11,8 @@ use crate::foundations::{
}; };
use crate::introspection::{Counter, CounterKey, ManualPageCounter, Meta}; use crate::introspection::{Counter, CounterKey, ManualPageCounter, Meta};
use crate::layout::{ use crate::layout::{
Abs, Align, AlignElem, Axes, ColumnsElem, Dir, Fragment, Frame, HAlign, Layout, Abs, AlignElem, Alignment, Axes, ColumnsElem, Dir, Fragment, Frame, HAlignment,
Length, Point, Ratio, Regions, Rel, Sides, Size, VAlign, Layout, Length, Point, Ratio, Regions, Rel, Sides, Size, VAlignment,
}; };
use crate::model::Numbering; use crate::model::Numbering;
@ -221,17 +221,17 @@ pub struct PageElem {
/// ///
/// #lorem(30) /// #lorem(30)
/// ``` /// ```
#[default(HAlign::Center + VAlign::Bottom)] #[default(HAlignment::Center + VAlignment::Bottom)]
#[parse({ #[parse({
let option: Option<Spanned<Align>> = args.named("number-align")?; let option: Option<Spanned<Alignment>> = args.named("number-align")?;
if let Some(Spanned { v: align, span }) = option { 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"); bail!(span, "page number cannot be `horizon`-aligned");
} }
} }
option.map(|spanned| spanned.v) option.map(|spanned| spanned.v)
})] })]
pub number_align: Align, pub number_align: Alignment,
/// The page's header. Fills the top margin of each page. /// The page's header. Fills the top margin of each page.
/// ///
@ -440,7 +440,7 @@ impl PageElem {
counter 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 }; header = if header.is_some() { header } else { numbering_marginal };
} else { } else {
footer = if footer.is_some() { footer } else { numbering_marginal }; footer = if footer.is_some() { footer } else { numbering_marginal };
@ -476,16 +476,16 @@ impl PageElem {
let ascent = header_ascent.relative_to(margin.top); let ascent = header_ascent.relative_to(margin.top);
pos = Point::with_x(margin.left); pos = Point::with_x(margin.left);
area = Size::new(pw, margin.top - ascent); area = Size::new(pw, margin.top - ascent);
align = Align::BOTTOM; align = Alignment::BOTTOM;
} else if ptr::eq(marginal, &footer) { } else if ptr::eq(marginal, &footer) {
let descent = footer_descent.relative_to(margin.bottom); let descent = footer_descent.relative_to(margin.bottom);
pos = Point::new(margin.left, size.y - margin.bottom + descent); pos = Point::new(margin.left, size.y - margin.bottom + descent);
area = Size::new(pw, margin.bottom - descent); area = Size::new(pw, margin.bottom - descent);
align = Align::TOP; align = Alignment::TOP;
} else { } else {
pos = Point::zero(); pos = Point::zero();
area = size; area = size;
align = HAlign::Center + VAlign::Horizon; align = HAlignment::Center + VAlignment::Horizon;
}; };
let pod = Regions::one(area, Axes::splat(true)); let pod = Regions::one(area, Axes::splat(true));
@ -650,12 +650,12 @@ impl Binding {
cast! { cast! {
Binding, Binding,
self => match self { self => match self {
Self::Left => Align::LEFT.into_value(), Self::Left => Alignment::LEFT.into_value(),
Self::Right => Align::RIGHT.into_value(), Self::Right => Alignment::RIGHT.into_value(),
}, },
v: Align => match v { v: Alignment => match v {
Align::LEFT => Self::Left, Alignment::LEFT => Self::Left,
Align::RIGHT => Self::Right, Alignment::RIGHT => Self::Right,
_ => bail!("must be `left` or `right`"), _ => bail!("must be `left` or `right`"),
}, },
} }

View File

@ -3,7 +3,9 @@ use crate::engine::Engine;
use crate::foundations::{ use crate::foundations::{
elem, Behave, Behaviour, Content, NativeElement, Smart, StyleChain, 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. /// 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 /// that axis will be ignored, instead, the item will be placed in the
/// origin of the axis. /// origin of the axis.
#[positional] #[positional]
#[default(Smart::Custom(Align::START))] #[default(Smart::Custom(Alignment::START))]
pub alignment: Smart<Align>, pub alignment: Smart<Alignment>,
/// Whether the placed element has floating layout. /// Whether the placed element has floating layout.
/// ///
@ -101,8 +103,9 @@ impl Layout for PlaceElem {
let alignment = self.alignment(styles); let alignment = self.alignment(styles);
if float if float
&& alignment && alignment.map_or(false, |align| {
.map_or(false, |align| matches!(align.y(), None | Some(VAlign::Horizon))) matches!(align.y(), None | Some(VAlignment::Horizon))
})
{ {
bail!(self.span(), "floating placement must be `auto`, `top`, or `bottom`"); bail!(self.span(), "floating placement must be `auto`, `top`, or `bottom`");
} else if !float && alignment.is_auto() { } else if !float && alignment.is_auto() {
@ -114,7 +117,7 @@ impl Layout for PlaceElem {
let child = self let child = self
.body() .body()
.clone() .clone()
.aligned(alignment.unwrap_or_else(|| Align::CENTER)); .aligned(alignment.unwrap_or_else(|| Alignment::CENTER));
let pod = Regions::one(base, Axes::splat(false)); let pod = Regions::one(base, Axes::splat(false));
let frame = child.layout(engine, styles, pod)?.into_frame(); let frame = child.layout(engine, styles, pod)?.into_frame();

View File

@ -5,7 +5,7 @@ use crate::diag::{bail, StrResult};
use crate::foundations::{ use crate::foundations::{
cast, CastInfo, Dict, Fold, FromValue, IntoValue, Reflect, Resolve, StyleChain, Value, 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; use crate::util::Get;
/// A container with left, top, right and bottom components. /// A container with left, top, right and bottom components.
@ -306,12 +306,12 @@ impl Side {
cast! { cast! {
Side, Side,
self => Align::from(self).into_value(), self => Alignment::from(self).into_value(),
align: Align => match align { align: Alignment => match align {
Align::LEFT => Self::Left, Alignment::LEFT => Self::Left,
Align::RIGHT => Self::Right, Alignment::RIGHT => Self::Right,
Align::TOP => Self::Top, Alignment::TOP => Self::Top,
Align::BOTTOM => Self::Bottom, Alignment::BOTTOM => Self::Bottom,
_ => bail!("cannot convert this alignment to a side"), _ => bail!("cannot convert this alignment to a side"),
}, },
} }

View File

@ -2,8 +2,8 @@ use crate::diag::SourceResult;
use crate::engine::Engine; use crate::engine::Engine;
use crate::foundations::{elem, Content, Resolve, StyleChain}; use crate::foundations::{elem, Content, Resolve, StyleChain};
use crate::layout::{ use crate::layout::{
Abs, Align, Angle, Axes, FixedAlign, Fragment, Frame, HAlign, Layout, Length, Point, Abs, Alignment, Angle, Axes, FixedAlign, Fragment, Frame, HAlignment, Layout, Length,
Ratio, Regions, Rel, Size, VAlign, Point, Ratio, Regions, Rel, Size, VAlignment,
}; };
/// Moves content without affecting layout. /// Moves content without affecting layout.
@ -95,8 +95,8 @@ pub struct RotateElem {
/// #box(rotate(30deg, origin: bottom + right, square())) /// #box(rotate(30deg, origin: bottom + right, square()))
/// ``` /// ```
#[fold] #[fold]
#[default(HAlign::Center + VAlign::Horizon)] #[default(HAlignment::Center + VAlignment::Horizon)]
pub origin: Align, pub origin: Alignment,
/// Whether the rotation impacts the layout. /// Whether the rotation impacts the layout.
/// ///
@ -183,8 +183,8 @@ pub struct ScaleElem {
/// B#box(scale(75%, origin: bottom + left)[B])B /// B#box(scale(75%, origin: bottom + left)[B])B
/// ``` /// ```
#[fold] #[fold]
#[default(HAlign::Center + VAlign::Horizon)] #[default(HAlignment::Center + VAlignment::Horizon)]
pub origin: Align, pub origin: Alignment,
/// Whether the scaling impacts the layout. /// Whether the scaling impacts the layout.
/// ///

View File

@ -70,7 +70,7 @@ use crate::foundations::{
Array, Bytes, Content, Datetime, Dict, Module, Scope, StyleChain, Styles, Array, Bytes, Content, Datetime, Dict, Module, Scope, StyleChain, Styles,
}; };
use crate::introspection::{Introspector, Locator}; use crate::introspection::{Introspector, Locator};
use crate::layout::{Align, Dir, LayoutRoot}; use crate::layout::{Alignment, Dir, LayoutRoot};
use crate::model::Document; use crate::model::Document;
use crate::syntax::{FileId, PackageSpec, Source, Span}; use crate::syntax::{FileId, PackageSpec, Source, Span};
use crate::text::{Font, FontBook}; use crate::text::{Font, FontBook};
@ -342,12 +342,12 @@ fn prelude(global: &mut Scope) {
global.define("rtl", Dir::RTL); global.define("rtl", Dir::RTL);
global.define("ttb", Dir::TTB); global.define("ttb", Dir::TTB);
global.define("btt", Dir::BTT); global.define("btt", Dir::BTT);
global.define("start", Align::START); global.define("start", Alignment::START);
global.define("left", Align::LEFT); global.define("left", Alignment::LEFT);
global.define("center", Align::CENTER); global.define("center", Alignment::CENTER);
global.define("right", Align::RIGHT); global.define("right", Alignment::RIGHT);
global.define("end", Align::END); global.define("end", Alignment::END);
global.define("top", Align::TOP); global.define("top", Alignment::TOP);
global.define("horizon", Align::HORIZON); global.define("horizon", Alignment::HORIZON);
global.define("bottom", Align::BOTTOM); global.define("bottom", Alignment::BOTTOM);
} }

View File

@ -8,7 +8,7 @@ use crate::foundations::{
}; };
use crate::introspection::{Count, Counter, CounterUpdate, Locatable}; use crate::introspection::{Count, Counter, CounterUpdate, Locatable};
use crate::layout::{ 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, Regions, Size,
}; };
use crate::math::{LayoutMath, MathContext}; use crate::math::{LayoutMath, MathContext};
@ -127,7 +127,7 @@ impl Finalize for EquationElem {
fn finalize(&self, realized: Content, style: StyleChain) -> Content { fn finalize(&self, realized: Content, style: StyleChain) -> Content {
let mut realized = realized; let mut realized = realized;
if self.block(style) { if self.block(style) {
realized = realized.styled(AlignElem::set_alignment(Align::CENTER)); realized = realized.styled(AlignElem::set_alignment(Alignment::CENTER));
} }
realized realized
.styled(TextElem::set_weight(FontWeight::from_number(450))) .styled(TextElem::set_weight(FontWeight::from_number(450)))

View File

@ -6,8 +6,8 @@ use crate::foundations::{
cast, elem, scope, Array, Content, Fold, NativeElement, Smart, StyleChain, cast, elem, scope, Array, Content, Fold, NativeElement, Smart, StyleChain,
}; };
use crate::layout::{ use crate::layout::{
Align, Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlign, Layout, Alignment, Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlignment,
Length, Regions, Sizing, Spacing, VAlign, Layout, Length, Regions, Sizing, Spacing, VAlignment,
}; };
use crate::model::{Numbering, NumberingPattern, ParElem}; use crate::model::{Numbering, NumberingPattern, ParElem};
use crate::text::TextElem; use crate::text::TextElem;
@ -178,8 +178,8 @@ pub struct EnumElem {
/// 16. Sixteen /// 16. Sixteen
/// 32. Thirty two /// 32. Thirty two
/// ```` /// ````
#[default(HAlign::End + VAlign::Top)] #[default(HAlignment::End + VAlignment::Top)]
pub number_align: Align, pub number_align: Alignment,
/// The numbered list's items. /// The numbered list's items.
/// ///

View File

@ -13,7 +13,9 @@ use crate::foundations::{
use crate::introspection::{ use crate::introspection::{
Count, Counter, CounterKey, CounterUpdate, Locatable, Location, 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::model::{Numbering, NumberingPattern, Outlinable, Refable, Supplement};
use crate::syntax::Spanned; use crate::syntax::Spanned;
use crate::text::{Lang, Region, TextElem}; use crate::text::{Lang, Region, TextElem};
@ -129,7 +131,7 @@ pub struct FigureElem {
/// ) /// )
/// #lorem(60) /// #lorem(60)
/// ``` /// ```
pub placement: Option<Smart<VAlign>>, pub placement: Option<Smart<VAlignment>>,
/// The figure's caption. /// The figure's caption.
pub caption: Option<FigureCaption>, pub caption: Option<FigureCaption>,
@ -307,7 +309,7 @@ impl Show for FigureElem {
// Build the caption, if any. // Build the caption, if any.
if let Some(caption) = self.caption(styles) { if let Some(caption) = self.caption(styles) {
let v = VElem::weak(self.gap(styles).into()).pack(); 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() realized + v + caption.pack()
} else { } else {
caption.pack() + v + realized caption.pack() + v + realized
@ -319,14 +321,14 @@ impl Show for FigureElem {
.with_body(Some(realized)) .with_body(Some(realized))
.spanned(self.span()) .spanned(self.span())
.pack() .pack()
.aligned(Align::CENTER); .aligned(Alignment::CENTER);
// Wrap in a float. // Wrap in a float.
if let Some(align) = self.placement(styles) { if let Some(align) = self.placement(styles) {
realized = PlaceElem::new(realized) realized = PlaceElem::new(realized)
.spanned(self.span()) .spanned(self.span())
.with_float(true) .with_float(true)
.with_alignment(align.map(|align| HAlign::Center + align)) .with_alignment(align.map(|align| HAlignment::Center + align))
.pack(); .pack();
} }
@ -450,17 +452,17 @@ pub struct FigureCaption {
/// ) /// )
/// ) /// )
/// ``` /// ```
#[default(VAlign::Bottom)] #[default(VAlignment::Bottom)]
#[parse({ #[parse({
let option: Option<Spanned<VAlign>> = args.named("position")?; let option: Option<Spanned<VAlignment>> = args.named("position")?;
if let Some(Spanned { v: align, span }) = option { if let Some(Spanned { v: align, span }) = option {
if align == VAlign::Horizon { if align == VAlignment::Horizon {
bail!(span, "expected `top` or `bottom`"); bail!(span, "expected `top` or `bottom`");
} }
} }
option.map(|spanned| spanned.v) option.map(|spanned| spanned.v)
})] })]
pub position: VAlign, pub position: VAlignment,
/// The separator which will appear between the number and body. /// The separator which will appear between the number and body.
/// ///

View File

@ -5,8 +5,8 @@ use crate::foundations::{
Value, Value,
}; };
use crate::layout::{ use crate::layout::{
Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlign, Layout, Length, Axes, BlockElem, Cell, CellGrid, Em, Fragment, GridLayouter, HAlignment, Layout,
Regions, Sizing, Spacing, VAlign, Length, Regions, Sizing, Spacing, VAlignment,
}; };
use crate::model::ParElem; use crate::model::ParElem;
use crate::text::TextElem; use crate::text::TextElem;
@ -156,7 +156,7 @@ impl Layout for ListElem {
.marker(styles) .marker(styles)
.resolve(engine, depth)? .resolve(engine, depth)?
// avoid '#set align' interference with the list // avoid '#set align' interference with the list
.aligned(HAlign::Start + VAlign::Top); .aligned(HAlignment::Start + VAlignment::Top);
let mut cells = vec![]; let mut cells = vec![];
for item in self.children() { for item in self.children() {

View File

@ -4,7 +4,7 @@ use crate::foundations::{
cast, elem, Content, Finalize, Label, NativeElement, Show, Smart, StyleChain, cast, elem, Content, Finalize, Label, NativeElement, Show, Smart, StyleChain,
Synthesize, 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::model::{CitationForm, CiteElem};
use crate::text::{SmartQuoteElem, SpaceElem, TextElem}; 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 // Use v(0.9em, weak: true) bring the attribution closer to the
// quote. // quote.
let weak_v = VElem::weak(Spacing::Rel(Em::new(0.9).into())).pack(); 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(); realized = PadElem::new(realized).pack();

View File

@ -4,7 +4,7 @@ use crate::foundations::{
cast, elem, scope, Content, Fold, NativeElement, Show, Smart, StyleChain, cast, elem, scope, Content, Fold, NativeElement, Show, Smart, StyleChain,
}; };
use crate::layout::{ 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, Layout, Length, Regions, Rel, ResolvableCell, Sides, TrackSizings,
}; };
use crate::model::Figurable; use crate::model::Figurable;
@ -118,7 +118,7 @@ pub struct TableElem {
/// ) /// )
/// ``` /// ```
#[borrowed] #[borrowed]
pub align: Celled<Smart<Align>>, pub align: Celled<Smart<Alignment>>,
/// How to [stroke]($stroke) the cells. /// How to [stroke]($stroke) the cells.
/// ///
@ -268,7 +268,7 @@ pub struct TableCell {
fill: Smart<Option<Paint>>, fill: Smart<Option<Paint>>,
/// The cell's alignment override. /// The cell's alignment override.
align: Smart<Align>, align: Smart<Alignment>,
/// The cell's inset override. /// The cell's inset override.
inset: Smart<Sides<Option<Rel<Length>>>>, inset: Smart<Sides<Option<Rel<Length>>>>,
@ -291,7 +291,7 @@ impl ResolvableCell for TableCell {
_: usize, _: usize,
_: usize, _: usize,
fill: &Option<Paint>, fill: &Option<Paint>,
align: Smart<Align>, align: Smart<Alignment>,
inset: Sides<Rel<Length>>, inset: Sides<Rel<Length>>,
styles: StyleChain, styles: StyleChain,
) -> Cell { ) -> Cell {

View File

@ -15,7 +15,7 @@ use crate::foundations::{
cast, elem, scope, Args, Array, Bytes, Content, Finalize, Fold, NativeElement, cast, elem, scope, Args, Array, Bytes, Content, Finalize, Fold, NativeElement,
PlainText, Show, Smart, StyleChain, Styles, Synthesize, Value, 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::model::Figurable;
use crate::syntax::{split_newlines, LinkedNode, Spanned}; use crate::syntax::{split_newlines, LinkedNode, Spanned};
use crate::text::{ use crate::text::{
@ -172,8 +172,8 @@ pub struct RawElem {
/// code = "centered" /// code = "centered"
/// ``` /// ```
/// ```` /// ````
#[default(HAlign::Start)] #[default(HAlignment::Start)]
pub align: HAlign, pub align: HAlignment,
/// One or multiple additional syntax definitions to load. The syntax /// One or multiple additional syntax definitions to load. The syntax
/// definitions should be in the /// definitions should be in the