From a6ee6edb1d38199d192d718434a7af73ea051221 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Wed, 8 Mar 2017 11:52:31 +1100 Subject: [PATCH] move MaxRows() method into cgrid --- cursor.go | 6 +++--- cwidgets/compact/grid.go | 1 + grid.go | 10 +++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cursor.go b/cursor.go index 1aee202..5f349ed 100644 --- a/cursor.go +++ b/cursor.go @@ -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] diff --git a/cwidgets/compact/grid.go b/cwidgets/compact/grid.go index a48dee0..43503e8 100644 --- a/cwidgets/compact/grid.go +++ b/cwidgets/compact/grid.go @@ -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() diff --git a/grid.go b/grid.go index 872330a..ff72b0e 100644 --- a/grid.go +++ b/grid.go @@ -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) })