Move sidebar into account tabs

This is accomplished through a bit of a hack, the statusbar is able to
be a child of multiple dudes
This commit is contained in:
Drew DeVault 2018-06-11 19:23:09 -04:00
parent e463c38476
commit 1c41b63f08
2 changed files with 34 additions and 21 deletions

View File

@ -8,7 +8,7 @@ import (
type Stack struct { type Stack struct {
children []Drawable children []Drawable
onInvalidate func(d Drawable) onInvalidate []func(d Drawable)
} }
func NewStack() *Stack { func NewStack() *Stack {
@ -16,12 +16,12 @@ func NewStack() *Stack {
} }
func (stack *Stack) OnInvalidate(onInvalidate func (d Drawable)) { func (stack *Stack) OnInvalidate(onInvalidate func (d Drawable)) {
stack.onInvalidate = onInvalidate stack.onInvalidate = append(stack.onInvalidate, onInvalidate)
} }
func (stack *Stack) Invalidate() { func (stack *Stack) Invalidate() {
if stack.onInvalidate != nil { for _, fn := range stack.onInvalidate {
stack.onInvalidate(stack) fn(stack)
} }
} }

View File

@ -20,33 +20,46 @@ type Aerc struct {
func NewAerc(logger *log.Logger) *Aerc { func NewAerc(logger *log.Logger) *Aerc {
tabs := libui.NewTabs() tabs := libui.NewTabs()
tabs.Add(libui.NewFill('★'), "白い星")
tabs.Add(libui.NewFill('☆'), "empty stars")
grid := libui.NewGrid().Rows([]libui.GridSpec{ mainGrid := libui.NewGrid().Rows([]libui.GridSpec{
libui.GridSpec{libui.SIZE_EXACT, 1}, libui.GridSpec{libui.SIZE_EXACT, 1},
libui.GridSpec{libui.SIZE_WEIGHT, 1}, libui.GridSpec{libui.SIZE_WEIGHT, 1},
}).Columns([]libui.GridSpec{
libui.GridSpec{libui.SIZE_EXACT, 20},
libui.GridSpec{libui.SIZE_WEIGHT, 1},
})
statusbar := libui.NewStack()
statusline := NewStatusLine()
statusbar.Push(statusline)
// TODO: Grab sidebar size from config and via :set command
mainGrid.AddChild(libui.NewText("aerc").
Strategy(libui.TEXT_CENTER).
Color(tcell.ColorBlack, tcell.ColorWhite))
mainGrid.AddChild(tabs.TabStrip).At(0, 1)
mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)
acctPlaceholder := func(sidebar, body rune, name string) {
accountGrid := libui.NewGrid().Rows([]libui.GridSpec{
libui.GridSpec{libui.SIZE_WEIGHT, 1},
libui.GridSpec{libui.SIZE_EXACT, 1}, libui.GridSpec{libui.SIZE_EXACT, 1},
}).Columns([]libui.GridSpec{ }).Columns([]libui.GridSpec{
libui.GridSpec{libui.SIZE_EXACT, 20}, libui.GridSpec{libui.SIZE_EXACT, 20},
libui.GridSpec{libui.SIZE_WEIGHT, 1}, libui.GridSpec{libui.SIZE_WEIGHT, 1},
}) })
// Sidebar placeholder
accountGrid.AddChild(libui.NewBordered(
libui.NewFill(sidebar), libui.BORDER_RIGHT)).Span(2, 1)
// Message list placeholder
accountGrid.AddChild(libui.NewFill(body)).At(0, 1)
// Statusbar
accountGrid.AddChild(statusbar).At(1, 1)
tabs.Add(accountGrid, name)
}
// TODO: move sidebar into tab content, probably acctPlaceholder('.', '★', "白い星")
grid.AddChild(libui.NewText("aerc"). acctPlaceholder(',', '☆', "empty stars")
Strategy(libui.TEXT_CENTER).
Color(tcell.ColorBlack, tcell.ColorWhite))
// sidebar placeholder:
grid.AddChild(libui.NewBordered(
libui.NewFill('.'), libui.BORDER_RIGHT)).At(1, 0).Span(2, 1)
grid.AddChild(tabs.TabStrip).At(0, 1)
grid.AddChild(tabs.TabContent).At(1, 1)
statusbar := libui.NewStack()
grid.AddChild(statusbar).At(2, 1)
statusline := NewStatusLine()
statusbar.Push(statusline)
go (func() { go (func() {
for { for {
@ -56,7 +69,7 @@ func NewAerc(logger *log.Logger) *Aerc {
})() })()
return &Aerc{ return &Aerc{
grid: grid, grid: mainGrid,
statusbar: statusbar, statusbar: statusbar,
statusline: statusline, statusline: statusline,
tabs: tabs, tabs: tabs,