diff options
Diffstat (limited to 'library/src/layout')
| -rw-r--r-- | library/src/layout/container.rs | 14 | ||||
| -rw-r--r-- | library/src/layout/enum.rs | 1 | ||||
| -rw-r--r-- | library/src/layout/list.rs | 18 | ||||
| -rw-r--r-- | library/src/layout/page.rs | 17 | ||||
| -rw-r--r-- | library/src/layout/par.rs | 8 | ||||
| -rw-r--r-- | library/src/layout/table.rs | 10 | ||||
| -rw-r--r-- | library/src/layout/transform.rs | 21 |
7 files changed, 52 insertions, 37 deletions
diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index 04c58075..b7d0ba2f 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -229,7 +229,6 @@ pub struct BlockElem { /// Whether the block can be broken and continue on the next page. /// - /// Defaults to `{true}`. /// ```example /// #set page(height: 80pt) /// The following block will @@ -282,13 +281,16 @@ pub struct BlockElem { /// A second paragraph. /// ``` #[external] + #[default(Em::new(1.2).into())] pub spacing: Spacing, /// The spacing between this block and its predecessor. Takes precedence /// over `spacing`. Can be used in combination with a show rule to adjust /// the spacing around arbitrary block-level elements. - /// - /// The default value is `{1.2em}`. + #[external] + #[default(Em::new(1.2).into())] + pub above: Spacing, + #[internal] #[parse( let spacing = args.named("spacing")?; args.named("above")? @@ -300,8 +302,10 @@ pub struct BlockElem { /// The spacing between this block and its successor. Takes precedence /// over `spacing`. - /// - /// The default value is `{1.2em}`. + #[external] + #[default(Em::new(1.2).into())] + pub below: Spacing, + #[internal] #[parse( args.named("below")? .map(VElem::block_around) diff --git a/library/src/layout/enum.rs b/library/src/layout/enum.rs index f7117574..0fd0ebb2 100644 --- a/library/src/layout/enum.rs +++ b/library/src/layout/enum.rs @@ -121,7 +121,6 @@ pub struct EnumElem { /// Whether to display the full numbering, including the numbers of /// all parent enumerations. /// - /// Defaults to `{false}`. /// /// ```example /// #set enum(numbering: "1.a)", full: true) diff --git a/library/src/layout/list.rs b/library/src/layout/list.rs index 75fc7c3a..1e42d51b 100644 --- a/library/src/layout/list.rs +++ b/library/src/layout/list.rs @@ -66,8 +66,6 @@ pub struct ListElem { /// control, you may pass a function that maps the list's nesting depth /// (starting from `{0}`) to a desired marker. /// - /// Default: `•` - /// /// ```example /// #set list(marker: [--]) /// - A more classic list @@ -79,7 +77,7 @@ pub struct ListElem { /// - Items /// - Items /// ``` - #[default(ListMarker::Content(vec![]))] + #[default(ListMarker::Content(vec![TextElem::packed('•')]))] pub marker: ListMarker, /// The indent of each item. @@ -192,11 +190,9 @@ impl ListMarker { /// Resolve the marker for the given depth. fn resolve(&self, vt: &mut Vt, depth: usize) -> SourceResult<Content> { Ok(match self { - Self::Content(list) => list - .get(depth) - .or(list.last()) - .cloned() - .unwrap_or_else(|| TextElem::packed('•')), + Self::Content(list) => { + list.get(depth).or(list.last()).cloned().unwrap_or_default() + } Self::Func(func) => func.call_vt(vt, [Value::Int(depth as i64)])?.display(), }) } @@ -216,7 +212,11 @@ cast_from_value! { cast_to_value! { v: ListMarker => match v { - ListMarker::Content(vec) => vec.into(), + ListMarker::Content(vec) => if vec.len() == 1 { + vec.into_iter().next().unwrap().into() + } else { + vec.into() + }, ListMarker::Func(func) => func.into(), } } diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs index cb0ed7dc..cfddc446 100644 --- a/library/src/layout/page.rs +++ b/library/src/layout/page.rs @@ -26,9 +26,9 @@ use crate::prelude::*; /// Category: layout #[element] pub struct PageElem { - /// A standard paper size to set width and height. When this is not - /// specified, Typst defaults to `{"a4"}` paper. + /// A standard paper size to set width and height. #[external] + #[default(Paper::A4)] pub paper: Paper, /// The width of the page. @@ -470,6 +470,8 @@ cast_to_value! { /// Specification of a paper. #[derive(Debug, Copy, Clone, Hash)] pub struct Paper { + /// The name of the paper. + name: &'static str, /// The width of the paper in millimeters. width: Scalar, /// The height of the paper in millimeters. @@ -490,12 +492,13 @@ impl Paper { /// Defines paper constants and a paper parsing implementation. macro_rules! papers { - ($(($var:ident: $width:expr, $height: expr, $pat:literal))*) => { + ($(($var:ident: $width:expr, $height: expr, $name:literal))*) => { /// Predefined papers. /// /// Each paper is parsable from its name in kebab-case. impl Paper { $(pub const $var: Self = Self { + name: $name, width: Scalar($width), height: Scalar($height), };)* @@ -506,7 +509,7 @@ macro_rules! papers { fn from_str(name: &str) -> Result<Self, Self::Err> { match name.to_lowercase().as_str() { - $($pat => Ok(Self::$var),)* + $($name => Ok(Self::$var),)* _ => Err("unknown paper size"), } } @@ -516,9 +519,13 @@ macro_rules! papers { Paper, $( /// Produces a paper of the respective size. - $pat => Self::$var, + $name => Self::$var, )* } + + cast_to_value! { + v: Paper => v.name.into() + } }; } diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index f8df63f4..f0dcbb11 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -20,8 +20,11 @@ use crate::text::{ /// /// ## Example { #example } /// ```example -/// #set par(first-line-indent: 1em, justify: true) /// #show par: set block(spacing: 0.65em) +/// #set par( +/// first-line-indent: 1em, +/// justify: true, +/// ) /// /// We proceed by contradiction. /// Suppose that there exists a set @@ -40,8 +43,6 @@ use crate::text::{ #[element(Construct)] pub struct ParElem { /// The spacing between lines. - /// - /// The default value is `{0.65em}`. #[resolve] #[default(Em::new(0.65).into())] pub leading: Length, @@ -102,6 +103,7 @@ pub struct ParElem { /// The contents of the paragraph. #[external] + #[required] pub body: Content, /// The paragraph's children. diff --git a/library/src/layout/table.rs b/library/src/layout/table.rs index bb24bd7c..fb4e4a3b 100644 --- a/library/src/layout/table.rs +++ b/library/src/layout/table.rs @@ -104,16 +104,18 @@ pub struct TableElem { /// How to stroke the cells. /// - /// This can be a color, a stroke width, both, or `{none}` to disable - /// the stroke. + /// See the [line's documentation]($func/line.stroke) for more details. + /// Strokes can be disabled by setting this to `{none}`. + /// + /// _Note:_ Richer stroke customization for individual cells is not yet + /// implemented, but will be in the future. In the meantime, you can use + /// the third-party [tablex library](https://github.com/PgBiel/typst-tablex/). #[resolve] #[fold] #[default(Some(PartialStroke::default()))] pub stroke: Option<PartialStroke>, /// How much to pad the cells's content. - /// - /// The default value is `{5pt}`. #[default(Abs::pt(5.0).into())] pub inset: Rel<Length>, diff --git a/library/src/layout/transform.rs b/library/src/layout/transform.rs index e3622ac5..f1f1e94a 100644 --- a/library/src/layout/transform.rs +++ b/library/src/layout/transform.rs @@ -83,10 +83,9 @@ pub struct RotateElem { /// The origin of the rotation. /// - /// By default, the origin is the center of the rotated element. If, - /// however, you wanted the bottom left corner of the rotated element to - /// stay aligned with the baseline, you would set the origin to `bottom + - /// left`. + /// If, for instance, you wanted the bottom left corner of the rotated + /// element to stay aligned with the baseline, you would set it to `bottom + + /// left` instead. /// /// ```example /// #set text(spacing: 8pt) @@ -98,6 +97,8 @@ pub struct RotateElem { /// #box(rotate(30deg, origin: bottom + right, square())) /// ``` #[resolve] + #[fold] + #[default(Align::CENTER_HORIZON)] pub origin: Axes<Option<GenAlign>>, /// The content to rotate. @@ -115,8 +116,8 @@ impl Layout for RotateElem { ) -> SourceResult<Fragment> { let pod = Regions::one(regions.base(), Axes::splat(false)); let mut frame = self.body().layout(vt, styles, pod)?.into_frame(); - let origin = self.origin(styles).unwrap_or(Align::CENTER_HORIZON); - let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); + let Axes { x, y } = + self.origin(styles).zip(frame.size()).map(|(o, s)| o.position(s)); let ts = Transform::translate(x, y) .pre_concat(Transform::rotate(self.angle(styles))) .pre_concat(Transform::translate(-x, -y)); @@ -160,13 +161,13 @@ pub struct ScaleElem { /// The origin of the transformation. /// - /// By default, the origin is the center of the scaled element. - /// /// ```example /// A#box(scale(75%)[A])A \ /// B#box(scale(75%, origin: bottom + left)[B])B /// ``` #[resolve] + #[fold] + #[default(Align::CENTER_HORIZON)] pub origin: Axes<Option<GenAlign>>, /// The content to scale. @@ -184,8 +185,8 @@ impl Layout for ScaleElem { ) -> SourceResult<Fragment> { let pod = Regions::one(regions.base(), Axes::splat(false)); let mut frame = self.body().layout(vt, styles, pod)?.into_frame(); - let origin = self.origin(styles).unwrap_or(Align::CENTER_HORIZON); - let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); + let Axes { x, y } = + self.origin(styles).zip(frame.size()).map(|(o, s)| o.position(s)); let transform = Transform::translate(x, y) .pre_concat(Transform::scale(self.x(styles), self.y(styles))) .pre_concat(Transform::translate(-x, -y)); |
