android-go/examples/dex/main.go

71 lines
1.3 KiB
Go
Raw Normal View History

//go:generate go generate ./java
//go:generate go-bindata java/classes.dex
package main
import (
"gioui.org/app"
"gioui.org/layout"
"gioui.org/io/system"
"gioui.org/unit"
"gioui.org/widget/material"
"gioui.org/font/gofont"
)
var (
labchan chan string
)
func main() {
labchan = make(chan string)
go eventloop()
app.Main()
}
func eventloop() {
gofont.Register()
w := app.NewWindow(app.Title("Dex"))
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}
go func() {
labchan <- "Starting"
SetJVM()
CallJNI()
}()
resetSysinset := func(x system.Insets) {
sysinset.Top = x.Top
sysinset.Bottom = x.Bottom
sysinset.Left = x.Left
sysinset.Right = x.Right
}
for { select {
case x := <-labchan:
labels = append(labels, th.Body1(x))
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)
}
}}
}