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

View File

@@ -11,23 +11,45 @@ type CTopHeader struct {
Time *ui.Par
Count *ui.Par
Filter *ui.Par
bg *ui.Par
}
func NewCTopHeader() *CTopHeader {
return &CTopHeader{
Time: headerPar(timeStr()),
Count: headerPar("-"),
Filter: headerPar(""),
Time: headerPar(2, timeStr()),
Count: headerPar(22, "-"),
Filter: headerPar(42, ""),
bg: headerBg(),
}
}
func (c *CTopHeader) Row() *ui.Row {
func (c *CTopHeader) Render() {
c.Time.Text = timeStr()
return ui.NewRow(
ui.NewCol(2, 0, c.Time),
ui.NewCol(2, 0, c.Count),
ui.NewCol(8, 0, c.Filter),
)
ui.Render(c.bg)
ui.Render(c.Time, c.Count, 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) {
@@ -46,8 +68,9 @@ func timeStr() string {
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.X = x
p.Border = false
p.Height = 1
p.Width = 20