Add support for alignment

This commit is contained in:
Patrik Svensson
2022-02-21 18:35:21 +01:00
committed by Phil Scott
parent 5e41a2f505
commit eb4a7d3bf4
8 changed files with 88 additions and 32 deletions

View File

@ -3,7 +3,7 @@ namespace Spectre.Console;
/// <summary>
/// Representation of a file system path.
/// </summary>
public sealed class TextPath : IRenderable
public sealed class TextPath : IRenderable, IAlignable
{
private const string Ellipsis = "...";
private const string UnicodeEllipsis = "…";
@ -32,6 +32,11 @@ public sealed class TextPath : IRenderable
/// </summary>
public Style? LeafStyle { get; set; }
/// <summary>
/// Gets or sets the alignment.
/// </summary>
public Justify? Alignment { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="TextPath"/> class.
/// </summary>
@ -75,6 +80,8 @@ public sealed class TextPath : IRenderable
/// <inheritdoc/>
public IEnumerable<Segment> Render(RenderContext context, int maxWidth)
{
var alignment = Alignment ?? Justify.Left;
var rootStyle = RootStyle ?? Style.Plain;
var separatorStyle = SeparatorStyle ?? Style.Plain;
var stemStyle = StemStyle ?? Style.Plain;
@ -111,6 +118,10 @@ public sealed class TextPath : IRenderable
}
}
// Align the result
Aligner.Align(parts, Alignment, maxWidth);
// Insert a line break
parts.Add(Segment.LineBreak);
return parts;