restructure compact widgets

This commit is contained in:
Bradley Cicenas
2017-03-06 00:15:32 +00:00
parent 3172f141f9
commit 52a3e61b92
7 changed files with 121 additions and 109 deletions

View File

@@ -5,28 +5,26 @@ import (
)
type CompactHeader struct {
pars []*ui.Par
X, Y int
Width int
Height int
pars []*ui.Par
}
func NewCompactHeader() *CompactHeader {
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX"}
header := &CompactHeader{}
for _, f := range fields {
header.pars = append(header.pars, slimHeaderPar(f))
header.pars = append(header.pars, headerPar(f))
}
return header
}
func (c *CompactHeader) SetWidth(w int) {
if w == c.Width {
return
}
x := 1
autoWidth := calcWidth(w, 5)
for n, col := range c.pars {
// set status column to static width
if n == 0 {
col.SetX(x)
col.SetWidth(statusWidth)
@@ -41,9 +39,6 @@ func (c *CompactHeader) SetWidth(w int) {
}
func (c *CompactHeader) SetY(y int) {
if y == c.Y {
return
}
for _, p := range c.pars {
p.SetY(y)
}
@@ -57,3 +52,12 @@ func (c *CompactHeader) Buffer() ui.Buffer {
}
return buf
}
func headerPar(s string) *ui.Par {
p := ui.NewPar(s)
p.Y = 2
p.Height = 2
p.Width = 20
p.Border = false
return p
}