2017-02-26 22:04:24 +00:00
|
|
|
package compact
|
|
|
|
|
|
|
|
import (
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CompactGrid struct {
|
|
|
|
ui.GridBufferer
|
2017-03-03 07:57:26 +00:00
|
|
|
Rows []*Compact // rows to render
|
2017-02-26 22:55:45 +00:00
|
|
|
X, Y int
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
header *CompactHeader
|
|
|
|
cursorID string
|
2017-02-26 22:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewCompactGrid() *CompactGrid {
|
|
|
|
return &CompactGrid{
|
|
|
|
header: NewCompactHeader(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 07:57:26 +00:00
|
|
|
func (cg *CompactGrid) Align() {
|
2017-02-26 22:04:24 +00:00
|
|
|
// Update y recursively
|
2017-03-03 07:57:26 +00:00
|
|
|
cg.header.SetY(cg.Y)
|
|
|
|
y := cg.Y + 1
|
2017-03-05 06:46:41 +00:00
|
|
|
for _, r := range cg.Rows {
|
|
|
|
r.SetY(y)
|
|
|
|
y += r.Height
|
2017-02-26 22:04:24 +00:00
|
|
|
}
|
|
|
|
// Update width recursively
|
2017-03-03 07:57:26 +00:00
|
|
|
cg.header.SetWidth(cg.Width)
|
|
|
|
for _, r := range cg.Rows {
|
|
|
|
r.SetWidth(cg.Width)
|
2017-02-26 22:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 07:57:26 +00:00
|
|
|
func (cg *CompactGrid) Clear() { cg.Rows = []*Compact{} }
|
|
|
|
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 }
|
2017-02-26 22:04:24 +00:00
|
|
|
|
2017-03-03 07:57:26 +00:00
|
|
|
func (cg *CompactGrid) Buffer() ui.Buffer {
|
2017-02-26 22:04:24 +00:00
|
|
|
buf := ui.NewBuffer()
|
2017-03-03 07:57:26 +00:00
|
|
|
buf.Merge(cg.header.Buffer())
|
|
|
|
for _, r := range cg.Rows {
|
2017-02-26 22:04:24 +00:00
|
|
|
buf.Merge(r.Buffer())
|
|
|
|
}
|
|
|
|
return buf
|
|
|
|
}
|
2017-03-03 07:57:26 +00:00
|
|
|
|
|
|
|
func (cg *CompactGrid) AddRows(rows ...*Compact) {
|
|
|
|
for _, r := range rows {
|
|
|
|
cg.Rows = append(cg.Rows, r)
|
|
|
|
}
|
|
|
|
}
|