88 lines
1.7 KiB
Go
88 lines
1.7 KiB
Go
// +build darwin linux
|
|
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"gioui.org/app"
|
|
"gioui.org/io/system"
|
|
"gioui.org/layout"
|
|
"gioui.org/op"
|
|
"gioui.org/unit"
|
|
"gioui.org/widget/material"
|
|
|
|
"gioui.org/font/gofont"
|
|
)
|
|
|
|
var (
|
|
labchan chan string
|
|
)
|
|
|
|
type (
|
|
D = layout.Dimensions
|
|
C = layout.Context
|
|
)
|
|
|
|
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"))
|
|
th := material.NewTheme(gofont.Collection())
|
|
var ops op.Ops
|
|
|
|
sysinset := &layout.Inset{}
|
|
margin := layout.UniformInset(unit.Dp(10))
|
|
labels := []material.LabelStyle{}
|
|
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(w)
|
|
}()
|
|
for {
|
|
select {
|
|
case x := <-labchan:
|
|
labels = append(labels, material.Body1(th, x))
|
|
w.Invalidate()
|
|
case e := <-w.Events():
|
|
switch e := e.(type) {
|
|
case system.DestroyEvent:
|
|
return
|
|
case system.FrameEvent:
|
|
gtx := layout.NewContext(&ops, e)
|
|
resetSysinset(e.Insets)
|
|
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)
|
|
})
|
|
})
|
|
})
|
|
e.Frame(gtx.Ops)
|
|
case system.StageEvent:
|
|
log.Printf("stage event -- %s", e.Stage)
|
|
if e.Stage == system.StageRunning {
|
|
initPgp(w)
|
|
}
|
|
case *system.CommandEvent:
|
|
log.Print("command event")
|
|
}
|
|
}
|
|
}
|
|
}
|