aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui
diff options
context:
space:
mode:
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 00000000..3c6f0a52
--- /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 8bdf592c..efab8282 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 9ea037c3..e9b4e9b5 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)
-}