Merge pull request #1514 from BlazeFace/blz/issues/1390

This commit is contained in:
Patrik Svensson 2024-10-30 01:36:05 +01:00 committed by GitHub
commit fdc03f2081
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 191 additions and 2 deletions

View File

@ -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))
{

View File

@ -0,0 +1,17 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘

View File

@ -0,0 +1,20 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘

View File

@ -0,0 +1,23 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘

View File

@ -0,0 +1,28 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘

View File

@ -0,0 +1,31 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘

View File

@ -0,0 +1,31 @@
┌──────────────────┐┌──────────────────┐
│ Hello, World! ││ Hello, World! │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘│ │
┌──────────────────┐│ │
│ Hello, World! ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘

View File

@ -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()