Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing #1390 #1514

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 test/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]
[Expectation("Render_Layout_With_Three_And_One_Columns")]
public Task Should_Render_Layout_With_Three_And_One_Columns()
{
// 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);
}

// When
console.Write(layout);

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