diff --git a/src/Spectre.Console/Internal/Ratio.cs b/src/Spectre.Console/Internal/Ratio.cs index fb38bdd..4ef5504 100644 --- a/src/Spectre.Console/Internal/Ratio.cs +++ b/src/Spectre.Console/Internal/Ratio.cs @@ -9,7 +9,17 @@ internal static class Ratio { static (int Div, float Mod) DivMod(float x, float y) { - return ((int)(x / y), x % y); + var (div, mod) = ((int)(x / y), x % y); + + // If remainder is within .0001 of 1 then we round up + if (!(mod > 0.9999)) + { + return (div, mod); + } + + div++; + mod = 0; + return (div, mod); } static int? GetEdgeWidth(IRatioResolvable edge) @@ -22,7 +32,7 @@ internal static class Ratio return edge.Size; } - var sizes = edges.Select(x => GetEdgeWidth(x)).ToArray(); + var sizes = edges.Select(GetEdgeWidth).ToArray(); while (sizes.Any(s => s == null)) { diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_17.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_17.verified.txt new file mode 100644 index 0000000..1a64de7 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_17.verified.txt @@ -0,0 +1,17 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_20.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_20.verified.txt new file mode 100644 index 0000000..4c6a7c9 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_20.verified.txt @@ -0,0 +1,20 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_23.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_23.verified.txt new file mode 100644 index 0000000..d6e7471 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_23.verified.txt @@ -0,0 +1,23 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_28.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_28.verified.txt new file mode 100644 index 0000000..f34e9d7 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_28.verified.txt @@ -0,0 +1,28 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_30.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_30.verified.txt new file mode 100644 index 0000000..be6f4b5 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_30.verified.txt @@ -0,0 +1,31 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_31.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_31.verified.txt new file mode 100644 index 0000000..be6f4b5 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_31.verified.txt @@ -0,0 +1,31 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs b/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs index 550922a..54182e1 100644 --- a/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs +++ b/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs @@ -153,6 +153,35 @@ public sealed class LayoutTests return Verifier.Verify(console.Output); } + [Theory] + [InlineData(17, "17")] + [InlineData(20, "20")] + [InlineData(23, "23")] + [InlineData(28, "28")] + [InlineData(31, "31")] + [Expectation("Render_Layout_With_Nested_Three_Rows_In_One_Column")] + public Task Should_Render_Layout_With_Three_And_One_Columns(int height, string expectationPrefix) + { + // Given + var console = new TestConsole().Size(new Size(40, height)); + + // Layout with 2 columns, left column has 3 rows and right column has 1 row + var layout = new Layout(new Panel("Hello, World!") { Expand = true }) + .SplitColumns( + new Layout(new Panel("Hello, World!") { Expand = true }) + .SplitRows( + new Layout(new Panel("Hello, World!") { Expand = true }), + new Layout(new Panel("Hello, World!") { Expand = true }), + new Layout(new Panel("Hello, World!") { Expand = true })), + new Layout(new Panel("Hello, World!") { Expand = true })); + + // When + console.Write(layout); + + // Then + return Verifier.Verify(console.Output).UseTextForParameters(expectationPrefix); + } + [Fact] [Expectation("Render_Layout_Without_Invisible_Children")] public Task Should_Render_Layout_Without_Invisible_Children()