aboutsummaryrefslogtreecommitdiffstats
path: root/env.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-08-24 17:13:44 -0400
committerSam Anthony <sam@samanthony.xyz>2024-08-24 17:13:44 -0400
commit0422e505333513beef8172cc79f2ec208293fc14 (patch)
tree5bc87db442c9c0a9cf92f5c37d651be471e83076 /env.go
parent9bf3236dc993a3d8dbf4caf14bd448ab4de70a72 (diff)
downloadgui-0422e505333513beef8172cc79f2ec208293fc14.zip
move functionality of makeEventsChan() to external library
Diffstat (limited to 'env.go')
-rw-r--r--env.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/env.go b/env.go
index f5f31cf..4094846 100644
--- a/env.go
+++ b/env.go
@@ -3,6 +3,8 @@ package gui
import (
"image"
"image/draw"
+
+ "git.samanthony.xyz/share"
)
// Env is the most important thing in this package. It is an interactive graphical
@@ -15,7 +17,7 @@ import (
//
// An Env guarantees to produce a "resize/<x0>/<y0>/<x1>/<y1>" event as its first event.
//
-// The Events() channel must be unlimited in capacity. Use makeEventsChan() to create
+// The Events() channel must be unlimited in capacity. Use share.Queue to create
// a channel of events with an unlimited capacity.
//
// The Draw() channel may be synchronous.
@@ -53,7 +55,7 @@ func newEnv(parent Env,
filterDraws func(func(draw.Image) image.Rectangle, chan<- func(draw.Image) image.Rectangle),
shutdown func(),
) Env {
- eventsOut, eventsIn := makeEventsChan()
+ events := share.NewQueue[Event]()
drawChan := make(chan func(draw.Image) image.Rectangle)
child := newAttachHandler()
kill := make(chan bool)
@@ -70,7 +72,7 @@ func newEnv(parent Env,
close(detachFromParent)
}()
defer shutdown()
- defer close(eventsIn)
+ defer close(events.Enqueue)
defer close(drawChan)
defer close(kill)
defer func() {
@@ -82,7 +84,7 @@ func newEnv(parent Env,
for {
select {
case e := <-parent.Events():
- filterEvents(e, eventsIn)
+ filterEvents(e, events.Enqueue)
case d := <-drawChan:
filterDraws(d, parent.Draw())
case <-kill:
@@ -92,7 +94,7 @@ func newEnv(parent Env,
}()
e := env{
- events: eventsOut,
+ events: events.Dequeue,
draw: drawChan,
attachChan: child.attach(),
kill: kill,