forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualTreeTreeView.cs
More file actions
69 lines (58 loc) · 2.27 KB
/
Copy pathVisualTreeTreeView.cs
File metadata and controls
69 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.Experimental.UIElements.Debugger
{
class VisualTreeItem : TreeViewItem
{
public readonly VisualElement elt;
public VisualTreeItem(VisualElement elt, int depth) : base((int)elt.controlid, depth, GetDisplayName(elt))
{
this.elt = elt;
}
private static string GetDisplayName(VisualElement elt)
{
string t = elt.GetType() == typeof(VisualElement) ? String.Empty : (elt.GetType().Name + " ");
string n = String.IsNullOrEmpty(elt.name) ? String.Empty : ("#" + elt.name + " ");
string res = t + n + (elt.GetClasses().Any() ? ("." + string.Join(",.", elt.GetClasses().ToArray())) : String.Empty);
if (res == String.Empty)
return elt.GetType().Name;
return res;
}
public uint controlId { get { return elt.controlid; } }
}
class VisualTreeTreeView : TreeView
{
public VisualTreeTreeView(TreeViewState state)
: base(state) {}
public Panel panel;
public bool includeShadowHierarchy;
protected override TreeViewItem BuildRoot()
{
var root = new TreeViewItem(0, -1);
Recurse(root, panel.visualTree);
return root;
}
private void Recurse(TreeViewItem tree, VisualElement elt)
{
var child = new VisualTreeItem(elt, tree.depth + 1);
tree.AddChild(child);
IEnumerable<VisualElement> childElements = includeShadowHierarchy
? elt.shadow.Children()
: (elt.contentContainer == null ? Enumerable.Empty<VisualElement>() : elt.Children());
foreach (VisualElement childElement in childElements)
{
Recurse(child, childElement);
}
}
public VisualTreeItem GetNodeFor(int selectedId)
{
return FindRows(new List<int> { selectedId }).FirstOrDefault() as VisualTreeItem;
}
}
}