Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeEventsChan ¶
MakeEventsChan implements a channel of events with an unlimited capacity. It does so by creating a goroutine that queues incoming events. Sending to this channel never blocks and no events get lost.
The unlimited capacity channel is very suitable for delivering events because the consumer may be unavailable for some time (doing a heavy computation), but will get to the events later.
An unlimited capacity channel has its dangers in general, but is completely fine for the purpose of delivering events. This is because the production of events is fairly infrequent and should never out-run their consumption in the long term.
func NewMux ¶
NewMux creates a new Mux that multiplexes the given Env. It returns the Mux along with a master Env. The 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 StartQueue ¶
Types ¶
type Env ¶
Env is the most important thing in this package. It is an interactive graphical environment, such as a window.
It has two channels: Events() and Draw().
The Events() channel produces events, like mouse and keyboard presses, while the Draw() channel receives drawing functions. A drawing function draws onto the supplied draw.Image, which is the drawing area of the Env and returns a rectangle covering the whole part of the image that got changed.
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 a channel of events with an unlimited capacity.
The Draw() channel may be synchronous.
Drawing functions sent to the Draw() channel are not guaranteed to be executed.
Closing the Draw() channel results in closing the Env. The Env will subsequently close the Events() channel. On the other hand, when the Events() channel gets closed the user of the Env should subsequently close the Draw() channel.
type Event ¶
type Event interface{}
Event is something that can happen in an environment.
This package defines only one kind of event: Resize. Other packages implementing environments may implement more kinds of events. For example, the win package implements all kinds of events for mouse and keyboard.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
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.