summary refs log blame commit diff stats
path: root/widgets/aerc.go
blob: cd4b77364655a4aabbfbfac17933ad5c357d785e (plain) (tree)
1
2
3
4
5
6
7
8



               
 
                                  
 
                                          



                                                


                                        

 
                                                                 
                               
 
                                                          

                                       
                                    

                                       

          

                                                                   
                                            
                                                          

                                                              
 

                                              
                                            
                                                     
                                       
                                         
         
 
                     


                                   



                                                                     


                                                       









                                            
                                                 

                                                                            
 
package widgets

import (
	"log"

	"github.com/gdamore/tcell"

	"git.sr.ht/~sircmpwn/aerc2/config"
	libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
)

type Aerc struct {
	accounts map[string]*AccountView
	grid     *libui.Grid
	tabs     *libui.Tabs
}

func NewAerc(conf *config.AercConfig, logger *log.Logger) *Aerc {
	tabs := libui.NewTabs()

	mainGrid := libui.NewGrid().Rows([]libui.GridSpec{
		{libui.SIZE_EXACT, 1},
		{libui.SIZE_WEIGHT, 1},
	}).Columns([]libui.GridSpec{
		{libui.SIZE_EXACT, 20},
		{libui.SIZE_WEIGHT, 1},
	})

	// 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)

	accts := make(map[string]*AccountView)

	for _, acct := range conf.Accounts {
		view := NewAccountView(&acct, logger)
		accts[acct.Name] = view
		tabs.Add(view, acct.Name)
	}

	return &Aerc{
		accounts: accts,
		grid:     mainGrid,
		tabs:     tabs,
	}
}

func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
	aerc.grid.OnInvalidate(func(_ libui.Drawable) {
		onInvalidate(aerc)
	})
}

func (aerc *Aerc) Invalidate() {
	aerc.grid.Invalidate()
}

func (aerc *Aerc) Draw(ctx *libui.Context) {
	aerc.grid.Draw(ctx)
}

func (aerc *Aerc) Event(event tcell.Event) bool {
	acct, _ := aerc.tabs.Tabs[aerc.tabs.Selected].Content.(*AccountView)
	return acct.Event(event)
}
size_for_autopreview not working Ideas ( ) #20 10/01/01 use inotify to monitor filesystem changes ( ) #24 10/01/06 progress bar (X) #27 10/01/06 hide bookmarks in list which contain hidden dir (X) #28 10/01/06 use regexp instead of string for searching ( ) #33 10/01/08 accelerate mousewheel speed ( ) #45 10/01/18 hooks for events like setting changes ( ) #53 10/01/23 merge fm and environment