diff --git a/CHANGELOG.md b/CHANGELOG.md index 854fdad..3a4fb8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed +- A screen reader hears one row of a fixed-width table as one line. `BlockLayout.Relayout` with + `LayoutContext.Linear` now wraps a block that is not fluid at the reader's width, as it does a fluid one; + before, it wrapped at the width the block's columns took, so a 35-cell WHO listing broke each player's row in two. The same holds for one nested in another block (`Bounded`). - Two equal elements side by side stay two. Before, an element closed and an equal one opened straight after it became one run, so a client saw one thing where the server sent two. This happened with two exits of one flagged element (`northsouth` read as one exit, `northsouth`), two ``s, ``s diff --git a/MarkupString.Tests/Layout/BlockLayoutTests.cs b/MarkupString.Tests/Layout/BlockLayoutTests.cs index 2d7cca5..76d14bf 100644 --- a/MarkupString.Tests/Layout/BlockLayoutTests.cs +++ b/MarkupString.Tests/Layout/BlockLayoutTests.cs @@ -210,6 +210,33 @@ await Assert.That(string.Join("\n", lines.Select(l => l.ToPlainText()))).IsEqual "Origin: Super Robot Wars AG\nOnline: 1h, Idle: 0s\nFactions\nMEDJAI, Court of Stardust\nQuote\nHooooo?"); } + [Test] + public async Task Linear_ReadsAFixedWidthTableRowAsOneLineAtTheReadersWidth() + { + // A WHO listing is laid out at its own width (not fluid); read aloud, its one row is one line. + var table = new Table([new TableColumn(P("Player Name")) { Min = 16 }, new TableColumn(P("On For")) { Min = 10, Alignment = Alignment.Right }, new TableColumn(P("Idle ")) { Min = 7, Alignment = Alignment.Right }], + [[P("Marguerite"), P("7s"), P("0s")]]) + { Gap = 1 }; + var text = BlockLayout.Build(table, 35); + + var read = BlockLayout.Relayout(text, 78, new LayoutContext { Linear = true }); + + await Assert.That(read.ToPlainText()).IsEqualTo("Player Name: Marguerite, On For: 7s, Idle: 0s"); + } + + [Test] + public async Task Linear_ReadsANestedFixedWidthTableRowAsOneLine() + { + // The same listing nested in a fluid block keeps its own width (Bounded); read aloud, it still reads as one line. + var table = new Table([new TableColumn(P("Player Name")) { Min = 16 }, new TableColumn(P("On For")) { Min = 10, Alignment = Alignment.Right }], + [[P("Marguerite"), P("7s")]]); + var text = BlockLayout.Build(new Bounded(table, 20), 78, fluid: true); + + var read = BlockLayout.Relayout(text, 78, new LayoutContext { Linear = true }); + + await Assert.That(read.ToPlainText()).IsEqualTo("Player Name: Marguerite, On For: 7s"); + } + [Test] public async Task Flex_StacksWhenItemsDoNotFit() { diff --git a/MarkupString/Layout/Blocks/BlockLayout.cs b/MarkupString/Layout/Blocks/BlockLayout.cs index 94508b2..a55bf34 100644 --- a/MarkupString/Layout/Blocks/BlockLayout.cs +++ b/MarkupString/Layout/Blocks/BlockLayout.cs @@ -105,7 +105,8 @@ private static void AddText(MarkupText content, int start, int end, Alignment? a /// /// with every intact block laid out again under : - /// a block at , any other at its own width. + /// a block at , and any block read in order + /// () too; any other at its own width. /// A block that was cut, edited or shares a line with other text is left as it is. /// /// The text. @@ -120,7 +121,9 @@ public static MarkupText Relayout(MarkupText text, int width, LayoutContext cont foreach (var region in BlockRegions.Find(text)) { if (region.Markup is not LayoutMarkup layout || !region.Intact || !region.Standalone) continue; - var target = layout.Fluid && width > 0 ? width : layout.Width; + // A screen reader hears a fixed-width block in reading order, so its lines wrap at the reader's + // width, not at the width its columns took: one row of a table stays one line. + var target = (layout.Fluid || context.Linear) && width > 0 ? width : layout.Width; if (target == layout.Width && context == LayoutContext.Default) continue; edits.Add((region.Start, region.End - region.Start, Build(layout.Root, target, layout.Fluid, context))); } diff --git a/MarkupString/Layout/Blocks/Modifiers.cs b/MarkupString/Layout/Blocks/Modifiers.cs index e20375f..c57b169 100644 --- a/MarkupString/Layout/Blocks/Modifiers.cs +++ b/MarkupString/Layout/Blocks/Modifiers.cs @@ -119,6 +119,11 @@ public override Block MapText(Func map) => public override void Draw(LayoutContext context, int width, IList lines) => context.Draw(Content, Math.Min(width, Math.Max(1, Width)), lines); + /// + /// Read in order, its content wraps at the reader's width: the bound keeps columns, which a reader does not hear. + public override void DrawLinear(LayoutContext context, int width, IList lines) => + context.Draw(Content, width, lines); + /// public override BlockMeasure Measure(LayoutContext context, int width) { diff --git a/MarkupString/PublicAPI.Unshipped.txt b/MarkupString/PublicAPI.Unshipped.txt index 4c6629a..54795e9 100644 --- a/MarkupString/PublicAPI.Unshipped.txt +++ b/MarkupString/PublicAPI.Unshipped.txt @@ -877,3 +877,4 @@ override MarkupString.ElementMarkup.GetHashCode() -> int override MarkupString.ElementMarkup.ToString() -> string! static MarkupString.ElementMarkup.operator !=(MarkupString.ElementMarkup? left, MarkupString.ElementMarkup? right) -> bool static MarkupString.ElementMarkup.operator ==(MarkupString.ElementMarkup? left, MarkupString.ElementMarkup? right) -> bool +override MarkupString.Layout.Bounded.DrawLinear(MarkupString.Layout.LayoutContext! context, int width, System.Collections.Generic.IList! lines) -> void