ctop/cwidgets/compact/header.go

60 lines
969 B
Go
Raw Normal View History

package compact
import (
ui "github.com/gizak/termui"
)
type CompactHeader struct {
X, Y int
Width int
Height int
2019-07-05 23:05:21 +00:00
cols []CompactCol
widths []int
2017-03-06 00:15:32 +00:00
pars []*ui.Par
}
func NewCompactHeader() *CompactHeader {
2019-07-05 23:05:21 +00:00
return &CompactHeader{Height: 2}
}
2019-07-05 23:05:21 +00:00
func (row *CompactHeader) GetHeight() int {
return row.Height
}
2019-07-05 23:05:21 +00:00
func (row *CompactHeader) SetWidths(totalWidth int, widths []int) {
x := row.X
for n, w := range row.pars {
w.SetX(x)
w.SetWidth(widths[n])
x += widths[n] + colSpacing
}
2019-07-05 23:05:21 +00:00
row.Width = totalWidth
}
2019-07-05 23:05:21 +00:00
func (row *CompactHeader) SetX(x int) {
row.X = x
}
2019-07-05 23:05:21 +00:00
func (row *CompactHeader) SetY(y int) {
for _, p := range row.pars {
p.SetY(y)
}
2019-07-05 23:05:21 +00:00
row.Y = y
}
2019-07-05 23:05:21 +00:00
func (row *CompactHeader) Buffer() ui.Buffer {
buf := ui.NewBuffer()
2019-07-05 23:05:21 +00:00
for _, p := range row.pars {
buf.Merge(p.Buffer())
}
return buf
}
2017-03-06 00:15:32 +00:00
2019-07-05 23:05:21 +00:00
func (row *CompactHeader) addFieldPar(s string) {
2017-03-06 00:15:32 +00:00
p := ui.NewPar(s)
2019-07-05 23:05:21 +00:00
p.Height = row.Height
2017-03-06 00:15:32 +00:00
p.Border = false
2019-07-05 23:05:21 +00:00
row.pars = append(row.pars, p)
2017-03-06 00:15:32 +00:00
}