Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ 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.24.0 — Unreleased

### Changed

- **A `Table` read linearly is one line per row**: its labelled values, comma-separated
(`Player Name: Dave, On For: 4s`), where it was one line per cell. A cell with nothing in it is left
out with its label, so a screen reader no longer reads a bare `Doing:`. A column with no heading reads
its value alone. A table too narrow for its columns still draws its rows as cards.

## 2.23.0 — Unreleased

### Added
Expand Down
19 changes: 18 additions & 1 deletion MarkupString.Tests/Layout/FieldsAndTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,24 @@ public async Task Table_Linear_LabelsEachCellWithoutTheHeadingsPadding()
[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" });
await Assert.That(Lines(table, 40, new LayoutContext { Linear = true })).IsEquivalentTo(new[] { "Player: Mannaz, Idle: 59s" });
}

[Test]
public async Task Table_Linear_ReadsEachRowAsOneLine_LeavingEmptyCellsOut()
{
var table = new Table(
[new TableColumn(P("Player Name")), new TableColumn(P("On For")), new TableColumn(P("Doing")), new TableColumn(P(""))],
[
[new TextBlock(P("Dave")), new TextBlock(P("4s")), new TextBlock(P("")), new TextBlock(P("[To do]"))],
[new TextBlock(P("Bob")), new TextBlock(P("1m")), new TextBlock(P("Exploring"))],
]);

await Assert.That(Lines(table, 60, new LayoutContext { Linear = true })).IsEquivalentTo(new[]
{
"Player Name: Dave, On For: 4s, [To do]",
"Player Name: Bob, On For: 1m, Doing: Exploring",
});
Comment thread
HarryCordewener marked this conversation as resolved.
}

private static Tree Channels(TreeGuide guide) => new(
Expand Down
19 changes: 17 additions & 2 deletions MarkupString/Layout/Blocks/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,25 @@ public override void Draw(LayoutContext context, int width, IList<MarkupText> li
}
}

/// <inheritdoc/>
/// <summary>
/// Each row as one line of labelled values, comma-separated, so a screen reader hears a row where the eye
/// sees one. A cell with nothing in it is left out with its label: a reader saying "Doing:" says nothing.
/// A column with no heading reads its value alone.
/// </summary>
public override void DrawLinear(LayoutContext context, int width, IList<MarkupText> lines)
{
if (!Columns.IsDefaultOrEmpty) DrawCards(context, width, lines);
if (Columns.IsDefaultOrEmpty) return;
var values = context with { TextAlignment = Alignment.Left };
Comment thread
coderabbitai[bot] marked this conversation as resolved.
foreach (var row in AllRows)
{
var parts = Enumerable.Range(0, Columns.Length)
.Select(c => (Label: Columns[c].Header.Trim(TrimType.TrimBoth), Value: MarkupText.Join(MarkupText.Plain(" "), values.Lines(Cell(row, c), int.MaxValue / 2).Select(line => line.Trim(TrimType.TrimBoth)))))
.Where(part => part.Value.ToPlainText().Trim().Length > 0)
.Select(part => part.Label.Length == 0 ? part.Value : MarkupText.Concat([part.Label, MarkupText.Plain(": "), part.Value]));
var line = MarkupText.Join(MarkupText.Plain(", "), parts);
if (line.Length == 0) continue;
foreach (var wrapped in values.Lines(new TextBlock(line), width)) lines.Add(wrapped);
}
}

/// <summary>Each row as a card of labelled values, the way a phone shows a table too wide for it.</summary>
Expand Down
Loading