mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00
Fix maxWidth bug in Panel
Panel could pass a maxWidth to the child Render function that was greater than the maxWidth that was passed to the Panel render function. I noticed this when trying to nest a table in a panel and the word wrapping was being disabled. N.B It might be that Table.Measure ought to not return a measurment larger than maxWidth, but this Panel change seems defensivly sensible regardless.
This commit is contained in:
parent
79af013bf2
commit
91f910326c
@ -0,0 +1,16 @@
|
||||
╔════════════════════════════╗
|
||||
║ ┌────────┬───────┬───────┐ ║
|
||||
║ │ Foo │ Bar │ Baz │ ║
|
||||
║ ├────────┼───────┼───────┤ ║
|
||||
║ │ Qux │ Corgi │ Waldo │ ║
|
||||
║ │ With A │ │ │ ║
|
||||
║ │ Long │ │ │ ║
|
||||
║ │ Descri │ │ │ ║
|
||||
║ │ ption │ │ │ ║
|
||||
║ │ Grault │ Garpl │ Fred │ ║
|
||||
║ │ │ y │ On A │ ║
|
||||
║ │ │ │ Long │ ║
|
||||
║ │ │ │ Long │ ║
|
||||
║ │ │ │ Walk │ ║
|
||||
║ └────────┴───────┴───────┘ ║
|
||||
╚════════════════════════════╝
|
@ -476,5 +476,26 @@ namespace Spectre.Console.Tests.Unit
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render_Fold")]
|
||||
public Task Should_Render_With_Folded_Text_Table_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole().Width(30);
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux With A Long Description", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred On A Long Long Walk");
|
||||
|
||||
var panel = new Panel(table);
|
||||
panel.Border = BoxBorder.Double;
|
||||
|
||||
// When
|
||||
console.Write(panel);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ namespace Spectre.Console
|
||||
|
||||
var panelWidth = childWidth + edgeWidth;
|
||||
panelWidth = Math.Min(panelWidth, maxWidth);
|
||||
childWidth = panelWidth - edgeWidth;
|
||||
|
||||
var result = new List<Segment>();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user