Files
gio-patched/example/hello/hello.go
T
Elias Naur f5985b5e7d cmd,example: bump gio version
Add os.Exit to examples now that app.Main never returns.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-26 16:30:34 +02:00

52 lines
892 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
package main
// A simple Gio program. See https://gioui.org for more information.
import (
"image/color"
"log"
"os"
"gioui.org/app"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/text"
"gioui.org/widget/material"
"gioui.org/font/gofont"
)
func main() {
go func() {
defer os.Exit(0)
w := app.NewWindow()
if err := loop(w); err != nil {
log.Fatal(err)
}
}()
app.Main()
}
func loop(w *app.Window) error {
th := material.NewTheme(gofont.Collection())
var ops op.Ops
for {
e := <-w.Events()
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
l := material.H1(th, "Hello, Gio")
maroon := color.RGBA{127, 0, 0, 255}
l.Color = maroon
l.Alignment = text.Middle
l.Layout(gtx)
e.Frame(gtx.Ops)
}
}
}