From c71fb555b23178d2abeaee2a3a5eeb6f2db604aa Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 17 Aug 2024 22:49:38 -0400 Subject: move shared data structures to external module --- mux.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'mux.go') diff --git a/mux.go b/mux.go index f4eb6d1..b1375a8 100644 --- a/mux.go +++ b/mux.go @@ -3,6 +3,8 @@ package gui import ( "image" "image/draw" + + "git.samanthony.xyz/share" ) // Mux can be used to multiplex an Env, let's call it a root Env. Mux implements a way to @@ -10,7 +12,7 @@ import ( // events and their draw functions get redirected to the root Env. type Mux struct { addEventsIn chan<- chan<- Event - size sharedVal[image.Rectangle] + size share.Val[image.Rectangle] draw chan<- func(draw.Image) image.Rectangle } @@ -20,7 +22,7 @@ type Mux struct { // created by the Mux. func NewMux(env Env) (mux *Mux, master Env) { addEventsIn := make(chan chan<- Event) - size := newSharedVal[image.Rectangle]() + size := share.NewVal[image.Rectangle]() drawChan := make(chan func(draw.Image) image.Rectangle) mux = &Mux{ addEventsIn: addEventsIn, @@ -33,7 +35,7 @@ func NewMux(env Env) (mux *Mux, master Env) { defer close(env.Draw()) defer close(addEventsIn) - defer size.close() + defer size.Close() defer func() { for _, eventsIn := range eventsIns { close(eventsIn) @@ -52,7 +54,7 @@ func NewMux(env Env) (mux *Mux, master Env) { return } if resize, ok := e.(Resize); ok { - size.set <- resize.Rectangle + size.Set <- resize.Rectangle } for _, eventsIn := range eventsIns { eventsIn <- e @@ -89,7 +91,7 @@ func (mux *Mux) makeEnv(master bool) Env { mux.addEventsIn <- eventsIn // make sure to always send a resize event to a new Env - eventsIn <- Resize{mux.size.get()} + eventsIn <- Resize{mux.size.Get()} go func() { func() { -- cgit v1.2.3