Browse Source

Fix applying ScrollBarAlways to List

merge-requests/1/merge
Trevor Slocum 2 years ago
parent
commit
74844d6d3f
  1. 1
      demos/progressbar/main.go
  2. 14
      list.go
  3. 2
      table.go
  4. 4
      treeview.go
  5. 10
      util.go

1
demos/progressbar/main.go

@ -11,6 +11,7 @@ func main() {
app := cview.NewApplication()
grid := cview.NewGrid().SetColumns(-1, 6, 4, 30, -1).SetRows(-1, 12, 4, 4, -1)
grid.SetBackgroundColor(cview.Styles.PrimitiveBackgroundColor)
verticalProgressBar := cview.NewProgressBar()
verticalProgressBar.SetBorder(true)

14
list.go

@ -488,9 +488,7 @@ func (l *List) Draw(screen tcell.Screen) {
}
}
if l.scrollBarVisibility == ScrollBarAlways || (l.scrollBarVisibility == ScrollBarAuto && len(l.items) > scrollBarHeight) {
RenderScrollBar(screen, scrollBarX, y, scrollBarHeight, len(l.items), l.currentItem, index-l.offset, l.hasFocus, l.scrollBarColor)
}
RenderScrollBar(screen, l.scrollBarVisibility, scrollBarX, y, scrollBarHeight, len(l.items), l.currentItem, index-l.offset, l.hasFocus, l.scrollBarColor)
y++
@ -502,13 +500,17 @@ func (l *List) Draw(screen tcell.Screen) {
if l.showSecondaryText {
Print(screen, item.SecondaryText, x, y, width, AlignLeft, l.secondaryTextColor)
if l.scrollBarVisibility == ScrollBarAlways || (l.scrollBarVisibility == ScrollBarAuto && len(l.items) > scrollBarHeight) {
RenderScrollBar(screen, scrollBarX, y, scrollBarHeight, len(l.items), l.currentItem, index-l.offset, l.hasFocus, l.scrollBarColor)
}
RenderScrollBar(screen, l.scrollBarVisibility, scrollBarX, y, scrollBarHeight, len(l.items), l.currentItem, index-l.offset, l.hasFocus, l.scrollBarColor)
y++
}
}
// Overdraw scroll bar when necessary.
for y < bottomLimit {
RenderScrollBar(screen, l.scrollBarVisibility, scrollBarX, y, scrollBarHeight, len(l.items), l.currentItem, bottomLimit-y, l.hasFocus, l.scrollBarColor)
y++
}
}
// InputHandler returns the handler for this primitive.

2
table.go

@ -913,7 +913,7 @@ ColumnLoop:
// Draw scroll bar.
cursor := int(float64(scrollBarItems) * (float64(t.rowOffset) / float64(((rows-t.fixedRows)-t.visibleRows)+padTotalOffset)))
for printed := 0; printed < scrollBarHeight; printed++ {
RenderScrollBar(screen, scrollBarX, scrollBarY+printed, scrollBarHeight, scrollBarItems, cursor, printed, t.hasFocus, t.scrollBarColor)
RenderScrollBar(screen, t.scrollBarVisibility, scrollBarX, scrollBarY+printed, scrollBarHeight, scrollBarItems, cursor, printed, t.hasFocus, t.scrollBarColor)
}
}

4
treeview.go

@ -709,9 +709,7 @@ func (t *TreeView) Draw(screen tcell.Screen) {
}
// Draw scroll bar.
if t.scrollBarVisibility == ScrollBarAlways || (t.scrollBarVisibility == ScrollBarAuto && rows > height) {
RenderScrollBar(screen, x+(width-1), posY, height, rows, cursor, posY-y, t.hasFocus, tcell.ColorWhite)
}
RenderScrollBar(screen, t.scrollBarVisibility, x+(width-1), posY, height, rows, cursor, posY-y, t.hasFocus, tcell.ColorWhite)
// Advance.
posY++

10
util.go

@ -646,12 +646,16 @@ const (
)
// RenderScrollBar renders a scroll bar character at the specified position.
func RenderScrollBar(screen tcell.Screen, x int, y int, height int, items int, cursor int, printed int, focused bool, color tcell.Color) {
// Do not render a scroll bar when all items are visible.
if items <= height {
func RenderScrollBar(screen tcell.Screen, visibility ScrollBarVisibility, x int, y int, height int, items int, cursor int, printed int, focused bool, color tcell.Color) {
if visibility == ScrollBarNever || (visibility == ScrollBarAuto && items <= height) {
return
}
// Place cursor at top when there are no items offscreen.
if items <= height {
cursor = 0
}
// Handle negative cursor.
if cursor < 0 {
cursor = 0

Loading…
Cancel
Save