mirror of
https://github.com/bcicen/ctop.git
synced 2025-11-12 22:25:40 +01:00
refactor all container widgets into subpackage
This commit is contained in:
50
cwidgets/compact/grid.go
Normal file
50
cwidgets/compact/grid.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package compact
|
||||
|
||||
import (
|
||||
"github.com/bcicen/ctop/cwidgets"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type CompactGrid struct {
|
||||
ui.GridBufferer
|
||||
Rows []cwidgets.ContainerWidgets
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
header *CompactHeader
|
||||
}
|
||||
|
||||
func NewCompactGrid() *CompactGrid {
|
||||
return &CompactGrid{
|
||||
header: NewCompactHeader(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CompactGrid) Align() {
|
||||
// Update y recursively
|
||||
c.header.SetY(c.Y)
|
||||
y := c.Y + 1
|
||||
for n, r := range c.Rows {
|
||||
r.SetY(y + n)
|
||||
}
|
||||
// Update width recursively
|
||||
c.header.SetWidth(c.Width)
|
||||
for _, r := range c.Rows {
|
||||
r.SetWidth(c.Width)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CompactGrid) Clear() { c.Rows = []cwidgets.ContainerWidgets{} }
|
||||
func (c *CompactGrid) GetHeight() int { return len(c.Rows) }
|
||||
func (c *CompactGrid) SetX(x int) { c.X = x }
|
||||
func (c *CompactGrid) SetY(y int) { c.Y = y }
|
||||
func (c *CompactGrid) SetWidth(w int) { c.Width = w }
|
||||
|
||||
func (c *CompactGrid) Buffer() ui.Buffer {
|
||||
buf := ui.NewBuffer()
|
||||
buf.Merge(c.header.Buffer())
|
||||
for _, r := range c.Rows {
|
||||
buf.Merge(r.Buffer())
|
||||
}
|
||||
return buf
|
||||
}
|
||||
Reference in New Issue
Block a user