aboutsummaryrefslogtreecommitdiffstats
path: root/layout/mux.go
diff options
context:
space:
mode:
Diffstat (limited to 'layout/mux.go')
-rw-r--r--layout/mux.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/layout/mux.go b/layout/mux.go
new file mode 100644
index 0000000..680e984
--- /dev/null
+++ b/layout/mux.go
@@ -0,0 +1,29 @@
+package layout
+
+import (
+ "image"
+ "image/draw"
+)
+
+// TaggedDrawCall is a draw function tagged with the index of a child Env within a layout.
+type taggedDrawCall struct {
+ f func(draw.Image) image.Rectangle
+ idx uint
+}
+
+// MuxDrawCalls tags draw functions with the index of a child Env, and forwards them to an output channel.
+// When the input channel is closed, it decrements the waitgroup counter.
+// It does NOT close the output channel.
+func muxDrawCalls(in <-chan func(draw.Image) image.Rectangle, idx uint, out chan<- taggedDrawCall, wg waitgroup) {
+ for f := range in {
+ out <- taggedDrawCall{f, idx}
+ }
+ wg.Done()
+}
+
+// Multicast sends a message to multiple recipients.
+func multicast[T any](msg T, recipients []chan T) {
+ for _, c := range recipients {
+ c <- msg
+ }
+}