mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Fix tree rendering
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.
This commit is contained in:

committed by
Patrik Svensson

parent
0e0f4b4220
commit
8261b25e5c
@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Cursor
|
||||
|
@ -6,42 +6,40 @@ namespace TableExample
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var tree = new Tree();
|
||||
|
||||
tree.AddNode(new FigletText("Dec 2020"));
|
||||
tree.AddNode("[link]Click to go to summary[/]");
|
||||
|
||||
// Add the calendar nodes
|
||||
tree.AddNode("[blue]Calendar[/]",
|
||||
node => node.AddNode(
|
||||
new Calendar(2020, 12)
|
||||
.AddCalendarEvent(2020, 12, 12)
|
||||
.HideHeader()));
|
||||
|
||||
// Add video games node
|
||||
tree.AddNode("[red]Played video games[/]",
|
||||
node => node.AddNode(
|
||||
new Table()
|
||||
.RoundedBorder()
|
||||
.AddColumn("Title")
|
||||
.AddColumn("Console")
|
||||
.AddRow("The Witcher 3", "XBox One X")
|
||||
.AddRow("Cyberpunk 2077", "PC")
|
||||
.AddRow("Animal Crossing", "Nintendo Switch")));
|
||||
|
||||
|
||||
// Add the fruit nodes
|
||||
tree.AddNode("[green]Fruits[/]", fruits =>
|
||||
fruits.AddNode("Eaten",
|
||||
node => node.AddNode(
|
||||
new BarChart().Width(40)
|
||||
.AddItem("Apple", 12, Color.Red)
|
||||
.AddItem("Kiwi", 3, Color.Green)
|
||||
.AddItem("Banana", 21, Color.Yellow))));
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[yellow]Monthly summary[/]");
|
||||
|
||||
// Render the tree
|
||||
var tree = BuildTree();
|
||||
AnsiConsole.Render(tree);
|
||||
}
|
||||
|
||||
private static Tree BuildTree()
|
||||
{
|
||||
// Create the tree
|
||||
var tree = new Tree("Root")
|
||||
.Style(Style.Parse("red"))
|
||||
.Guide(TreeGuide.BoldLine);
|
||||
|
||||
// Add some nodes
|
||||
var foo = tree.AddNode("[yellow]Foo[/]");
|
||||
var table = foo.AddNode(new Table()
|
||||
.RoundedBorder()
|
||||
.AddColumn("First")
|
||||
.AddColumn("Second")
|
||||
.AddRow("1", "2")
|
||||
.AddRow("3", "4")
|
||||
.AddRow("5", "6"));
|
||||
|
||||
table.AddNode("[blue]Baz[/]");
|
||||
foo.AddNode("Qux");
|
||||
|
||||
var bar = tree.AddNode("[yellow]Bar[/]");
|
||||
bar.AddNode(new Calendar(2020, 12)
|
||||
.AddCalendarEvent(2020, 12, 12)
|
||||
.HideHeader());
|
||||
|
||||
// Return the tree
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user