Fix TextView always visible scroll bar not appearing when empty

This commit is contained in:
Trevor Slocum 2021-07-05 00:56:11 -07:00
parent c25dbea325
commit 7b45918cfa
2 changed files with 12 additions and 8 deletions

View File

@ -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

View File

@ -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 {