From e13b9a499082d638c3bf015b6f3390942c133dd8 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 13 Jul 2019 11:43:54 +0200 Subject: [PATCH] apps: support DestroyEvent Signed-off-by: Elias Naur --- apps/go.mod | 2 +- apps/gophers/main.go | 36 ++++++++++++++++-------------------- apps/hello/hello.go | 12 +++--------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/apps/go.mod b/apps/go.mod index ac66e13d..11d3c87c 100644 --- a/apps/go.mod +++ b/apps/go.mod @@ -3,7 +3,7 @@ module gioui.org/apps go 1.12 require ( - gioui.org/ui v0.0.0-20190712184729-a3b9c7818fa7 + gioui.org/ui v0.0.0-20190713110951-59e92e8233a4 github.com/google/go-github/v24 v24.0.1 golang.org/x/exp v0.0.0-20190627132806-fd42eb6b336f golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 diff --git a/apps/gophers/main.go b/apps/gophers/main.go index 4332c3d7..339f44c8 100644 --- a/apps/gophers/main.go +++ b/apps/gophers/main.go @@ -152,24 +152,21 @@ func initProfiling() { func init() { flag.Parse() initProfiling() - fonts.regular = mustLoadFont(goregular.TTF) - fonts.bold = mustLoadFont(gobold.TTF) - fonts.italic = mustLoadFont(goitalic.TTF) - fonts.mono = mustLoadFont(gomono.TTF) - var ops ui.Ops - theme.text = colorMaterial(&ops, rgb(0x333333)) - theme.tertText = colorMaterial(&ops, rgb(0xbbbbbb)) - theme.brand = colorMaterial(&ops, rgb(0x62798c)) - theme.white = colorMaterial(&ops, rgb(0xffffff)) - w, err := app.NewWindow(&app.WindowOptions{ - Width: ui.Dp(400), - Height: ui.Dp(800), - Title: "Gophers", - }) - if err != nil { - log.Fatal(err) - } go func() { + fonts.regular = mustLoadFont(goregular.TTF) + fonts.bold = mustLoadFont(gobold.TTF) + fonts.italic = mustLoadFont(goitalic.TTF) + fonts.mono = mustLoadFont(gomono.TTF) + var ops ui.Ops + theme.text = colorMaterial(&ops, rgb(0x333333)) + theme.tertText = colorMaterial(&ops, rgb(0xbbbbbb)) + theme.brand = colorMaterial(&ops, rgb(0x62798c)) + theme.white = colorMaterial(&ops, rgb(0xffffff)) + w := app.NewWindow(&app.WindowOptions{ + Width: ui.Dp(400), + Height: ui.Dp(800), + Title: "Gophers", + }) if err := newApp(w).run(); err != nil { log.Fatal(err) } @@ -203,6 +200,8 @@ func (a *App) run() error { a.w.Redraw() } } + case app.DestroyEvent: + return e.Err case app.StageEvent: if e.Stage >= app.StageRunning { if a.ctxCancel == nil { @@ -217,9 +216,6 @@ func (a *App) run() error { a.ctxCancel = nil } } - if e.Stage == app.StageDead { - return a.w.Err() - } case *app.CommandEvent: switch e.Type { case app.CommandBack: diff --git a/apps/hello/hello.go b/apps/hello/hello.go index 571b99eb..1ee9656e 100644 --- a/apps/hello/hello.go +++ b/apps/hello/hello.go @@ -26,12 +26,8 @@ func main() { // On iOS and Android main will never be called, so // setting up the window must run in an init function. func init() { - wopt := app.WindowOptions{Width: ui.Dp(800), Height: ui.Dp(600), Title: "Hello"} - w, err := app.NewWindow(&wopt) - if err != nil { - log.Fatal(err) - } go func() { + w := app.NewWindow(nil) if err := loop(w); err != nil { log.Fatal(err) } @@ -52,10 +48,8 @@ func loop(w *app.Window) error { for { e := <-w.Events() switch e := e.(type) { - case app.StageEvent: - if e.Stage == app.StageDead { - return w.Err() - } + case app.DestroyEvent: + return e.Err case app.DrawEvent: cfg = e.Config cs := layout.ExactConstraints(w.Size())