summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-02-27 21:17:26 -0500
committerDrew DeVault <sir@cmpwn.com>2018-02-27 21:17:26 -0500
commitcab3771e17286788913255a6abe858b476166837 (patch)
tree85c626c779e380bb6a9d7ddd6cba69ef33cf919d /lib/ui
parenta073d7613fac7c79b7909d93a0dd7bfea05d5c9d (diff)
downloadaerc-cab3771e17286788913255a6abe858b476166837.tar.gz
Pull main aerc UI into widget
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/fill.go27
-rw-r--r--lib/ui/interactive.go5
-rw-r--r--lib/ui/ui.go19
3 files changed, 38 insertions, 13 deletions
diff --git a/lib/ui/fill.go b/lib/ui/fill.go
new file mode 100644
index 0000000..3c6f0a5
--- /dev/null
+++ b/lib/ui/fill.go
@@ -0,0 +1,27 @@
+package ui
+
+import (
+	tb "github.com/nsf/termbox-go"
+)
+
+type Fill rune
+
+func NewFill(f rune) Fill {
+	return Fill(f)
+}
+
+func (f Fill) Draw(ctx *Context) {
+	for x := 0; x < ctx.Width(); x += 1 {
+		for y := 0; y < ctx.Height(); y += 1 {
+			ctx.SetCell(x, y, rune(f), tb.ColorDefault, tb.ColorDefault)
+		}
+	}
+}
+
+func (f Fill) OnInvalidate(callback func(d Drawable)) {
+	// no-op
+}
+
+func (f Fill) Invalidate() {
+	// no-op
+}
diff --git a/lib/ui/interactive.go b/lib/ui/interactive.go
index 8bdf592..efab828 100644
--- a/lib/ui/interactive.go
+++ b/lib/ui/interactive.go
@@ -13,3 +13,8 @@ type Simulator interface {
 	// Queues up the given input events for simulation
 	Simulate(events []tb.Event)
 }
+
+type DrawableInteractive interface {
+	Drawable
+	Interactive
+}
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)
-}