about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-06-11 19:23:09 -0400
committerDrew DeVault <sir@cmpwn.com>2018-06-11 19:23:09 -0400
commit1c41b63f08d9b46ed558b0b3470cd2a2a9dfaf97 (patch)
tree22240b2d97d940968f2be4ced794083729550652
parente463c38476b96be99b4ae08af4db9e92da9d2a50 (diff)
downloadaerc-1c41b63f08d9b46ed558b0b3470cd2a2a9dfaf97.tar.gz
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
-rw-r--r--lib/ui/stack.go8
-rw-r--r--widgets/aerc.go45
2 files changed, 33 insertions, 20 deletions
diff --git a/lib/ui/stack.go b/lib/ui/stack.go
index 3c66f5a..2b97e78 100644
--- a/lib/ui/stack.go
+++ b/lib/ui/stack.go
@@ -8,7 +8,7 @@ import (
 
 type Stack struct {
 	children []Drawable
-	onInvalidate func(d Drawable)
+	onInvalidate []func(d Drawable)
 }
 
 func NewStack() *Stack {
@@ -16,12 +16,12 @@ func NewStack() *Stack {
 }
 
 func (stack *Stack) OnInvalidate(onInvalidate func (d Drawable)) {
-	stack.onInvalidate = onInvalidate
+	stack.onInvalidate = append(stack.onInvalidate, onInvalidate)
 }
 
 func (stack *Stack) Invalidate() {
-	if stack.onInvalidate != nil {
-		stack.onInvalidate(stack)
+	for _, fn := range stack.onInvalidate {
+		fn(stack)
 	}
 }
 
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 19ddfdd..798a4dd 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -20,33 +20,46 @@ type Aerc struct {
 
 func NewAerc(logger *log.Logger) *Aerc {
 	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_WEIGHT, 1},
-		libui.GridSpec{libui.SIZE_EXACT, 1},
 	}).Columns([]libui.GridSpec{
 		libui.GridSpec{libui.SIZE_EXACT, 20},
 		libui.GridSpec{libui.SIZE_WEIGHT, 1},
 	})
 
-	// TODO: move sidebar into tab content, probably
-	grid.AddChild(libui.NewText("aerc").
+	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))
-	// 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)
+	mainGrid.AddChild(tabs.TabStrip).At(0, 1)
+	mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)
 
-	statusbar := libui.NewStack()
-	grid.AddChild(statusbar).At(2, 1)
+	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},
+		}).Columns([]libui.GridSpec{
+			libui.GridSpec{libui.SIZE_EXACT, 20},
+			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)
+	}
 
-	statusline := NewStatusLine()
-	statusbar.Push(statusline)
+	acctPlaceholder('.', '★', "白い星")
+	acctPlaceholder(',', '☆', "empty stars")
 
 	go (func() {
 		for {
@@ -56,7 +69,7 @@ func NewAerc(logger *log.Logger) *Aerc {
 	})()
 
 	return &Aerc{
-		grid:        grid,
+		grid:        mainGrid,
 		statusbar:   statusbar,
 		statusline:  statusline,
 		tabs:        tabs,