From 7b45918cfae8a6ff92ede6e03f3d2cb1c0fd8346 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 5 Jul 2021 00:56:11 -0700 Subject: [PATCH] Fix TextView always visible scroll bar not appearing when empty --- CHANGELOG | 1 + textview.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 60c1ff0..a2c96fe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ v1.5.6 (WIP) - Add CheckBox.SetCursorRune (cursors are now shown within CheckBoxes when focused by default) - Add DropDown.SetAlwaysDrawDropDownSymbol (DropDown symbols are now shown only when focused by default) - Add DropDown.SetDropDownOpenSymbolRune +- Fix TextView always visible scroll bar not appearing when empty - Draw additional accents when rendering a list divider - Update Application.Draw and Application.QueueUpdateDraw to accept one or more primitives to draw instead of the whole screen diff --git a/textview.go b/textview.go index 3771acf..8cd4537 100644 --- a/textview.go +++ b/textview.go @@ -1039,6 +1039,17 @@ func (t *TextView) Draw(screen tcell.Screen) { t.regionInfos = nil } + // Draw scroll bar last. + defer func() { + if !showVerticalScrollBar { + return + } + cursor := int(float64(len(t.index)) * (float64(t.lineOffset) / float64(len(t.index)-height))) + for printed := 0; printed < height; printed++ { + RenderScrollBar(screen, t.scrollBarVisibility, x+width, y+printed, height, len(t.index), cursor, printed, t.hasFocus, t.scrollBarColor) + } + }() + // If we don't have an index, there's nothing to draw. if t.index == nil { return @@ -1252,14 +1263,6 @@ func (t *TextView) Draw(screen tcell.Screen) { } } - // Draw scroll bar. - if showVerticalScrollBar { - cursor := int(float64(len(t.index)) * (float64(t.lineOffset) / float64(len(t.index)-height))) - for printed := 0; printed < height; printed++ { - RenderScrollBar(screen, t.scrollBarVisibility, x+width, y+printed, height, len(t.index), cursor, printed, t.hasFocus, t.scrollBarColor) - } - } - // If this view is not scrollable, we'll purge the buffer of lines that have // scrolled out of view. if !t.scrollable && t.lineOffset > 0 {