ui/app,apps/gophers,apps/hello: revert NewWindow to CreateWindow

It turns out we already support multiple windows on Android: when
the activity is recreated.

This reverts commit f21b5eb1df.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-04-02 19:26:23 +02:00
parent 6899f96532
commit ed2590e30e
9 changed files with 90 additions and 80 deletions
+15 -10
View File
@@ -121,6 +121,14 @@ func main() {
fmt.Println("The quota for anonymous GitHub API access is very low. Specify a token with -token to avoid quota errors.")
fmt.Println("See https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line.")
}
err := app.CreateWindow(&app.WindowOptions{
Width: ui.Dp(400),
Height: ui.Dp(800),
Title: "Gophers",
})
if err != nil {
log.Fatal(err)
}
app.Main()
}
@@ -141,16 +149,13 @@ func init() {
fonts.italic = mustLoadFont(goitalic.TTF)
fonts.mono = mustLoadFont(gomono.TTF)
go func() {
w, err := app.NewWindow(&app.WindowOptions{
Width: ui.Dp(400),
Height: ui.Dp(800),
Title: "Gophers",
})
if err != nil {
log.Fatal(err)
}
if err := newApp(w).run(); err != nil {
log.Fatal(err)
for w := range app.Windows() {
w := w
go func() {
if err := newApp(w).run(); err != nil {
log.Fatal(err)
}
}()
}
}()
}
+25 -23
View File
@@ -20,14 +20,24 @@ import (
)
func main() {
// Never called on mobile, blocks forever on
// desktop.
err := app.CreateWindow(nil)
if err != nil {
log.Fatal(err)
}
app.Main()
}
// On iOS and Android main will never be called, so
// setting up the window must run in an init function.
func init() {
go func() {
for w := range app.Windows() {
go loop(w)
}
}()
}
func loop(w *app.Window) {
regular, err := sfnt.Parse(goregular.TTF)
if err != nil {
panic("failed to load font")
@@ -35,26 +45,18 @@ func init() {
var faces measure.Faces
black := &image.Uniform{color.Black}
face := faces.For(regular, ui.Dp(50))
// On iOS and Android app.NewWindow blocks, waiting
// for the platform to create a window.
go func() {
w, err := app.NewWindow(nil)
if err != nil {
log.Fatal(err)
for w.IsAlive() {
e := <-w.Events()
switch e := e.(type) {
case app.Draw:
faces.Cfg = e.Config
cs := layout.ExactConstraints(w.Size())
root, _ := (text.Label{Src: black, Face: face, Text: "Hello, World!"}).Layout(cs)
w.Draw(root)
faces.Frame()
}
for w.IsAlive() {
e := <-w.Events()
switch e := e.(type) {
case app.Draw:
faces.Cfg = e.Config
cs := layout.ExactConstraints(w.Size())
root, _ := (text.Label{Src: black, Face: face, Text: "Hello, World!"}).Layout(cs)
w.Draw(root)
faces.Frame()
}
}
if w.Err() != nil {
log.Fatal(err)
}
}()
}
if w.Err() != nil {
log.Fatal(err)
}
}