summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/layout
diff options
context:
space:
mode:
authorPg Biel <9021226+PgBiel@users.noreply.github.com>2023-07-11 11:11:18 -0300
committerGitHub <noreply@github.com>2023-07-11 16:11:18 +0200
commit9b1a2b41f0bb2d62106e029a5a0174dcf07ae0d2 (patch)
tree6f0ae44b3dfffd1c5b3e44535716d382ffc41c46 /crates/typst-library/src/layout
parent507efc3a1c14e8487705c7424d605a1663d3fe6e (diff)
Add fields and methods to several primitives (#790)
Diffstat (limited to 'crates/typst-library/src/layout')
-rw-r--r--crates/typst-library/src/layout/align.rs13
-rw-r--r--crates/typst-library/src/layout/stack.rs9
2 files changed, 22 insertions, 0 deletions
diff --git a/crates/typst-library/src/layout/align.rs b/crates/typst-library/src/layout/align.rs
index bbfe9f7e..fecc7e33 100644
--- a/crates/typst-library/src/layout/align.rs
+++ b/crates/typst-library/src/layout/align.rs
@@ -33,10 +33,23 @@ pub struct AlignElem {
/// - `horizon`
/// - `bottom`
///
+ /// You may use the `axis` method on a single-axis alignment to obtain
+ /// whether it is `{"horizontal"}` or `{"vertical"}`. You may also use the
+ /// `inv` method to obtain its inverse alignment. For example,
+ /// `{top.axis()}` is `{"vertical"}`, while `{top.inv()}` is equal to
+ /// `{bottom}`.
+ ///
/// To align along both axes at the same time, add the two alignments using
/// the `+` operator to get a `2d alignment`. For example, `top + right`
/// aligns the content to the top right corner.
///
+ /// For 2d alignments, you may use the `x` and `y` fields to access their
+ /// horizontal and vertical components, respectively. Additionally, you may
+ /// use the `inv` method to obtain a 2d alignment with both components
+ /// inverted. For instance, `{(top + right).x}` is `right`,
+ /// `{(top + right).y}` is `top`, and `{(top + right).inv()}` is equal to
+ /// `bottom + left`.
+ ///
/// ```example
/// #set page(height: 6cm)
/// #set text(lang: "ar")
diff --git a/crates/typst-library/src/layout/stack.rs b/crates/typst-library/src/layout/stack.rs
index 97305ddf..8d536638 100644
--- a/crates/typst-library/src/layout/stack.rs
+++ b/crates/typst-library/src/layout/stack.rs
@@ -26,6 +26,15 @@ pub struct StackElem {
/// - `{rtl}`: Right to left.
/// - `{ttb}`: Top to bottom.
/// - `{btt}`: Bottom to top.
+ ///
+ /// You may use the `start` and `end` methods to obtain the initial and
+ /// final points (respectively) of a direction, as `alignment`. You may
+ /// also use the `axis` method to obtain whether a direction is
+ /// `{"horizontal"}` or `{"vertical"}`. Finally, the `inv` method returns
+ /// its inverse direction.
+ ///
+ /// For example, `{ttb.start()}` is `top`, `{ttb.end()}` is `bottom`,
+ /// `{ttb.axis()}` is `{"vertical"}` and `{ttb.inv()}` is equal to `btt`.
#[default(Dir::TTB)]
pub dir: Dir,