Skip to content

Commit fdc03f2

Browse files
Merge pull request #1514 from BlazeFace/blz/issues/1390
2 parents a32dc80 + 3eb620a commit fdc03f2

8 files changed

+191
-2
lines changed

src/Spectre.Console/Internal/Ratio.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ public static List<int> Resolve(int total, IEnumerable<IRatioResolvable> edges)
99
{
1010
static (int Div, float Mod) DivMod(float x, float y)
1111
{
12-
return ((int)(x / y), x % y);
12+
var (div, mod) = ((int)(x / y), x % y);
13+
14+
// If remainder is within .0001 of 1 then we round up
15+
if (!(mod > 0.9999))
16+
{
17+
return (div, mod);
18+
}
19+
20+
div++;
21+
mod = 0;
22+
return (div, mod);
1323
}
1424

1525
static int? GetEdgeWidth(IRatioResolvable edge)
@@ -22,7 +32,7 @@ public static List<int> Resolve(int total, IEnumerable<IRatioResolvable> edges)
2232
return edge.Size;
2333
}
2434

25-
var sizes = edges.Select(x => GetEdgeWidth(x)).ToArray();
35+
var sizes = edges.Select(GetEdgeWidth).ToArray();
2636

2737
while (sizes.Any(s => s == null))
2838
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
┌──────────────────┐┌──────────────────┐
2+
│ Hello, World! ││ Hello, World! │
3+
│ ││ │
4+
│ ││ │
5+
└──────────────────┘│ │
6+
┌──────────────────┐│ │
7+
│ Hello, World! ││ │
8+
│ ││ │
9+
│ ││ │
10+
│ ││ │
11+
└──────────────────┘│ │
12+
┌──────────────────┐│ │
13+
│ Hello, World! ││ │
14+
│ ││ │
15+
│ ││ │
16+
│ ││ │
17+
└──────────────────┘└──────────────────┘
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
┌──────────────────┐┌──────────────────┐
2+
│ Hello, World! ││ Hello, World! │
3+
│ ││ │
4+
│ ││ │
5+
│ ││ │
6+
└──────────────────┘│ │
7+
┌──────────────────┐│ │
8+
│ Hello, World! ││ │
9+
│ ││ │
10+
│ ││ │
11+
│ ││ │
12+
│ ││ │
13+
└──────────────────┘│ │
14+
┌──────────────────┐│ │
15+
│ Hello, World! ││ │
16+
│ ││ │
17+
│ ││ │
18+
│ ││ │
19+
│ ││ │
20+
└──────────────────┘└──────────────────┘
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
┌──────────────────┐┌──────────────────┐
2+
│ Hello, World! ││ Hello, World! │
3+
│ ││ │
4+
│ ││ │
5+
│ ││ │
6+
│ ││ │
7+
└──────────────────┘│ │
8+
┌──────────────────┐│ │
9+
│ Hello, World! ││ │
10+
│ ││ │
11+
│ ││ │
12+
│ ││ │
13+
│ ││ │
14+
│ ││ │
15+
└──────────────────┘│ │
16+
┌──────────────────┐│ │
17+
│ Hello, World! ││ │
18+
│ ││ │
19+
│ ││ │
20+
│ ││ │
21+
│ ││ │
22+
│ ││ │
23+
└──────────────────┘└──────────────────┘
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
┌──────────────────┐┌──────────────────┐
2+
│ Hello, World! ││ Hello, World! │
3+
│ ││ │
4+
│ ││ │
5+
│ ││ │
6+
│ ││ │
7+
│ ││ │
8+
│ ││ │
9+
└──────────────────┘│ │
10+
┌──────────────────┐│ │
11+
│ Hello, World! ││ │
12+
│ ││ │
13+
│ ││ │
14+
│ ││ │
15+
│ ││ │
16+
│ ││ │
17+
│ ││ │
18+
└──────────────────┘│ │
19+
┌──────────────────┐│ │
20+
│ Hello, World! ││ │
21+
│ ││ │
22+
│ ││ │
23+
│ ││ │
24+
│ ││ │
25+
│ ││ │
26+
│ ││ │
27+
│ ││ │
28+
└──────────────────┘└──────────────────┘
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
┌──────────────────┐┌──────────────────┐
2+
│ Hello, World! ││ Hello, World! │
3+
│ ││ │
4+
│ ││ │
5+
│ ││ │
6+
│ ││ │
7+
│ ││ │
8+
│ ││ │
9+
│ ││ │
10+
└──────────────────┘│ │
11+
┌──────────────────┐│ │
12+
│ Hello, World! ││ │
13+
│ ││ │
14+
│ ││ │
15+
│ ││ │
16+
│ ││ │
17+
│ ││ │
18+
│ ││ │
19+
│ ││ │
20+
└──────────────────┘│ │
21+
┌──────────────────┐│ │
22+
│ Hello, World! ││ │
23+
│ ││ │
24+
│ ││ │
25+
│ ││ │
26+
│ ││ │
27+
│ ││ │
28+
│ ││ │
29+
│ ││ │
30+
│ ││ │
31+
└──────────────────┘└──────────────────┘
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
┌──────────────────┐┌──────────────────┐
2+
│ Hello, World! ││ Hello, World! │
3+
│ ││ │
4+
│ ││ │
5+
│ ││ │
6+
│ ││ │
7+
│ ││ │
8+
│ ││ │
9+
│ ││ │
10+
└──────────────────┘│ │
11+
┌──────────────────┐│ │
12+
│ Hello, World! ││ │
13+
│ ││ │
14+
│ ││ │
15+
│ ││ │
16+
│ ││ │
17+
│ ││ │
18+
│ ││ │
19+
│ ││ │
20+
└──────────────────┘│ │
21+
┌──────────────────┐│ │
22+
│ Hello, World! ││ │
23+
│ ││ │
24+
│ ││ │
25+
│ ││ │
26+
│ ││ │
27+
│ ││ │
28+
│ ││ │
29+
│ ││ │
30+
│ ││ │
31+
└──────────────────┘└──────────────────┘

