add pagination support for compact view

This commit is contained in:
Bradley Cicenas
2017-03-08 18:45:31 +11:00
parent a6ee6edb1d
commit 2b80832a36
3 changed files with 71 additions and 55 deletions

View File

@@ -8,11 +8,11 @@ var header = NewCompactHeader()
type CompactGrid struct {
ui.GridBufferer
Rows []ui.GridBufferer
X, Y int
Width int
Height int
cursorID string
Rows []ui.GridBufferer
X, Y int
Width int
Height int
Offset int // starting row offset
}
func NewCompactGrid() *CompactGrid {
@@ -20,29 +20,31 @@ func NewCompactGrid() *CompactGrid {
}
func (cg *CompactGrid) Align() {
// update row y pos recursively
// update row ypos, width recursively
y := cg.Y
for _, r := range cg.Rows {
for _, r := range cg.pageRows() {
r.SetY(y)
y += r.GetHeight()
}
// update row width recursively
for _, r := range cg.Rows {
r.SetWidth(cg.Width)
}
}
func (cg *CompactGrid) Clear() { cg.Rows = []ui.GridBufferer{header} }
func (cg *CompactGrid) Clear() { cg.Rows = []ui.GridBufferer{} }
func (cg *CompactGrid) GetHeight() int { return len(cg.Rows) }
func (cg *CompactGrid) SetX(x int) { cg.X = x }
func (cg *CompactGrid) SetY(y int) { cg.Y = y }
func (cg *CompactGrid) SetWidth(w int) { cg.Width = w }
func (cg *CompactGrid) MaxRows() int { return ui.TermHeight() - header.Height - cg.Y }
func (cg *CompactGrid) pageRows() (rows []ui.GridBufferer) {
rows = append(rows, header)
rows = append(rows, cg.Rows[cg.Offset:]...)
return rows
}
func (cg *CompactGrid) Buffer() ui.Buffer {
buf := ui.NewBuffer()
for _, r := range cg.Rows {
for _, r := range cg.pageRows() {
buf.Merge(r.Buffer())
}
return buf