mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-20 05:48:14 +08:00
Use file scoped namespace declarations
This commit is contained in:

committed by
Phil Scott

parent
1dbaf50935
commit
ec1188b837
@ -2,67 +2,66 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Spectre.Console.Rendering
|
||||
namespace Spectre.Console.Rendering;
|
||||
|
||||
internal readonly struct SegmentShape
|
||||
{
|
||||
internal readonly struct SegmentShape
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
|
||||
public SegmentShape(int width, int height)
|
||||
{
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public SegmentShape(int width, int height)
|
||||
public static SegmentShape Calculate(RenderContext context, List<SegmentLine> lines)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
public static SegmentShape Calculate(RenderContext context, List<SegmentLine> lines)
|
||||
if (lines is null)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (lines is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(lines));
|
||||
}
|
||||
|
||||
var height = lines.Count;
|
||||
var width = lines.Max(l => Segment.CellCount(l));
|
||||
|
||||
return new SegmentShape(width, height);
|
||||
throw new ArgumentNullException(nameof(lines));
|
||||
}
|
||||
|
||||
public SegmentShape Inflate(SegmentShape other)
|
||||
var height = lines.Count;
|
||||
var width = lines.Max(l => Segment.CellCount(l));
|
||||
|
||||
return new SegmentShape(width, height);
|
||||
}
|
||||
|
||||
public SegmentShape Inflate(SegmentShape other)
|
||||
{
|
||||
return new SegmentShape(
|
||||
Math.Max(Width, other.Width),
|
||||
Math.Max(Height, other.Height));
|
||||
}
|
||||
|
||||
public void Apply(RenderContext context, ref List<SegmentLine> lines)
|
||||
{
|
||||
foreach (var line in lines)
|
||||
{
|
||||
return new SegmentShape(
|
||||
Math.Max(Width, other.Width),
|
||||
Math.Max(Height, other.Height));
|
||||
var length = Segment.CellCount(line);
|
||||
var missing = Width - length;
|
||||
if (missing > 0)
|
||||
{
|
||||
line.Add(Segment.Padding(missing));
|
||||
}
|
||||
}
|
||||
|
||||
public void Apply(RenderContext context, ref List<SegmentLine> lines)
|
||||
if (lines.Count < Height && Width > 0)
|
||||
{
|
||||
foreach (var line in lines)
|
||||
var missing = Height - lines.Count;
|
||||
for (var i = 0; i < missing; i++)
|
||||
{
|
||||
var length = Segment.CellCount(line);
|
||||
var missing = Width - length;
|
||||
if (missing > 0)
|
||||
{
|
||||
line.Add(Segment.Padding(missing));
|
||||
}
|
||||
}
|
||||
|
||||
if (lines.Count < Height && Width > 0)
|
||||
{
|
||||
var missing = Height - lines.Count;
|
||||
for (var i = 0; i < missing; i++)
|
||||
{
|
||||
lines.Add(new SegmentLine
|
||||
lines.Add(new SegmentLine
|
||||
{
|
||||
Segment.Padding(Width),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user