src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs

+29
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,35 @@ public Task Should_Render_Layout_With_Nested_Rows_And_Columns()
153153
return Verifier.Verify(console.Output);
154154
}
155155

156+
[Theory]
157+
[InlineData(17, "17")]
158+
[InlineData(20, "20")]
159+
[InlineData(23, "23")]
160+
[InlineData(28, "28")]
161+
[InlineData(31, "31")]
162+
[Expectation("Render_Layout_With_Nested_Three_Rows_In_One_Column")]
163+
public Task Should_Render_Layout_With_Three_And_One_Columns(int height, string expectationPrefix)
164+
{
165+
// Given
166+
var console = new TestConsole().Size(new Size(40, height));
167+
168+
// Layout with 2 columns, left column has 3 rows and right column has 1 row
169+
var layout = new Layout(new Panel("Hello, World!") { Expand = true })
170+
.SplitColumns(
171+
new Layout(new Panel("Hello, World!") { Expand = true })
172+
.SplitRows(
173+
new Layout(new Panel("Hello, World!") { Expand = true }),
174+
new Layout(new Panel("Hello, World!") { Expand = true }),
175+
new Layout(new Panel("Hello, World!") { Expand = true })),
176+
new Layout(new Panel("Hello, World!") { Expand = true }));
177+
178+
// When
179+
console.Write(layout);
180+
181+
// Then
182+
return Verifier.Verify(console.Output).UseTextForParameters(expectationPrefix);
183+
}
184+
156185
[Fact]
157186
[Expectation("Render_Layout_Without_Invisible_Children")]
158187
public Task Should_Render_Layout_Without_Invisible_Children()

0 commit comments

Comments
 (0)