namespace Spectre.Console; /// /// Renders things in rows. /// public sealed class Rows : Renderable, IExpandable { private readonly List _children; /// public bool Expand { get; set; } /// /// Initializes a new instance of the class. /// /// The items to render as rows. public Rows(params IRenderable[] items) : this((IEnumerable)items) { } /// /// Initializes a new instance of the class. /// /// The items to render as rows. public Rows(IEnumerable children) { _children = new List(children ?? throw new ArgumentNullException(nameof(children))); } /// protected override Measurement Measure(RenderOptions options, int maxWidth) { if (Expand) { return new Measurement(maxWidth, maxWidth); } else { var measurements = _children.Select(c => c.Measure(options, maxWidth)).ToArray(); if (measurements.Length > 0) { return new Measurement( measurements.Min(c => c.Min), measurements.Min(c => c.Max)); } return new Measurement(0, 0); } } /// protected override IEnumerable Render(RenderOptions options, int maxWidth) { var result = new List(); foreach (var child in _children) { var segments = child.Render(options, maxWidth); foreach (var (_, _, last, segment) in segments.Enumerate()) { result.Add(segment); if (last) { if (!segment.IsLineBreak) { result.Add(Segment.LineBreak); } } } } return result; } }