add y pos scrolling to expanded view

This commit is contained in:
Bradley Cicenas 2017-03-12 20:53:17 +00:00
parent 8327406069
commit 12fa716825
2 changed files with 35 additions and 5 deletions

View File

@ -18,6 +18,7 @@ type Expanded struct {
Cpu *Cpu
Mem *Mem
IO *IO
X, Y int
Width int
}
@ -35,14 +36,25 @@ func NewExpanded(id string) *Expanded {
}
}
func (e *Expanded) SetWidth(w int) {
e.Width = w
func (e *Expanded) Up() {
if e.Y < 0 {
e.Y++
e.Align()
ui.Render(e)
}
}
func (e *Expanded) SetMeta(k, v string) {
e.Info.Set(k, v)
func (e *Expanded) Down() {
if e.Y > (ui.TermHeight() - e.GetHeight()) {
e.Y--
e.Align()
ui.Render(e)
}
}
func (e *Expanded) SetWidth(w int) { e.Width = w }
func (e *Expanded) SetMeta(k, v string) { e.Info.Set(k, v) }
func (e *Expanded) SetMetrics(m metrics.Metrics) {
e.Cpu.Update(m.CPUUtil)
e.Net.Update(m.NetRx, m.NetTx)
@ -50,12 +62,28 @@ func (e *Expanded) SetMetrics(m metrics.Metrics) {
e.IO.Update(m.IOBytesRead, m.IOBytesWrite)
}
// Return total column height
func (e *Expanded) GetHeight() (h int) {
h += e.Info.Height
h += e.Net.Height
h += e.Cpu.Height
h += e.Mem.Height
h += e.IO.Height
return h
}
func (e *Expanded) Align() {
y := 0
// reset offset if needed
if e.GetHeight() <= ui.TermHeight() {
e.Y = 0
}
y := e.Y
for _, i := range e.all() {
i.SetY(y)
y += i.GetHeight()
}
if e.Width > colWidth[0] {
colWidth[1] = e.Width - (colWidth[0] + 1)
}

View File

@ -44,6 +44,8 @@ func ExpandView(c *Container) {
ex.Align()
ui.Render(ex)
ui.Handle("/sys/kbd/<up>", func(ui.Event) { ex.Up() })
ui.Handle("/sys/kbd/<down>", func(ui.Event) { ex.Down() })
ui.Handle("/timer/1s", func(ui.Event) {
ui.Render(ex)
})