2019-10-18 14:40:35 -04:00
|
|
|
// +build darwin linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"gioui.org/app"
|
|
|
|
"gioui.org/io/system"
|
|
|
|
"gioui.org/layout"
|
2020-06-11 10:42:43 -04:00
|
|
|
"gioui.org/op"
|
2019-10-18 14:40:35 -04:00
|
|
|
"gioui.org/unit"
|
|
|
|
"gioui.org/widget/material"
|
|
|
|
|
2019-11-01 14:21:44 -04:00
|
|
|
"gioui.org/font/gofont"
|
2019-10-18 14:40:35 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
labchan chan string
|
|
|
|
)
|
|
|
|
|
2020-06-11 10:42:43 -04:00
|
|
|
type (
|
|
|
|
D = layout.Dimensions
|
|
|
|
C = layout.Context
|
|
|
|
)
|
|
|
|
|
2019-10-18 14:40:35 -04:00
|
|
|
func main() {
|
|
|
|
labchan = make(chan string)
|
|
|
|
log.Print("Staring event loop")
|
|
|
|
go eventloop()
|
|
|
|
app.Main()
|
|
|
|
log.Print("app.Main() returned")
|
|
|
|
}
|
|
|
|
|
|
|
|
func eventloop() {
|
|
|
|
w := app.NewWindow(
|
|
|
|
app.Size(unit.Dp(400), unit.Dp(400)),
|
|
|
|
app.Title("Hello"))
|
2020-06-11 10:42:43 -04:00
|
|
|
th := material.NewTheme(gofont.Collection())
|
|
|
|
var ops op.Ops
|
2019-10-18 14:40:35 -04:00
|
|
|
|
|
|
|
sysinset := &layout.Inset{}
|
|
|
|
margin := layout.UniformInset(unit.Dp(10))
|
2020-06-11 10:42:43 -04:00
|
|
|
labels := []material.LabelStyle{}
|
2019-10-18 14:40:35 -04:00
|
|
|
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:
|
2020-06-11 10:42:43 -04:00
|
|
|
labels = append(labels, material.Body1(th, x))
|
2019-10-18 14:40:35 -04:00
|
|
|
case e := <-w.Events():
|
|
|
|
switch e := e.(type) {
|
|
|
|
case system.DestroyEvent:
|
|
|
|
return
|
|
|
|
case system.FrameEvent:
|
2020-06-11 10:42:43 -04:00
|
|
|
gtx := layout.NewContext(&ops, e)
|
2019-10-18 14:40:35 -04:00
|
|
|
resetSysinset(e.Insets)
|
2020-06-11 10:42:43 -04:00
|
|
|
sysinset.Layout(gtx, func(gtx C) D {
|
|
|
|
return margin.Layout(gtx, func(gtx C) D {
|
|
|
|
return list.Layout(gtx, len(labels), func(gtx C, i int) D {
|
|
|
|
return labels[i].Layout(gtx)
|
2019-10-18 14:40:35 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
e.Frame(gtx.Ops)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|