@@ -55,6 +55,11 @@ private set
55
55
}
56
56
}
57
57
58
+ public string SelectedNodeName
59
+ {
60
+ get { return SelectedNode != null ? SelectedNode . Path : null ; }
61
+ }
62
+
58
63
public string Title
59
64
{
60
65
get { return title ; }
@@ -79,7 +84,7 @@ public string PathSeparator
79
84
set { pathSeparator = value ; }
80
85
}
81
86
82
- public void AddNode ( string path , string label , int level , bool isFolder , bool isActive , bool isHidden , bool isCollapsed )
87
+ public void AddNode ( string path , string label , int level , bool isFolder , bool isActive , bool isHidden , bool isCollapsed , bool isSelected )
83
88
{
84
89
var node = new TreeNode
85
90
{
@@ -101,6 +106,11 @@ public void AddNode(string path, string label, int level, bool isFolder, bool is
101
106
activeNode = node ;
102
107
}
103
108
109
+ if ( isSelected )
110
+ {
111
+ SelectedNode = node ;
112
+ }
113
+
104
114
if ( isFolder )
105
115
{
106
116
folders . Add ( node . Path , node ) ;
@@ -111,6 +121,7 @@ public void Clear()
111
121
{
112
122
folders . Clear ( ) ;
113
123
nodes . Clear ( ) ;
124
+ SelectedNode = null ;
114
125
}
115
126
116
127
public HashSet < string > GetCollapsedFolders ( )
@@ -119,7 +130,7 @@ public HashSet<string> GetCollapsedFolders()
119
130
return new HashSet < string > ( collapsedFoldersEnumerable ) ;
120
131
}
121
132
122
- public Rect Render ( Rect rect , Vector2 scroll , Action < TreeNode > singleClick = null , Action < TreeNode > doubleClick = null , Action < TreeNode > rightClick = null )
133
+ public Rect Render ( Rect containingRect , Rect rect , Vector2 scroll , Action < TreeNode > singleClick = null , Action < TreeNode > doubleClick = null , Action < TreeNode > rightClick = null )
123
134
{
124
135
if ( Event . current . type != EventType . Repaint )
125
136
{
@@ -131,6 +142,9 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
131
142
}
132
143
}
133
144
145
+ var startDisplay = scroll . y ;
146
+ var endDisplay = scroll . y + containingRect . height ;
147
+
134
148
RequiresRepaint = false ;
135
149
rect = new Rect ( 0f , rect . y , rect . width , ItemHeight ) ;
136
150
@@ -139,7 +153,13 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
139
153
if ( DisplayRootNode )
140
154
{
141
155
var titleNode = nodes [ 0 ] ;
142
- var renderResult = titleNode . Render ( rect , Styles . TreeIndentation , selectedNode == titleNode , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
156
+ var renderResult = TreeNodeRenderResult . None ;
157
+
158
+ var titleDisplay = ! ( rect . y > endDisplay || rect . yMax < startDisplay ) ;
159
+ if ( titleDisplay )
160
+ {
161
+ renderResult = titleNode . Render ( rect , Styles . TreeIndentation , selectedNode == titleNode , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
162
+ }
143
163
144
164
if ( renderResult == TreeNodeRenderResult . VisibilityChange )
145
165
{
@@ -165,7 +185,14 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
165
185
{
166
186
Indent ( ) ;
167
187
}
168
- var renderResult = node . Render ( rect , Styles . TreeIndentation , selectedNode == node , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
188
+
189
+ var renderResult = TreeNodeRenderResult . None ;
190
+
191
+ var display = ! ( rect . y > endDisplay || rect . yMax < startDisplay ) ;
192
+ if ( display )
193
+ {
194
+ renderResult = node . Render ( rect , Styles . TreeIndentation , selectedNode == node , FolderStyle , TreeNodeStyle , ActiveTreeNodeStyle ) ;
195
+ }
169
196
170
197
if ( renderResult == TreeNodeRenderResult . VisibilityChange )
171
198
{
0 commit comments