render global header independent of grid rows

This commit is contained in:
Bradley Cicenas
2017-02-18 14:31:50 +11:00
parent 3c28137873
commit 0e8480ce5d
2 changed files with 42 additions and 24 deletions

23
grid.go
View File

@@ -76,9 +76,12 @@ func (g *Grid) redrawRows() {
// build layout // build layout
if config.GetSwitchVal("enableHeader") { if config.GetSwitchVal("enableHeader") {
ui.Body.Y = g.header.Height()
g.header.SetCount(len(g.containers)) g.header.SetCount(len(g.containers))
g.header.SetFilter(config.GetVal("filterStr")) g.header.SetFilter(config.GetVal("filterStr"))
ui.Body.AddRows(g.header.Row()) g.header.Render()
} else {
ui.Body.Y = 0
} }
ui.Body.AddRows(fieldHeader()) ui.Body.AddRows(fieldHeader())
for _, c := range g.containers { for _, c := range g.containers {
@@ -100,10 +103,7 @@ func (g *Grid) redrawRows() {
func resizeIndicator() { func resizeIndicator() {
xShift := 1 xShift := 1
toWidth := 3 toWidth := 3
for i, r := range ui.Body.Rows { for _, r := range ui.Body.Rows {
if config.GetSwitchVal("enableHeader") && i == 0 {
continue
}
wDiff := r.Cols[0].Width - (toWidth + xShift) wDiff := r.Cols[0].Width - (toWidth + xShift)
// set indicator x, width // set indicator x, width
r.Cols[0].SetX(xShift) r.Cols[0].SetX(xShift)
@@ -137,14 +137,10 @@ func headerPar(s string) *ui.Par {
return p return p
} }
func ResetView() {
ui.DefaultEvtStream.ResetHandlers()
ui.Clear()
}
func (g *Grid) ExpandView() { func (g *Grid) ExpandView() {
ResetView() ui.Clear()
defer ResetView() ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
container := g.cmap.Get(g.cursorID) container := g.cmap.Get(g.cursorID)
container.Expand() container.Expand()
container.widgets.Render() container.widgets.Render()
@@ -167,8 +163,7 @@ func Display(g *Grid) bool {
ui.DefaultEvtStream.Hook(logEvent) ui.DefaultEvtStream.Hook(logEvent)
// calculate layout // initial draw
ui.Body.Align()
g.redrawCursor() g.redrawCursor()
g.redrawRows() g.redrawRows()

View File

@@ -11,23 +11,45 @@ type CTopHeader struct {
Time *ui.Par Time *ui.Par
Count *ui.Par Count *ui.Par
Filter *ui.Par Filter *ui.Par
bg *ui.Par
} }
func NewCTopHeader() *CTopHeader { func NewCTopHeader() *CTopHeader {
return &CTopHeader{ return &CTopHeader{
Time: headerPar(timeStr()), Time: headerPar(2, timeStr()),
Count: headerPar("-"), Count: headerPar(22, "-"),
Filter: headerPar(""), Filter: headerPar(42, ""),
bg: headerBg(),
} }
} }
func (c *CTopHeader) Row() *ui.Row { func (c *CTopHeader) Render() {
c.Time.Text = timeStr() c.Time.Text = timeStr()
return ui.NewRow( ui.Render(c.bg)
ui.NewCol(2, 0, c.Time), ui.Render(c.Time, c.Count, c.Filter)
ui.NewCol(2, 0, c.Count), }
ui.NewCol(8, 0, c.Filter),
) func (c *CTopHeader) Height() int {
return c.bg.Height
}
func headerBgBordered() *ui.Par {
bg := ui.NewPar("")
bg.X = 1
bg.Width = ui.TermWidth() - 1
bg.Height = 3
bg.Bg = ui.ColorWhite
return bg
}
func headerBg() *ui.Par {
bg := ui.NewPar("")
bg.X = 1
bg.Width = ui.TermWidth() - 1
bg.Height = 1
bg.Border = false
bg.Bg = ui.ColorWhite
return bg
} }
func (c *CTopHeader) SetCount(val int) { func (c *CTopHeader) SetCount(val int) {
@@ -46,8 +68,9 @@ func timeStr() string {
return time.Now().Local().Format("15:04:05 MST") return time.Now().Local().Format("15:04:05 MST")
} }
func headerPar(s string) *ui.Par { func headerPar(x int, s string) *ui.Par {
p := ui.NewPar(fmt.Sprintf(" %s", s)) p := ui.NewPar(fmt.Sprintf(" %s", s))
p.X = x
p.Border = false p.Border = false
p.Height = 1 p.Height = 1
p.Width = 20 p.Width = 20