using System.Collections.Generic;
using System.Linq;
using Spectre.Console.Rendering;
namespace Spectre.Console
{
///
/// Node of a tree.
///
public sealed class TreeNode : IRenderable
{
private readonly IRenderable _renderable;
private List _children;
///
/// Initializes a new instance of the class.
///
/// The which this node wraps.
/// Any children that the node is declared with.
public TreeNode(IRenderable renderable, IEnumerable? children = null)
{
_renderable = renderable;
_children = new List(children ?? Enumerable.Empty());
}
///
/// Gets the children of this node.
///
public List Children
{
get => _children;
}
///
/// Adds a child to the end of the node's list of children.
///
/// Child to be added.
public void AddChild(TreeNode child)
{
_children.Add(child);
}
///
public Measurement Measure(RenderContext context, int maxWidth)
{
return _renderable.Measure(context, maxWidth);
}
///
public IEnumerable Render(RenderContext context, int maxWidth)
{
return _renderable.Render(context, maxWidth);
}
}
}