mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 17:28:01 +01:00
Fix 1130 broken links (#1131)
* fixed table & treeview docs * regen docs * relnote
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
<h1 id="tree-view">Tree View</h1>
|
||||
|
||||
<p>TreeView is a control for navigating hierarchical objects. It comes in two forms <code>TreeView</code> and <code>TreeView<T></code>.</p>
|
||||
<p><a href="api/Terminal.Gui/Terminal.Gui.TreeView.html">TreeView API Reference</a></p>
|
||||
<h2 id="using-treeview">Using TreeView</h2>
|
||||
<p>The basic non generic TreeView class is populated by <code>ITreeNode</code> objects. The simplest tree you can make would look something like:</p>
|
||||
<pre><code class="lang-csharp">var tree = new TreeView()
|
||||
@@ -97,42 +98,42 @@ tree.AddObject(root2);
|
||||
<pre><code class="lang-csharp">// Your data class
|
||||
private class House : TreeNode {
|
||||
|
||||
// Your properties
|
||||
public string Address {get;set;}
|
||||
public List<Room> Rooms {get;set;}
|
||||
// Your properties
|
||||
public string Address {get;set;}
|
||||
public List<Room> Rooms {get;set;}
|
||||
|
||||
// ITreeNode member:
|
||||
public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
|
||||
// ITreeNode member:
|
||||
public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
|
||||
|
||||
public override string Text { get => Address; set => Address = value; }
|
||||
public override string Text { get => Address; set => Address = value; }
|
||||
}
|
||||
|
||||
|
||||
// Your other data class
|
||||
private class Room : TreeNode{
|
||||
|
||||
public string Name {get;set;}
|
||||
public string Name {get;set;}
|
||||
|
||||
public override string Text{get=>Name;set{Name=value;}}
|
||||
public override string Text{get=>Name;set{Name=value;}}
|
||||
}
|
||||
</code></pre><p>After implementing the interface you can add your objects directly to the tree</p>
|
||||
<pre><code class="lang-csharp">
|
||||
var myHouse = new House()
|
||||
{
|
||||
Address = "23 Nowhere Street",
|
||||
Rooms = new List<Room>{
|
||||
new Room(){Name = "Ballroom"},
|
||||
new Room(){Name = "Bedroom 1"},
|
||||
new Room(){Name = "Bedroom 2"}
|
||||
}
|
||||
Address = "23 Nowhere Street",
|
||||
Rooms = new List<Room>{
|
||||
new Room(){Name = "Ballroom"},
|
||||
new Room(){Name = "Bedroom 1"},
|
||||
new Room(){Name = "Bedroom 2"}
|
||||
}
|
||||
};
|
||||
|
||||
var tree = new TreeView()
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 40,
|
||||
Height = 20
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 40,
|
||||
Height = 20
|
||||
};
|
||||
|
||||
tree.AddObject(myHouse);
|
||||
@@ -146,72 +147,73 @@ tree.AddObject(myHouse);
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private class Army : GameObject
|
||||
{
|
||||
public string Designation {get;set;}
|
||||
public List<Unit> Units {get;set;}
|
||||
public string Designation {get;set;}
|
||||
public List<Unit> Units {get;set;}
|
||||
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return Designation;
|
||||
}
|
||||
public override string ToString ()
|
||||
{
|
||||
return Designation;
|
||||
}
|
||||
}
|
||||
|
||||
private class Unit : GameObject
|
||||
{
|
||||
public string Name {get;set;}
|
||||
public override string ToString ()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
public string Name {get;set;}
|
||||
public override string ToString ()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
</code></pre><p>An <code>ITreeBuilder<T></code> for these classes might look like:</p>
|
||||
<pre><code class="lang-csharp">
|
||||
private class GameObjectTreeBuilder : ITreeBuilder<GameObject> {
|
||||
public bool SupportsCanExpand => true;
|
||||
public bool SupportsCanExpand => true;
|
||||
|
||||
public bool CanExpand (GameObject model)
|
||||
{
|
||||
return model is Army;
|
||||
}
|
||||
public bool CanExpand (GameObject model)
|
||||
{
|
||||
return model is Army;
|
||||
}
|
||||
|
||||
public IEnumerable<GameObject> GetChildren (GameObject model)
|
||||
{
|
||||
if(model is Army a)
|
||||
return a.Units;
|
||||
public IEnumerable<GameObject> GetChildren (GameObject model)
|
||||
{
|
||||
if(model is Army a)
|
||||
return a.Units;
|
||||
|
||||
return Enumerable.Empty<GameObject>();
|
||||
}
|
||||
return Enumerable.Empty<GameObject>();
|
||||
}
|
||||
}
|
||||
</code></pre><p>To use the builder in a tree you would use:</p>
|
||||
<pre><code class="lang-csharp">var army1 = new Army()
|
||||
{
|
||||
Designation = "3rd Infantry",
|
||||
Units = new List<Unit>{
|
||||
new Unit(){Name = "Orc"},
|
||||
new Unit(){Name = "Troll"},
|
||||
new Unit(){Name = "Goblin"},
|
||||
}
|
||||
Designation = "3rd Infantry",
|
||||
Units = new List<Unit>{
|
||||
new Unit(){Name = "Orc"},
|
||||
new Unit(){Name = "Troll"},
|
||||
new Unit(){Name = "Goblin"},
|
||||
}
|
||||
};
|
||||
|
||||
var tree = new TreeView<GameObject>()
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 40,
|
||||
Height = 20,
|
||||
TreeBuilder = new GameObjectTreeBuilder()
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 40,
|
||||
Height = 20,
|
||||
TreeBuilder = new GameObjectTreeBuilder()
|
||||
};
|
||||
|
||||
|
||||
tree.AddObject(army1);
|
||||
</code></pre><p>Alternatively you can use <code>DelegateTreeBuilder<T></code> instead of implementing your own <code>ITreeBuilder<T></code>. For example:</p>
|
||||
<pre><code class="lang-csharp">tree.TreeBuilder = new DelegateTreeBuilder<GameObject>(
|
||||
(o)=>o is Army a ? a.Units
|
||||
: Enumerable.Empty<GameObject>());
|
||||
(o)=>o is Army a ? a.Units
|
||||
: Enumerable.Empty<GameObject>());
|
||||
</code></pre><h2 id="node-text-and-tostring">Node Text and ToString</h2>
|
||||
<p>The default behaviour of TreeView is to use the <code>ToString</code> method on the objects for rendering. You can customise this by changing the <code>AspectGetter</code>. For example:</p>
|
||||
<p>The default behavior of TreeView is to use the <code>ToString</code> method on the objects for rendering. You can customise this by changing the <code>AspectGetter</code>. For example:</p>
|
||||
<pre><code class="lang-csharp">treeViewFiles.AspectGetter = (f)=>f.FullName;
|
||||
</code></pre></article>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user