Skip to content

Commit

Permalink
Merge pull request #1514 from BlazeFace/blz/issues/1390
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksvensson authored Oct 30, 2024
2 parents a32dc80 + 3eb620a commit fdc03f2
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 2 deletions.
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

0 comments on commit fdc03f2

Please sign in to comment.