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
14 changes: 12 additions & 2 deletions src/Spectre.Console/Internal/Ratio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ public static List<int> Resolve(int total, IEnumerable<IRatioResolvable> edges)
{
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)
Expand All @@ -22,7 +32,7 @@ public static List<int> Resolve(int total, IEnumerable<IRatioResolvable> edges)
return edge.Size;
}

var sizes = edges.Select(x => GetEdgeWidth(x)).ToArray();
var sizes = edges.Select(GetEdgeWidth).ToArray();

while (sizes.Any(s => s == null))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘
29 changes: 29 additions & 0 deletions src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,35 @@ public Task Should_Render_Layout_With_Nested_Rows_And_Columns()
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()
Expand Down