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 Cpu *Cpu
Mem *Mem Mem *Mem
IO *IO IO *IO
X, Y int
Width int Width int
} }
@ -35,14 +36,25 @@ func NewExpanded(id string) *Expanded {
} }
} }
func (e *Expanded) SetWidth(w int) { func (e *Expanded) Up() {
e.Width = w if e.Y < 0 {
e.Y++
e.Align()
ui.Render(e)
}
} }
func (e *Expanded) SetMeta(k, v string) { func (e *Expanded) Down() {
e.Info.Set(k, v) 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) { func (e *Expanded) SetMetrics(m metrics.Metrics) {
e.Cpu.Update(m.CPUUtil) e.Cpu.Update(m.CPUUtil)
e.Net.Update(m.NetRx, m.NetTx) 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) 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() { 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() { for _, i := range e.all() {
i.SetY(y) i.SetY(y)
y += i.GetHeight() y += i.GetHeight()
} }
if e.Width > colWidth[0] { if e.Width > colWidth[0] {
colWidth[1] = e.Width - (colWidth[0] + 1) colWidth[1] = e.Width - (colWidth[0] + 1)
} }

View File

@ -44,6 +44,8 @@ func ExpandView(c *Container) {
ex.Align() ex.Align()
ui.Render(ex) 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.Handle("/timer/1s", func(ui.Event) {
ui.Render(ex) ui.Render(ex)
}) })