Added canvas unit tests & fix canvas scaling bug

This commit is contained in:
Matt Constable
2021-01-05 13:00:04 +00:00
committed by GitHub
parent 1bb0b9ccc6
commit 5b553a4106
2 changed files with 124 additions and 0 deletions

View File

@ -44,6 +44,16 @@ namespace Spectre.Console
/// <param name="height">The canvas height.</param>
public Canvas(int width, int height)
{
if (width < 1)
{
throw new ArgumentException("Must be > 1", nameof(width));
}
if (height < 1)
{
throw new ArgumentException("Must be > 1", nameof(height));
}
Width = width;
Height = height;
@ -104,6 +114,12 @@ namespace Spectre.Console
{
height = (int)(height * (maxWidth / (float)(width * PixelWidth)));
width = maxWidth / PixelWidth;
// If it's not possible to scale the canvas sufficiently, it's too small to render.
if (height == 0)
{
yield break;
}
}
// Need to rescale the pixel buffer?