Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 withing .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! ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────┘└──────────────────┘
33 changes: 33 additions & 0 deletions src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,37 @@ public Task Should_Fall_Back_To_Parent_Layout_If_All_Children_Are_Invisible()
// Then
return Verifier.Verify(console.Output);
}

[Fact]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this a [Theory] and pass in the problematic console heights 17, 20, 23, 28, 31 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

[Expectation("Render_Layout_With_Three_And_One_Columns")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this/the underlying expectation file should probably be renamed to Render_Layout_With_Nested_Three_Rows_In_One_Column, to be more consistent with:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

public Task Should_Render_Layout_With_Three_And_One_Columns()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this to line 156, so your test follows directly after public Task Should_Render_Layout_With_Nested_Rows_And_Columns(), which is a natural grouping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

{
// Given
var console = new TestConsole().Size(new Size(40, 17));
var layout = new Layout();
var col1 = new Layout();
var col1Row1 = new Layout();
var col1Row2 = new Layout();
var col1Row3 = new Layout();

col1.SplitRows(col1Row1, col1Row2, col1Row3);

var col2 = new Layout();

layout.SplitColumns(col1, col2);

var panel = new Panel("Hello, World!") { Expand = true };

List<Layout> layouts = [col1Row1, col1Row2, col1Row3, col2];
foreach (var l in layouts)
{
l.Update(panel);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about this, and whilst I'm happy with the correctness of the above test, all the other tests in the same file use a fluent convention. Can you please have a go at updating your test to be in the same style as the others, here's a close example to follow (I'm sorry for this 🏈 ache request, and I know the test comes direct from the issue repro code):

    public Task Should_Render_Layout_With_Nested_Rows_And_Columns()
    {
        // Given
        var console = new TestConsole().Size(new Size(40, 15));
        var layout = new Layout()
            .SplitRows(
                new Layout("Top")
                    .SplitRows(
                        new Layout("T1")
                            .SplitColumns(
                                new Layout("A"),
                                new Layout("B")),
                        new Layout("T2")
                            .SplitColumns(
                                new Layout("C"),
                                new Layout("D"))),
                new Layout("Bottom")
                    .SplitRows(
                        new Layout("B1")
                            .SplitColumns(
                                new Layout("E"),
                                new Layout("F")),
                        new Layout("B2")
                            .SplitColumns(
                                    new Layout("G"),
                                    new Layout("H"))));

        // When
        console.Write(layout);

        // Then
        return Verifier.Verify(console.Output);
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


// When
console.Write(layout);

// Then
return Verifier.Verify(console.Output);
}
}