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
+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: