ui/app: introduce DestroyEvent for ending the event loop

Replace the StageDead stage with DestroyEvent dedicated to ending
the event loop and, for premature window closes, the error.

Drop the error return from NewWindow; any errors in window creation
will appear as an immediate DestroyEvent with its Err field set.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-13 11:41:12 +02:00
parent 8e307b40a6
commit 59e92e8233
6 changed files with 51 additions and 30 deletions
+16 -8
View File
@@ -17,6 +17,8 @@ type Event interface {
ImplementsEvent()
}
// DrawEvent is sent when a Window's Draw
// method must be called.
type DrawEvent struct {
Config Config
Size image.Point
@@ -27,6 +29,14 @@ type DrawEvent struct {
sync bool
}
// DestroyEvent is the last event sent through
// a window event channel.
type DestroyEvent struct {
// Err is nil for normal window closures. If a
// window is prematurely closed, Err is the cause.
Err error
}
// Insets is the space taken up by
// system decoration such as translucent
// system bars and software keyboards.
@@ -60,8 +70,7 @@ type windowAndOptions struct {
}
const (
StageDead Stage = iota
StagePaused
StagePaused Stage = iota
StageRunning
)
@@ -93,8 +102,6 @@ var extraArgs string
func (l Stage) String() string {
switch l {
case StageDead:
return "StageDead"
case StagePaused:
return "StagePaused"
case StageRunning:
@@ -104,10 +111,6 @@ func (l Stage) String() string {
}
}
func (_ DrawEvent) ImplementsEvent() {}
func (_ StageEvent) ImplementsEvent() {}
func (_ *CommandEvent) ImplementsEvent() {}
func init() {
args := strings.Split(extraArgs, "|")
os.Args = append(os.Args, args...)
@@ -178,3 +181,8 @@ func newWindowRendezvous() *windowRendezvous {
}()
return wr
}
func (_ DrawEvent) ImplementsEvent() {}
func (_ StageEvent) ImplementsEvent() {}
func (_ *CommandEvent) ImplementsEvent() {}
func (_ DestroyEvent) ImplementsEvent() {}