aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfaiface <faiface2202@gmail.com>2019-05-07 01:31:49 +0200
committerfaiface <faiface2202@gmail.com>2019-05-07 01:31:49 +0200
commit6f8f32604eb7ffcff6baeee9cf994666167085c9 (patch)
treeedcbd9de809b897fa6088e511ece4cbda072e7d2
parentf2f7b00ab803499424c55f56a18bdf477b3b9b76 (diff)
downloadgui-6f8f32604eb7ffcff6baeee9cf994666167085c9.zip
add Mux docs
-rw-r--r--mux.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/mux.go b/mux.go
index b8e5f5c..d0c31de 100644
--- a/mux.go
+++ b/mux.go
@@ -6,6 +6,9 @@ import (
"sync"
)
+// Mux can be used to multiplex an Env, let's call it a root Env. Mux implements a way to
+// create multiple virtual Envs that all interact with the root Env. They receive the same
+// events and their draw functions get redirected to the root Env.
type Mux struct {
mu sync.Mutex
haveR bool
@@ -14,6 +17,10 @@ type Mux struct {
draw chan<- func(draw.Image) image.Rectangle
}
+// NewMux creates a new Mux that multiplexes the given Env. It returns the Mux along with
+// a master Env. A master Env is just like any other Env created by the Mux, except that
+// closing the Draw() channel on the master Env closes the whole Mux and all other Envs
+// created by the Mux.
func NewMux(env Env) (mux *Mux, master Env) {
drawChan := make(chan func(draw.Image) image.Rectangle)
mux = &Mux{draw: drawChan}
@@ -51,6 +58,9 @@ func NewMux(env Env) (mux *Mux, master Env) {
return mux, master
}
+// MakeEnv creates a new virtual Env that interacts with the root Env of the Mux. Closing
+// the Draw() channel of the Env will not close the Mux, or any other Env created by the Mux
+// but will delete the Env from the Mux.
func (mux *Mux) MakeEnv() Env {
return mux.makeEnv(false)
}