mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-13 15:42:50 +08:00
Merge pull request #1514 from BlazeFace/blz/issues/1390
This commit is contained in:
commit
fdc03f2081
@ -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))
|
||||
{
|
||||
|
@ -0,0 +1,17 @@
|
||||
┌──────────────────┐┌──────────────────┐
|
||||
│ Hello, World! ││ Hello, World! │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘└──────────────────┘
|
@ -0,0 +1,20 @@
|
||||
┌──────────────────┐┌──────────────────┐
|
||||
│ Hello, World! ││ Hello, World! │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘└──────────────────┘
|
@ -0,0 +1,23 @@
|
||||
┌──────────────────┐┌──────────────────┐
|
||||
│ Hello, World! ││ Hello, World! │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘└──────────────────┘
|
@ -0,0 +1,28 @@
|
||||
┌──────────────────┐┌──────────────────┐
|
||||
│ Hello, World! ││ Hello, World! │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘└──────────────────┘
|
@ -0,0 +1,31 @@
|
||||
┌──────────────────┐┌──────────────────┐
|
||||
│ Hello, World! ││ Hello, World! │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘└──────────────────┘
|
@ -0,0 +1,31 @@
|
||||
┌──────────────────┐┌──────────────────┐
|
||||
│ Hello, World! ││ Hello, World! │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘│ │
|
||||
┌──────────────────┐│ │
|
||||
│ Hello, World! ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
│ ││ │
|
||||
└──────────────────┘└──────────────────┘
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user