You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lntop/ui/views/views.go

67 lines
1.1 KiB
Go

5 years ago
package views
5 years ago
import (
"github.com/edouardparis/lntop/ui/models"
"github.com/jroimartin/gocui"
)
5 years ago
type view interface {
Set(*gocui.Gui, int, int, int, int) error
Name() string
}
5 years ago
type Views struct {
Previous view
Help *Help
5 years ago
Header *Header
Summary *Summary
Channels *Channels
5 years ago
Channel *Channel
5 years ago
Footer *Footer
}
func (v Views) Get(name string) view {
switch name {
case CHANNELS:
return v.Channels
case HELP:
return v.Help
default:
return nil
}
}
func (v *Views) SetPrevious(p view) {
v.Previous = p
}
5 years ago
func (v *Views) Layout(g *gocui.Gui, maxX, maxY int) error {
err := v.Header.Set(g, 0, -1, maxX, 1)
if err != nil {
return err
}
err = v.Summary.Set(g, 0, 1, maxX, 6)
if err != nil {
return err
}
err = v.Channels.Set(g, 0, 6, maxX-1, maxY-1)
if err != nil {
return err
}
return v.Footer.Set(g, 0, maxY-2, maxX, maxY)
}
5 years ago
func New(m *models.Models) *Views {
5 years ago
return &Views{
5 years ago
Header: NewHeader(m.Info),
5 years ago
Footer: NewFooter(),
Help: NewHelp(),
5 years ago
Summary: NewSummary(m.Info, m.ChannelsBalance, m.WalletBalance, m.Channels),
Channels: NewChannels(m.Channels),
5 years ago
Channel: NewChannel(m.CurrentChannel),
5 years ago
}
}