From cab3771e17286788913255a6abe858b476166837 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Feb 2018 21:17:26 -0500 Subject: Pull main aerc UI into widget --- lib/ui/ui.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lib/ui/ui.go') diff --git a/lib/ui/ui.go b/lib/ui/ui.go index 9ea037c..e9b4e9b 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -8,16 +8,16 @@ import ( type UI struct { Exit bool - Content Drawable + Content DrawableInteractive ctx *Context - interactive []Interactive - tbEvents chan tb.Event invalidations chan interface{} } -func Initialize(conf *config.AercConfig, content Drawable) (*UI, error) { +func Initialize(conf *config.AercConfig, + content DrawableInteractive) (*UI, error) { + if err := tb.Init(); err != nil { return nil, err } @@ -52,6 +52,7 @@ func (state *UI) Tick() bool { case event := <-state.tbEvents: switch event.Type { case tb.EventKey: + // TODO: temporary if event.Key == tb.KeyEsc { state.Exit = true } @@ -60,11 +61,7 @@ func (state *UI) Tick() bool { state.ctx = NewContext(event.Width, event.Height) state.Content.Invalidate() } - if state.interactive != nil { - for _, i := range state.interactive { - i.Event(event) - } - } + state.Content.Event(event) case <-state.invalidations: state.Content.Draw(state.ctx) tb.Flush() @@ -73,7 +70,3 @@ func (state *UI) Tick() bool { } return true } - -func (state *UI) AddInteractive(i Interactive) { - state.interactive = append(state.interactive, i) -} -- cgit 1.4.1-2-gfad0