Adjust table inset behavior to the same as container's (#1979) (#2323)

This commit is contained in:
HydroH 2023-10-09 21:52:04 +08:00 committed by GitHub
parent 0804a9e25d
commit 7b61d722dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 3 deletions

View File

@ -114,8 +114,27 @@ pub struct TableElem {
pub stroke: Option<Stroke>,
/// How much to pad the cells' content.
#[default(Abs::pt(5.0).into())]
pub inset: Rel<Length>,
///
/// ```example
/// #table(
/// inset: 10pt,
/// [Hello],
/// [World],
/// )
///
/// #table(
/// columns: 2,
/// inset: (
/// x: 20pt,
/// y: 10pt,
/// ),
/// [Hello],
/// [World],
/// )
/// ```
#[fold]
#[default(Sides::splat(Abs::pt(5.0).into()))]
pub inset: Sides<Option<Rel<Length>>>,
/// The contents of the table cells.
#[variadic]
@ -141,7 +160,7 @@ impl Layout for TableElem {
.into_iter()
.enumerate()
.map(|(i, child)| {
let mut child = child.padded(Sides::splat(inset));
let mut child = child.padded(inset);
let x = i % cols;
let y = i / cols;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -29,6 +29,38 @@
[A], [B], [C]
)
---
// Test inset.
#table(
columns: 3,
inset: 10pt,
[A], [B], [C]
)
#table(
columns: 3,
inset: (y: 10pt),
[A], [B], [C]
)
#table(
columns: 3,
inset: (left: 20pt, rest: 10pt),
[A], [B], [C]
)
#table(
columns: 2,
inset: (
left: 20pt,
right: 5pt,
top: 10pt,
bottom: 3pt,
),
[A],
[B],
)
---
// Ref: false
#table()