android-go/examples/pgp/main.go

80 lines
1.5 KiB
Go

// +build darwin linux
package main
import (
"log"
"gioui.org/app"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget/material"
"gioui.org/font/gofont"
)
var (
labchan chan string
)
func main() {
labchan = make(chan string)
log.Print("Staring event loop")
go eventloop()
app.Main()
log.Print("app.Main() returned")
}
func eventloop() {
gofont.Register()
w := app.NewWindow(
app.Size(unit.Dp(400), unit.Dp(400)),
app.Title("Hello"))
th := material.NewTheme()
gtx := &layout.Context{Queue: w.Queue()}
sysinset := &layout.Inset{}
margin := layout.UniformInset(unit.Dp(10))
labels := []material.Label{}
list := &layout.List{Axis: layout.Vertical}
resetSysinset := func(x system.Insets) {
sysinset.Top = x.Top
sysinset.Bottom = x.Bottom
sysinset.Left = x.Left
sysinset.Right = x.Right
}
go func() {
labchan <- "Starting"
callJni()
}()
for {
select {
case x := <-labchan:
labels = append(labels, th.Body1(x))
w.Invalidate()
case e := <-w.Events():
switch e := e.(type) {
case system.DestroyEvent:
return
case system.FrameEvent:
gtx.Reset(e.Config, e.Size)
resetSysinset(e.Insets)
sysinset.Layout(gtx, func() {
margin.Layout(gtx, func() {
list.Layout(gtx, len(labels), func(i int) {
labels[i].Layout(gtx)
})
})
})
e.Frame(gtx.Ops)
case system.StageEvent:
log.Printf("stage event -- %s", e.Stage)
case *system.CommandEvent:
log.Print("command event")
}
}
}
}