diff --git a/Terminal.Gui/Views/TreeView/TreeViewT.cs b/Terminal.Gui/Views/TreeView/TreeViewT.cs index aeae194acf..2d745289a8 100644 --- a/Terminal.Gui/Views/TreeView/TreeViewT.cs +++ b/Terminal.Gui/Views/TreeView/TreeViewT.cs @@ -686,11 +686,7 @@ private void UpdateContentSize () try { - IReadOnlyCollection> map = BuildLineMap (); - int width = map.Count > 0 ? map.Max (b => b.GetWidth ()) : 0; - int height = map.Count; - - SetContentSize (new Size (width, height)); + SetContentSize (GetSize ()); } finally { @@ -698,6 +694,18 @@ private void UpdateContentSize () } } + /// + /// Calculates the logical size of the tree based on currently expanded branches. The width is the maximum width of + /// all visible branches, and the height is the total number of visible branches. + /// + /// + public Size GetSize () + { + IReadOnlyCollection> map = BuildLineMap (); + + return new Size (map.Count > 0 ? map.Max (b => b.GetWidth ()) : 0, map.Count); + } + /// protected override void OnViewportChanged (DrawEventArgs e) {