@@ -55,6 +55,11 @@ private set
5555 }
5656 }
5757
58+ public string SelectedNodeName
59+ {
60+ get { return SelectedNode != null ? SelectedNode . Path : null ; }
61+ }
62+
5863 public string Title
5964 {
6065 get { return title ; }
@@ -79,7 +84,7 @@ public string PathSeparator
7984 set { pathSeparator = value ; }
8085 }
8186
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 )
8388 {
8489 var node = new TreeNode
8590 {
@@ -101,6 +106,11 @@ public void AddNode(string path, string label, int level, bool isFolder, bool is
101106 activeNode = node ;
102107 }
103108
109+ if ( isSelected )
110+ {
111+ SelectedNode = node ;
112+ }
113+
104114 if ( isFolder )
105115 {
106116 folders . Add ( node . Path , node ) ;
@@ -111,6 +121,7 @@ public void Clear()
111121 {
112122 folders . Clear ( ) ;
113123 nodes . Clear ( ) ;
124+ SelectedNode = null ;
114125 }
115126
116127 public HashSet < string > GetCollapsedFolders ( )
@@ -119,7 +130,7 @@ public HashSet<string> GetCollapsedFolders()
119130 return new HashSet < string > ( collapsedFoldersEnumerable ) ;
120131 }
121132
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 )
123134 {
124135 if ( Event . current . type != EventType . Repaint )
125136 {
@@ -131,6 +142,9 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
131142 }
132143 }
133144
145+ var startDisplay = scroll . y ;
146+ var endDisplay = scroll . y + containingRect . height ;
147+
134148 RequiresRepaint = false ;
135149 rect = new Rect ( 0f , rect . y , rect . width , ItemHeight ) ;
136150
@@ -139,7 +153,13 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
139153 if ( DisplayRootNode )
140154 {
141155 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+ }
143163
144164 if ( renderResult == TreeNodeRenderResult . VisibilityChange )
145165 {
@@ -165,7 +185,14 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
165185 {
166186 Indent ( ) ;
167187 }
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+ }
169196
170197 if ( renderResult == TreeNodeRenderResult . VisibilityChange )
171198 {
0 commit comments