Add a scroll location indicator to the process table
This commit is contained in:
parent
ade4f2a623
commit
0f2a5d1e9a
|
@ -1,6 +1,7 @@
|
|||
package termui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
"strings"
|
||||
|
@ -21,6 +22,8 @@ type Table struct {
|
|||
ShowCursor bool
|
||||
CursorColor Color
|
||||
|
||||
ShowLocation bool
|
||||
|
||||
UniqueCol int // the column used to uniquely identify each table row
|
||||
SelectedItem string // used to keep the cursor on the correct item if the data changes
|
||||
SelectedRow int
|
||||
|
@ -43,6 +46,10 @@ func NewTable() *Table {
|
|||
func (self *Table) Draw(buf *Buffer) {
|
||||
self.Block.Draw(buf)
|
||||
|
||||
if self.ShowLocation {
|
||||
self.drawLocation(buf)
|
||||
}
|
||||
|
||||
self.ColResizer()
|
||||
|
||||
// finds exact column starting position
|
||||
|
@ -121,6 +128,21 @@ func (self *Table) Draw(buf *Buffer) {
|
|||
}
|
||||
}
|
||||
|
||||
// drawLoca
|
||||
func (self *Table) drawLocation(buf *Buffer) {
|
||||
total := len(self.Rows)
|
||||
topRow := self.TopRow + 1
|
||||
bottomRow := self.TopRow + self.Inner.Dy() - 1
|
||||
if bottomRow > total {
|
||||
bottomRow = total
|
||||
}
|
||||
|
||||
loc := fmt.Sprintf(" %d - %d of %d ", topRow, bottomRow, total)
|
||||
|
||||
width := len(loc)
|
||||
buf.SetString(loc, self.TitleStyle, image.Pt(self.Max.X-width-2, self.Min.Y))
|
||||
}
|
||||
|
||||
// Scrolling ///////////////////////////////////////////////////////////////////
|
||||
|
||||
// calcPos is used to calculate the cursor position and the current view into the table.
|
||||
|
|
|
@ -59,6 +59,7 @@ func NewProcWidget() *ProcWidget {
|
|||
}
|
||||
self.Title = " Processes "
|
||||
self.ShowCursor = true
|
||||
self.ShowLocation = true
|
||||
self.ColGap = 3
|
||||
self.PadLeft = 2
|
||||
self.ColResizer = func() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user