summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHydroH <iodizon@163.com>2023-10-09 21:52:04 +0800
committerGitHub <noreply@github.com>2023-10-09 15:52:04 +0200
commit7b61d722ddcd609e7bb51a454b27dd883f620357 (patch)
treeb46b7b84116af0517d1a3b41c3a837f534fd795f
parent0804a9e25d865dc25d10aae22b0a39c4e16cab19 (diff)
Adjust table inset behavior to the same as container's (#1979) (#2323)
-rw-r--r--crates/typst-library/src/layout/table.rs25
-rw-r--r--tests/ref/layout/table.pngbin7530 -> 12226 bytes
-rw-r--r--tests/typ/layout/table.typ32
3 files changed, 54 insertions, 3 deletions
diff --git a/crates/typst-library/src/layout/table.rs b/crates/typst-library/src/layout/table.rs
index 1b84a616..056b63a2 100644
--- a/crates/typst-library/src/layout/table.rs
+++ b/crates/typst-library/src/layout/table.rs
@@ -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;
diff --git a/tests/ref/layout/table.png b/tests/ref/layout/table.png
index 5c8dbf0e..fe4554d9 100644
--- a/tests/ref/layout/table.png
+++ b/tests/ref/layout/table.png
Binary files differ
diff --git a/tests/typ/layout/table.typ b/tests/typ/layout/table.typ
index d91c3fa7..5ddc8503 100644
--- a/tests/typ/layout/table.typ
+++ b/tests/typ/layout/table.typ
@@ -30,6 +30,38 @@
)
---
+// 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()