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