diff --git a/DarkUI/Controls/DarkTreeView.cs b/DarkUI/Controls/DarkTreeView.cs index c8fb1ee..ea9fbbd 100644 --- a/DarkUI/Controls/DarkTreeView.cs +++ b/DarkUI/Controls/DarkTreeView.cs @@ -1268,10 +1268,29 @@ private void DrawNode(DarkTreeNode node, Graphics g) } // 5. Draw child nodes - if (node.Expanded) - { - foreach (var childNode in node.Nodes) - DrawNode(childNode, g); + DrawChildNodes(node, g); + } + + /// + /// Recursively paints only the nodes and child nodes within the viewport. + /// + private void DrawChildNodes(DarkTreeNode node, Graphics g) { + if( node.Expanded ) { + foreach( var childNode in node.Nodes ) { + + if( childNode.Expanded ) + DrawChildNodes(childNode, g); + + bool isInTopView = Viewport.Top <= childNode.FullArea.Y; + bool isWithin = childNode.FullArea.Y < Viewport.Top + Viewport.Height; + bool isPastBottomView = childNode.FullArea.Y > Viewport.Top + Viewport.Height; + + if( isInTopView && isWithin ) + DrawNode(childNode, g); + + if( isPastBottomView ) + break; + } } } diff --git a/SOURCES.md b/SOURCES.md index 11faecf..3b3a69a 100644 --- a/SOURCES.md +++ b/SOURCES.md @@ -15,4 +15,6 @@ These PRs came from RobinPerris' Repo 3. #41 https://github.com/RobinPerris/DarkUI/pull/41 - Fixed the display of the selected item in the combobox when changing its visibility from ricardodalarme:FixedComboBox 4. #48 https://github.com/RobinPerris/DarkUI/pull/48 - - Fix Issue #47 from cronoxyd:master \ No newline at end of file + - Fix Issue #47 from cronoxyd:master +5. #52 https://github.com/RobinPerris/DarkUI/pull/52 + - DarkTreeView rendering optimization from Quobi:patch-2 \ No newline at end of file