Default enum number alignment to 'end' (#1042)
@ -147,6 +147,30 @@ pub struct EnumElem {
|
|||||||
/// If set to `{auto}`, uses the spacing [below blocks]($func/block.below).
|
/// If set to `{auto}`, uses the spacing [below blocks]($func/block.below).
|
||||||
pub spacing: Smart<Spacing>,
|
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.
|
/// The numbered list's items.
|
||||||
///
|
///
|
||||||
/// When using the enum syntax, adjacent items are automatically collected
|
/// 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 mut parents = self.parents(styles);
|
||||||
let full = self.full(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() {
|
for item in self.children() {
|
||||||
number = item.number(styles).unwrap_or(number);
|
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());
|
cells.push(Content::empty());
|
||||||
// avoid '#set align' interference with the enum
|
cells.push(resolved);
|
||||||
cells.push(resolved.aligned(Align::LEFT_TOP.into()));
|
|
||||||
cells.push(Content::empty());
|
cells.push(Content::empty());
|
||||||
cells.push(item.body().styled(Self::set_parents(Parent(number))));
|
cells.push(item.body().styled(Self::set_parents(Parent(number))));
|
||||||
number = number.saturating_add(1);
|
number = number.saturating_add(1);
|
||||||
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.1 KiB |
BIN
tests/ref/layout/enum-align.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 14 KiB |
41
tests/typ/layout/enum-align.typ
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Test the alignment of enum numbers.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Alignment shouldn't affect number
|
||||||
|
#set align(horizon)
|
||||||
|
|
||||||
|
+ ABCDEF\ GHIJKL\ MNOPQR
|
||||||
|
+ INNER\ INNER\ INNER
|
||||||
|
+ BACK\ HERE
|
||||||
|
|
||||||
|
---
|
||||||
|
// Enum number alignment should be 'end' by default
|
||||||
|
1. a
|
||||||
|
10. b
|
||||||
|
100. c
|
||||||
|
|
||||||
|
#set enum(number-align: start)
|
||||||
|
1. a
|
||||||
|
8. b
|
||||||
|
16. c
|
||||||
|
|
||||||
|
---
|
||||||
|
// Number align option should not be affected by the context
|
||||||
|
#set align(center)
|
||||||
|
#set enum(number-align: start)
|
||||||
|
|
||||||
|
4. c
|
||||||
|
8. d
|
||||||
|
16. e\ f
|
||||||
|
2. f\ g
|
||||||
|
32. g
|
||||||
|
64. h
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test valid number align values (horizontal)
|
||||||
|
#set enum(number-align: start)
|
||||||
|
#set enum(number-align: end)
|
||||||
|
#set enum(number-align: left)
|
||||||
|
#set enum(number-align: right)
|
||||||
|
// Error: 25-28 alignment must be horizontal
|
||||||
|
#set enum(number-align: top)
|
@ -46,11 +46,3 @@ a + 0.
|
|||||||
[Second],
|
[Second],
|
||||||
enum.item(5)[Fifth]
|
enum.item(5)[Fifth]
|
||||||
)
|
)
|
||||||
|
|
||||||
---
|
|
||||||
// Alignment shouldn't affect number
|
|
||||||
#set align(horizon)
|
|
||||||
|
|
||||||
+ ABCDEF\ GHIJKL\ MNOPQR
|
|
||||||
+ INNER\ INNER\ INNER
|
|
||||||
+ BACK\ HERE
|
|
||||||
|