aboutsummaryrefslogtreecommitdiffstats
path: root/layout/interface.go
diff options
context:
space:
mode:
Diffstat (limited to 'layout/interface.go')
-rw-r--r--layout/interface.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/layout/interface.go b/layout/interface.go
new file mode 100644
index 0000000..1dcf34a
--- /dev/null
+++ b/layout/interface.go
@@ -0,0 +1,40 @@
+package layout
+
+import (
+ "fmt"
+ "image"
+ "image/draw"
+)
+
+type EventDrawer interface {
+ Event() <-chan EventConsume
+ Draw() chan<- ImageFlush
+}
+
+type EventConsume struct {
+ Event string
+ Consume chan<- bool
+}
+
+func SendEvent(ch chan<- EventConsume, format string, a ...interface{}) (consume <-chan bool) {
+ cons := make(chan bool)
+ ch <- EventConsume{fmt.Sprintf(format, a...), cons}
+ return cons
+}
+
+func (ec EventConsume) Matches(format string, a ...interface{}) bool {
+ _, err := fmt.Sscanf(ec.Event, format, a...)
+ return err == nil
+}
+
+type ImageFlush struct {
+ Image chan<- draw.Image
+ Flush <-chan image.Rectangle
+}
+
+func SendDraw(ch chan<- ImageFlush) (img <-chan draw.Image, flush chan<- image.Rectangle) {
+ imgC := make(chan draw.Image)
+ flushC := make(chan image.Rectangle)
+ ch <- ImageFlush{imgC, flushC}
+ return imgC, flushC
+}