summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
Diffstat (limited to 'library/src')
-rw-r--r--library/src/layout/enum.rs39
1 files changed, 37 insertions, 2 deletions
diff --git a/library/src/layout/enum.rs b/library/src/layout/enum.rs
index a0b23945..0a11a751 100644
--- a/library/src/layout/enum.rs
+++ b/library/src/layout/enum.rs
@@ -147,6 +147,30 @@ pub struct EnumElem {
/// If set to `{auto}`, uses the spacing [below blocks]($func/block.below).
pub spacing: Smart<Spacing>,
+ /// The horizontal alignment that enum numbers should have.
+ ///
+ /// By default, this is set to `{end}`, which aligns enum numbers
+ /// towards end of the current text direction (in left-to-right script,
+ /// for example, this is the same as `{right}`). The choice of `{end}`
+ /// for horizontal alignment of enum numbers is usually preferred over
+ /// `{start}`, as numbers then grow away from the text instead of towards
+ /// it, avoiding certain visual issues. This option lets you override this
+ /// behavior, however.
+ ///
+ /// ````example
+ /// #set enum(number-align: start)
+ ///
+ /// Here are some powers of two:
+ /// 1. One
+ /// 2. Two
+ /// 4. Four
+ /// 8. Eight
+ /// 16. Sixteen
+ /// 32. Thirty two
+ /// ````
+ #[default(HorizontalAlign(GenAlign::End))]
+ pub number_align: HorizontalAlign,
+
/// The numbered list's items.
///
/// When using the enum syntax, adjacent items are automatically collected
@@ -191,6 +215,13 @@ impl Layout for EnumElem {
let mut parents = self.parents(styles);
let full = self.full(styles);
+ // Horizontally align based on the given respective parameter.
+ // Vertically align to the top to avoid inheriting 'horizon' or
+ // 'bottom' alignment from the context and having the number be
+ // displaced in relation to the item it refers to.
+ let number_align: Axes<Option<GenAlign>> =
+ Axes::new(self.number_align(styles).into(), Align::Top.into()).map(Some);
+
for item in self.children() {
number = item.number(styles).unwrap_or(number);
@@ -208,9 +239,13 @@ impl Layout for EnumElem {
}
};
+ // Disable overhang as a workaround to end-aligned dots glitching
+ // and decreasing spacing between numbers and items.
+ let resolved =
+ resolved.aligned(number_align).styled(TextElem::set_overhang(false));
+
cells.push(Content::empty());
- // avoid '#set align' interference with the enum
- cells.push(resolved.aligned(Align::LEFT_TOP.into()));
+ cells.push(resolved);
cells.push(Content::empty());
cells.push(item.body().styled(Self::set_parents(Parent(number))));
number = number.saturating_add(1);