move MaxRows() method into cgrid

This commit is contained in:
Bradley Cicenas 2017-03-08 11:52:31 +11:00
parent d7f9f715bb
commit a6ee6edb1d
3 changed files with 7 additions and 10 deletions

View File

@ -87,9 +87,9 @@ func (gc *GridCursor) Down() {
if idx >= (gc.Len() - 1) {
return
}
if idx >= maxRows()-1 {
return
}
//if idx >= maxRows()-1 {
//return
//}
active := gc.containers[idx]
next := gc.containers[idx+1]

View File

@ -38,6 +38,7 @@ 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) Buffer() ui.Buffer {
buf := ui.NewBuffer()

10
grid.go
View File

@ -6,10 +6,6 @@ import (
ui "github.com/gizak/termui"
)
func maxRows() int {
return ui.TermHeight() - 2 - cGrid.Y
}
func RedrawRows(clr bool) {
// reinit body rows
cGrid.Clear()
@ -24,7 +20,7 @@ func RedrawRows(clr bool) {
cGrid.SetY(y)
var cursorVisible bool
max := maxRows()
max := cGrid.MaxRows()
for n, c := range cursor.filtered {
if n >= max {
break
@ -66,7 +62,7 @@ func ExpandView(c *Container) {
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
ex.SetWidth(ui.TermWidth())
ex.Align()
log.Infof("resize: width=%v max-rows=%v", ex.Width, maxRows())
log.Infof("resize: width=%v max-rows=%v", ex.Width, cGrid.MaxRows())
})
ui.Handle("/sys/kbd/", func(ui.Event) {
ui.StopLoop()
@ -141,7 +137,7 @@ func Display() bool {
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
header.Align()
cGrid.SetWidth(ui.TermWidth())
log.Infof("resize: width=%v max-rows=%v", cGrid.Width, maxRows())
log.Infof("resize: width=%v max-rows=%v", cGrid.Width, cGrid.MaxRows())
RedrawRows(true)
})