mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Rename Align
to Alignment
This commit is contained in:
parent
bc2a4f802c
commit
c298cf61f2
@ -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<Value> {
|
||||
mismatch!("cannot apply unary '+' to {}", value)
|
||||
}
|
||||
Dyn(d) => {
|
||||
if d.is::<Align>() {
|
||||
if d.is::<Alignment>() {
|
||||
mismatch!("cannot apply unary '+' to {}", d)
|
||||
} else {
|
||||
mismatch!("cannot apply '+' to {}", d)
|
||||
@ -238,7 +238,9 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
|
||||
|
||||
(Dyn(a), Dyn(b)) => {
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
@ -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<Value> {
|
||||
}
|
||||
_ => return missing(),
|
||||
}
|
||||
} else if let Some(align) = dynamic.downcast::<Align>() {
|
||||
} else if let Some(align) = dynamic.downcast::<Alignment>() {
|
||||
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::<Stroke>() {
|
||||
&["paint", "thickness", "cap", "join", "dash", "miter-limit"]
|
||||
} else if ty == Type::of::<Align>() {
|
||||
} else if ty == Type::of::<Alignment>() {
|
||||
&["x", "y"]
|
||||
} else {
|
||||
&[]
|
||||
|
@ -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`"),
|
||||
},
|
||||
}
|
||||
|
@ -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<HAlign> {
|
||||
pub const fn x(self) -> Option<HAlignment> {
|
||||
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<VAlign> {
|
||||
pub const fn y(self) -> Option<VAlignment> {
|
||||
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<Self>;
|
||||
|
||||
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<FixedAlign>;
|
||||
|
||||
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 {
|
||||
match side {
|
||||
Side::Left => Self::LEFT,
|
||||
@ -246,12 +246,12 @@ impl From<Side> 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<VAlign> for HAlign {
|
||||
type Output = Align;
|
||||
impl Add<VAlignment> 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<HAlign> for Align {
|
||||
fn from(align: HAlign) -> Self {
|
||||
impl From<HAlignment> 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<HAlign> for VAlign {
|
||||
type Output = Align;
|
||||
impl Add<HAlignment> 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<VAlign> for Align {
|
||||
fn from(align: VAlign) -> Self {
|
||||
impl From<VAlignment> 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()),
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<Paint>,
|
||||
align: Smart<Align>,
|
||||
align: Smart<Alignment>,
|
||||
inset: Sides<Rel<Length>>,
|
||||
styles: StyleChain,
|
||||
) -> Cell;
|
||||
@ -212,7 +212,7 @@ impl CellGrid {
|
||||
gutter: Axes<&[Sizing]>,
|
||||
cells: &[T],
|
||||
fill: &Celled<Option<Paint>>,
|
||||
align: &Celled<Smart<Align>>,
|
||||
align: &Celled<Smart<Alignment>>,
|
||||
inset: Sides<Rel<Length>>,
|
||||
engine: &mut Engine,
|
||||
styles: StyleChain,
|
||||
|
@ -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<Smart<Align>>,
|
||||
pub align: Celled<Smart<Alignment>>,
|
||||
|
||||
/// How to [stroke]($stroke) the cells.
|
||||
///
|
||||
@ -299,7 +300,7 @@ pub struct GridCell {
|
||||
fill: Smart<Option<Paint>>,
|
||||
|
||||
/// The cell's alignment override.
|
||||
align: Smart<Align>,
|
||||
align: Smart<Alignment>,
|
||||
|
||||
/// The cell's inset override.
|
||||
inset: Smart<Sides<Option<Rel<Length>>>>,
|
||||
@ -322,7 +323,7 @@ impl ResolvableCell for GridCell {
|
||||
_: usize,
|
||||
_: usize,
|
||||
fill: &Option<Paint>,
|
||||
align: Smart<Align>,
|
||||
align: Smart<Alignment>,
|
||||
inset: Sides<Rel<Length>>,
|
||||
styles: StyleChain,
|
||||
) -> Cell {
|
||||
@ -364,7 +365,7 @@ impl From<Content> for GridCell {
|
||||
pub fn show_grid_cell(
|
||||
mut body: Content,
|
||||
inset: Smart<Sides<Option<Rel<Length>>>>,
|
||||
align: Smart<Align>,
|
||||
align: Smart<Alignment>,
|
||||
) -> SourceResult<Content> {
|
||||
let inset = inset.unwrap_or_default().map(Option::unwrap_or_default);
|
||||
|
||||
|
@ -95,7 +95,7 @@ pub fn define(global: &mut Scope) {
|
||||
global.define_type::<Rel<Length>>();
|
||||
global.define_type::<Fr>();
|
||||
global.define_type::<Dir>();
|
||||
global.define_type::<Align>();
|
||||
global.define_type::<Alignment>();
|
||||
global.define_elem::<PageElem>();
|
||||
global.define_elem::<PagebreakElem>();
|
||||
global.define_elem::<VElem>();
|
||||
|
@ -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<Spanned<Align>> = args.named("number-align")?;
|
||||
let option: Option<Spanned<Alignment>> = 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`"),
|
||||
},
|
||||
}
|
||||
|
@ -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<Align>,
|
||||
#[default(Smart::Custom(Alignment::START))]
|
||||
pub alignment: Smart<Alignment>,
|
||||
|
||||
/// 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();
|
||||
|
@ -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"),
|
||||
},
|
||||
}
|
||||
|
@ -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.
|
||||
///
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)))
|
||||
|
@ -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.
|
||||
///
|
||||
|
@ -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<Smart<VAlign>>,
|
||||
pub placement: Option<Smart<VAlignment>>,
|
||||
|
||||
/// The figure's caption.
|
||||
pub caption: Option<FigureCaption>,
|
||||
@ -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<Spanned<VAlign>> = args.named("position")?;
|
||||
let option: Option<Spanned<VAlignment>> = 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.
|
||||
///
|
||||
|
@ -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() {
|
||||
|
@ -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();
|
||||
|
@ -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<Smart<Align>>,
|
||||
pub align: Celled<Smart<Alignment>>,
|
||||
|
||||
/// How to [stroke]($stroke) the cells.
|
||||
///
|
||||
@ -268,7 +268,7 @@ pub struct TableCell {
|
||||
fill: Smart<Option<Paint>>,
|
||||
|
||||
/// The cell's alignment override.
|
||||
align: Smart<Align>,
|
||||
align: Smart<Alignment>,
|
||||
|
||||
/// The cell's inset override.
|
||||
inset: Smart<Sides<Option<Rel<Length>>>>,
|
||||
@ -291,7 +291,7 @@ impl ResolvableCell for TableCell {
|
||||
_: usize,
|
||||
_: usize,
|
||||
fill: &Option<Paint>,
|
||||
align: Smart<Align>,
|
||||
align: Smart<Alignment>,
|
||||
inset: Sides<Rel<Length>>,
|
||||
styles: StyleChain,
|
||||
) -> Cell {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user