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
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
+16 -20
View File
@@ -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:
+3 -9
View File
@@ -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())