mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-05-01 07:12:50 +08:00

Fixes some tree rendering problems where lines were not properly drawn at some levels during some circumstances. * Change the API back to only allow one root. * Now uses a stack based approach to rendering instead of recursion. * Removes the need for measuring the whole tree in advance. Leave this up to each child to render.
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System;
|
|
|
|
namespace Spectre.Console
|
|
{
|
|
/// <summary>
|
|
/// Contains extension methods for <see cref="TreeNode"/>.
|
|
/// </summary>
|
|
public static class TreeNodeExtensions
|
|
{
|
|
/// <summary>
|
|
/// Expands the tree.
|
|
/// </summary>
|
|
/// <param name="node">The tree node.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static TreeNode Expand(this TreeNode node)
|
|
{
|
|
return Expand(node, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Collapses the tree.
|
|
/// </summary>
|
|
/// <param name="node">The tree node.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static TreeNode Collapse(this TreeNode node)
|
|
{
|
|
return Expand(node, false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets whether or not the tree node should be expanded.
|
|
/// </summary>
|
|
/// <param name="node">The tree node.</param>
|
|
/// <param name="expand">Whether or not the tree node should be expanded.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static TreeNode Expand(this TreeNode node, bool expand)
|
|
{
|
|
if (node is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(node));
|
|
}
|
|
|
|
node.Expanded = expand;
|
|
return node;
|
|
}
|
|
}
|
|
}
|