apps: support DestroyEvent

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-13 11:43:54 +02:00
parent 59e92e8233
commit e13b9a4990
3 changed files with 20 additions and 30 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ module gioui.org/apps
go 1.12 go 1.12
require ( 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 github.com/google/go-github/v24 v24.0.1
golang.org/x/exp v0.0.0-20190627132806-fd42eb6b336f golang.org/x/exp v0.0.0-20190627132806-fd42eb6b336f
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9
+4 -8
View File
@@ -152,6 +152,7 @@ func initProfiling() {
func init() { func init() {
flag.Parse() flag.Parse()
initProfiling() initProfiling()
go func() {
fonts.regular = mustLoadFont(goregular.TTF) fonts.regular = mustLoadFont(goregular.TTF)
fonts.bold = mustLoadFont(gobold.TTF) fonts.bold = mustLoadFont(gobold.TTF)
fonts.italic = mustLoadFont(goitalic.TTF) fonts.italic = mustLoadFont(goitalic.TTF)
@@ -161,15 +162,11 @@ func init() {
theme.tertText = colorMaterial(&ops, rgb(0xbbbbbb)) theme.tertText = colorMaterial(&ops, rgb(0xbbbbbb))
theme.brand = colorMaterial(&ops, rgb(0x62798c)) theme.brand = colorMaterial(&ops, rgb(0x62798c))
theme.white = colorMaterial(&ops, rgb(0xffffff)) theme.white = colorMaterial(&ops, rgb(0xffffff))
w, err := app.NewWindow(&app.WindowOptions{ w := app.NewWindow(&app.WindowOptions{
Width: ui.Dp(400), Width: ui.Dp(400),
Height: ui.Dp(800), Height: ui.Dp(800),
Title: "Gophers", Title: "Gophers",
}) })
if err != nil {
log.Fatal(err)
}
go func() {
if err := newApp(w).run(); err != nil { if err := newApp(w).run(); err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -203,6 +200,8 @@ func (a *App) run() error {
a.w.Redraw() a.w.Redraw()
} }
} }
case app.DestroyEvent:
return e.Err
case app.StageEvent: case app.StageEvent:
if e.Stage >= app.StageRunning { if e.Stage >= app.StageRunning {
if a.ctxCancel == nil { if a.ctxCancel == nil {
@@ -217,9 +216,6 @@ func (a *App) run() error {
a.ctxCancel = nil a.ctxCancel = nil
} }
} }
if e.Stage == app.StageDead {
return a.w.Err()
}
case *app.CommandEvent: case *app.CommandEvent:
switch e.Type { switch e.Type {
case app.CommandBack: case app.CommandBack:
+3 -9
View File
@@ -26,12 +26,8 @@ func main() {
// On iOS and Android main will never be called, so // On iOS and Android main will never be called, so
// setting up the window must run in an init function. // setting up the window must run in an init function.
func init() { 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() { go func() {
w := app.NewWindow(nil)
if err := loop(w); err != nil { if err := loop(w); err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -52,10 +48,8 @@ func loop(w *app.Window) error {
for { for {
e := <-w.Events() e := <-w.Events()
switch e := e.(type) { switch e := e.(type) {
case app.StageEvent: case app.DestroyEvent:
if e.Stage == app.StageDead { return e.Err
return w.Err()
}
case app.DrawEvent: case app.DrawEvent:
cfg = e.Config cfg = e.Config
cs := layout.ExactConstraints(w.Size()) cs := layout.ExactConstraints(w.Size())