summary refs log tree commit diff stats
path: root/widgets/msglist.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-14 21:37:00 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-14 21:37:00 -0400
commit0f8b7a1203309ebec0dc78baf3f195671eadac2d (patch)
treefce6d8148cdbfa5ecfb2030a902f5a0763bb3643 /widgets/msglist.go
parentb3896476a0e6978c0d7f6fedfb64588934a78f1e (diff)
downloadaerc-0f8b7a1203309ebec0dc78baf3f195671eadac2d.tar.gz
Lay out message list widget basic design
Diffstat (limited to 'widgets/msglist.go')
-rw-r--r--widgets/msglist.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 370ba85..8e3c2eb 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -1,6 +1,12 @@
 package widgets
 
 import (
+	"log"
+
+	"github.com/gdamore/tcell"
+
+	"git.sr.ht/~sircmpwn/aerc2/config"
+	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
 	"git.sr.ht/~sircmpwn/aerc2/worker/types"
 )
 
@@ -34,3 +40,86 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
 		break
 	}
 }
+
+type MessageList struct {
+	conf         *config.AercConfig
+	logger       *log.Logger
+	onInvalidate func(d ui.Drawable)
+	spinner      *Spinner
+	store        *MessageStore
+	worker       *types.Worker
+}
+
+// TODO: fish in config
+func NewMessageList(logger *log.Logger, worker *types.Worker) *MessageList {
+	ml := &MessageList{
+		logger:  logger,
+		spinner: NewSpinner(),
+		worker:  worker,
+	}
+	ml.spinner.OnInvalidate(func(_ ui.Drawable) {
+		ml.Invalidate()
+	})
+	// TODO: stop spinner, probably
+	ml.spinner.Start()
+	return ml
+}
+
+func (ml *MessageList) OnInvalidate(onInvalidate func(d ui.Drawable)) {
+	ml.onInvalidate = onInvalidate
+}
+
+func (ml *MessageList) Invalidate() {
+	if ml.onInvalidate != nil {
+		ml.onInvalidate(ml)
+	}
+}
+
+func (ml *MessageList) Draw(ctx *ui.Context) {
+	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+
+	if ml.store == nil {
+		ml.spinner.Draw(ctx)
+		return
+	}
+
+	var (
+		needsHeaders []uint64
+		row          int = 0
+	)
+
+	for uid, msg := range ml.store.Messages {
+		if row >= ctx.Height() {
+			break
+		}
+
+		if msg == nil {
+			needsHeaders = append(needsHeaders, uid)
+			ml.spinner.Draw(ctx.Subcontext(0, row, ctx.Width(), 1))
+		}
+
+		row += 1
+	}
+
+	if len(needsHeaders) != 0 {
+		ml.spinner.Start()
+	} else {
+		ml.spinner.Stop()
+	}
+
+	// TODO: Fetch these messages
+}
+
+func (ml *MessageList) SetStore(store *MessageStore) {
+	if ml.store == store {
+		return
+	}
+
+	ml.store = store
+	if store != nil {
+		ml.spinner.Stop()
+	} else {
+		ml.spinner.Start()
+	}
+	ml.Invalidate()
+}