diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-08-24 17:13:44 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-08-24 17:13:44 -0400 |
| commit | 0422e505333513beef8172cc79f2ec208293fc14 (patch) | |
| tree | 5bc87db442c9c0a9cf92f5c37d651be471e83076 /mux.go | |
| parent | 9bf3236dc993a3d8dbf4caf14bd448ab4de70a72 (diff) | |
| download | gui-0422e505333513beef8172cc79f2ec208293fc14.zip | |
move functionality of makeEventsChan() to external library
Diffstat (limited to 'mux.go')
| -rw-r--r-- | mux.go | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -66,7 +66,7 @@ func NewMux(parent Env) Mux { size.Set <- resize.Rectangle } for _, child := range children { - child.eventsIn <- e + child.events.Enqueue <- e } case child := <-addChild: children = append(children, child) @@ -108,8 +108,7 @@ func (mux Mux) detach() <-chan bool { } type muxEnv struct { - eventsIn chan<- Event - eventsOut <-chan Event + events share.Queue[Event] draw chan<- func(draw.Image) image.Rectangle attachChan chan<- attachable kill chan<- bool @@ -118,7 +117,7 @@ type muxEnv struct { } func (mux Mux) MakeEnv() Env { - eventsOut, eventsIn := makeEventsChan() + events := share.NewQueue[Event]() drawChan := make(chan func(draw.Image) image.Rectangle) attached := newAttachHandler() kill := make(chan bool) @@ -126,8 +125,7 @@ func (mux Mux) MakeEnv() Env { detachFromMux := make(chan bool) env := muxEnv{ - eventsIn: eventsIn, - eventsOut: eventsOut, + events: events, draw: drawChan, attachChan: attached.attach(), kill: kill, @@ -136,7 +134,7 @@ func (mux Mux) MakeEnv() Env { } mux.addChild <- env // make sure to always send a resize event to a new Env - eventsIn <- Resize{mux.size.Get()} + events.Enqueue <- Resize{mux.size.Get()} go func() { defer func() { @@ -145,8 +143,7 @@ func (mux Mux) MakeEnv() Env { }() defer close(kill) defer close(drawChan) - defer close(eventsIn) - // eventsOut closed automatically by makeEventsChan() + defer close(events.Enqueue) defer func() { mux.removeChild <- env @@ -174,7 +171,7 @@ func (mux Mux) MakeEnv() Env { } func (env muxEnv) Events() <-chan Event { - return env.eventsOut + return env.events.Dequeue } func (env muxEnv) Draw() chan<- func(draw.Image) image.Rectangle { |