diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b8b511..521abb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and `MarkupString.Pueblo`. The packages share one version and are released toget The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.22.1 — Unreleased + +### Fixed + +- A `Table` read as cards (linear, or too narrow for its columns) trims the spaces around each heading + before using it as a label, so a heading padded for its column, such as `"Idle "`, reads `Idle: 59s` + instead of `Idle : 59s`. + ## 2.22.0 — Unreleased ### Added diff --git a/MarkupString.Tests/Layout/FieldsAndTreeTests.cs b/MarkupString.Tests/Layout/FieldsAndTreeTests.cs index 271361e..b8e8b85 100644 --- a/MarkupString.Tests/Layout/FieldsAndTreeTests.cs +++ b/MarkupString.Tests/Layout/FieldsAndTreeTests.cs @@ -94,6 +94,16 @@ public async Task Fields_Linear_ReadLabelThenValue() => await Assert.That(Lines(Sheet(Character[..2]) with { Columns = 2 }, 40, new LayoutContext { Linear = true })) .IsEquivalentTo(new[] { "Sex: Male", "Species: Human" }); + [Test] + public async Task Table_Linear_LabelsEachCellWithoutTheHeadingsPadding() + { + var table = new Table( + [new TableColumn(P("Player")), new TableColumn(P("Idle ")) { Alignment = Alignment.Right }], + [[new TextBlock(P("Mannaz")), new TextBlock(P("59s"))]]); + + await Assert.That(Lines(table, 40, new LayoutContext { Linear = true })).IsEquivalentTo(new[] { "Player: Mannaz", "Idle: 59s" }); + } + private static Tree Channels(TreeGuide guide) => new( [ new TreeItem(P("Channels"), diff --git a/MarkupString/Layout/Blocks/Table.cs b/MarkupString/Layout/Blocks/Table.cs index e3e333e..ad009b8 100644 --- a/MarkupString/Layout/Blocks/Table.cs +++ b/MarkupString/Layout/Blocks/Table.cs @@ -98,7 +98,8 @@ private void DrawCards(LayoutContext context, int width, IList lines { if (r > 0 && !context.Linear) lines.Add(MarkupText.Empty); var row = rows[r]; - cards.Draw(new Fields([.. Enumerable.Range(0, Columns.Length).Select(c => new Field(Columns[c].Header, Cell(row, c)))]), width, lines); + // A header's outer spaces line its column up with the next; as a label they would sit before the colon. + cards.Draw(new Fields([.. Enumerable.Range(0, Columns.Length).Select(c => new Field(Columns[c].Header.Trim(TrimType.TrimBoth), Cell(row, c)))]), width, lines); } }