blob: d203c3fa668f968a59c343bd83932f63d5865431 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package layout
import (
"fmt"
"image"
"image/draw"
)
type EventDrawer interface {
Event() <-chan EventConsume
Draw(func(draw.Image) image.Rectangle)
}
type EventConsume struct {
Event
Consume chan<- bool
}
type Event string
func (e Event) Matches(format string, a ...interface{}) bool {
_, err := fmt.Sscanf(string(e), format, a...)
return err == nil
}
func SendEvent(ch chan<- EventConsume, format string, a ...interface{}) (consume <-chan bool) {
cons := make(chan bool)
ch <- EventConsume{Event(fmt.Sprintf(format, a...)), cons}
return cons
}
|