From eb97e64830f9c64451b7115bc4e2fffa4f9c6b28 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 24 Jan 2021 19:08:34 +0000 Subject: [PATCH] Made 'LeaveLastRow' optional as new property in TableStyle --- Terminal.Gui/Views/TreeView.cs | 13 ++++++++++--- UICatalog/Scenarios/TreeViewFileSystem.cs | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs index 67109385b..af0a4ab90 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -262,6 +262,12 @@ namespace Terminal.Gui { /// public bool InvertExpandSymbolColors {get;set;} + /// + /// True to leave the last row of the control free for overwritting (e.g. by a scrollbar). When True scrolling will be triggered on the second last row of the control rather than the last. + /// + /// + public bool LeaveLastRow {get;set;} + } /// @@ -792,16 +798,17 @@ namespace Terminal.Gui { var newIdx = Math.Min(Math.Max(0,idx+offset),map.Length-1); SelectedObject = map[newIdx].Model; + /*this -1 allows for possible horizontal scroll bar in the last row of the control*/ + int leaveSpace = Style.LeaveLastRow ? 1 :0; if(newIdx < ScrollOffsetVertical) { //if user has scrolled up too far to see their selection ScrollOffsetVertical = newIdx; } - else if(newIdx >= ScrollOffsetVertical + Bounds.Height -1 /*this -1 allows for possible horizontal scroll bar*/){ + else if(newIdx >= ScrollOffsetVertical + Bounds.Height - leaveSpace){ //if user has scrolled off bottom of visible tree - ScrollOffsetVertical = Math.Max(0,(newIdx+1) - (Bounds.Height-1)); - + ScrollOffsetVertical = Math.Max(0,(newIdx+1) - (Bounds.Height-leaveSpace)); } } diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index b9ac80a5c..3306d43ce 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -83,6 +83,9 @@ namespace UICatalog.Scenarios { private void SetupScrollBar () { + // When using scroll bar leave the last row of the control free (for over-rendering with scroll bar) + treeViewFiles.Style.LeaveLastRow = true; + var _scrollBar = new ScrollBarView (treeViewFiles, true); _scrollBar.ChangedPosition += () => {