From d836c5790b70f48d2844465c7dfbd4e3843f3bd9 Mon Sep 17 00:00:00 2001 From: Quobi Date: Tue, 29 Dec 2020 14:53:35 +0200 Subject: [PATCH] DarkTreeView rendering optimization. Optimized the drawing of child nodes. It'll perform similar to listview, drawing only the visible elements within the viewport, thus making the scrolling smooth. With support for each child nodes. --- DarkUI/Controls/DarkTreeView.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/DarkUI/Controls/DarkTreeView.cs b/DarkUI/Controls/DarkTreeView.cs index bfecb86..cf52f67 100644 --- a/DarkUI/Controls/DarkTreeView.cs +++ b/DarkUI/Controls/DarkTreeView.cs @@ -1262,10 +1262,33 @@ private void DrawNode(DarkTreeNode node, Graphics g) } // 5. Draw child nodes + 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) - DrawNode(childNode, g); + { + + 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; + } } }