mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
ui/app,apps/gophers,apps/hello: replace CreateWindow with NewWindow
Gio doesn't support multiple windows anyway, so get rid of the app.Windows channel and use NewWindow call for the mobile platforms as well. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+24
-30
@@ -18,26 +18,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := app.CreateWindow(app.WindowOptions{
|
||||
Width: ui.Dp(400),
|
||||
Height: ui.Dp(800),
|
||||
Title: "Hello World",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
app.Main()
|
||||
}
|
||||
|
||||
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")
|
||||
@@ -45,19 +29,29 @@ func loop(w *app.Window) {
|
||||
var faces measure.Faces
|
||||
black := &image.Uniform{color.Black}
|
||||
face := faces.For(regular, ui.Dp(50))
|
||||
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()
|
||||
go func() {
|
||||
w, err := app.NewWindow(app.WindowOptions{
|
||||
Width: ui.Dp(400),
|
||||
Height: ui.Dp(800),
|
||||
Title: "Hello World",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
w.Ack()
|
||||
}
|
||||
if w.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()
|
||||
}
|
||||
w.Ack()
|
||||
}
|
||||
if w.Err() != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user