2019-09-17 10:42:01 -04:00
|
|
|
// +build darwin linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
2019-10-07 10:41:51 -04:00
|
|
|
"log"
|
2019-09-17 10:42:01 -04:00
|
|
|
|
2019-10-03 11:32:15 -04:00
|
|
|
"gioui.org/app"
|
|
|
|
"gioui.org/layout"
|
|
|
|
"gioui.org/text"
|
|
|
|
"gioui.org/text/shape"
|
|
|
|
"gioui.org/unit"
|
2019-09-17 10:42:01 -04:00
|
|
|
|
|
|
|
"golang.org/x/image/font/gofont/goregular"
|
2019-10-07 10:41:51 -04:00
|
|
|
"golang.org/x/image/font/sfnt"
|
2019-09-17 10:42:01 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-10-07 10:41:51 -04:00
|
|
|
face text.Face
|
2019-09-17 10:42:01 -04:00
|
|
|
white = color.RGBA{A: 0xff, R: 0xff, G: 0xff, B: 0xff}
|
2019-10-07 10:41:51 -04:00
|
|
|
gray = color.RGBA{A: 0xff, R: 0xb0, G: 0xb0, B: 0xb0}
|
2019-09-17 10:42:01 -04:00
|
|
|
black = color.RGBA{A: 0xff, R: 0x00, G: 0x00, B: 0x00}
|
|
|
|
|
|
|
|
labchan chan string
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
labchan = make(chan string)
|
|
|
|
log.Print("Staring event loop")
|
|
|
|
go eventloop()
|
|
|
|
app.Main()
|
|
|
|
log.Print("App closed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func diffInsets(x, y app.Insets) bool {
|
2019-10-07 10:41:51 -04:00
|
|
|
return x.Top != y.Top ||
|
2019-09-17 10:42:01 -04:00
|
|
|
x.Bottom != y.Bottom ||
|
|
|
|
x.Left != y.Left ||
|
|
|
|
x.Right != y.Right
|
|
|
|
}
|
|
|
|
|
|
|
|
func eventloop() {
|
|
|
|
w := app.NewWindow(
|
2019-10-03 11:32:15 -04:00
|
|
|
app.WithWidth(unit.Dp(400)),
|
|
|
|
app.WithHeight(unit.Dp(400)),
|
2019-09-17 10:42:01 -04:00
|
|
|
app.WithTitle("Hello"))
|
2019-10-03 11:32:15 -04:00
|
|
|
gtx := &layout.Context{Queue: w.Queue()}
|
|
|
|
var faces shape.Faces
|
2019-09-17 10:42:01 -04:00
|
|
|
|
|
|
|
regular, err := sfnt.Parse(goregular.TTF)
|
2019-10-07 10:41:51 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Cannot parse font.")
|
|
|
|
}
|
2019-10-03 11:32:15 -04:00
|
|
|
face = faces.For(regular, unit.Sp(16))
|
2019-09-17 10:42:01 -04:00
|
|
|
|
|
|
|
sysinset := &layout.Inset{}
|
2019-10-03 11:32:15 -04:00
|
|
|
margin := layout.UniformInset(unit.Dp(10))
|
2019-09-17 10:42:01 -04:00
|
|
|
labels := []*text.Label{}
|
|
|
|
list := &layout.List{Axis: layout.Vertical}
|
|
|
|
|
|
|
|
resetSysinset := func(x app.Insets) {
|
|
|
|
sysinset.Top = x.Top
|
|
|
|
sysinset.Bottom = x.Bottom
|
|
|
|
sysinset.Left = x.Left
|
|
|
|
sysinset.Right = x.Right
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case x := <-labchan:
|
2019-10-07 10:41:51 -04:00
|
|
|
labels = append(labels, &text.Label{Face: face, Text: x})
|
2019-09-17 10:42:01 -04:00
|
|
|
case e := <-w.Events():
|
|
|
|
switch e := e.(type) {
|
|
|
|
case app.DestroyEvent:
|
|
|
|
return
|
|
|
|
case app.UpdateEvent:
|
2019-10-03 11:32:15 -04:00
|
|
|
gtx.Reset(&e.Config, e.Size)
|
|
|
|
faces.Reset(&e.Config)
|
2019-09-17 10:42:01 -04:00
|
|
|
resetSysinset(e.Insets)
|
2019-10-03 11:32:15 -04:00
|
|
|
sysinset.Layout(gtx, func() {
|
|
|
|
margin.Layout(gtx, func() {
|
2019-10-10 13:10:58 -04:00
|
|
|
list.Layout(gtx, len(labels), func(i int) {
|
|
|
|
labels[i].Layout(gtx)
|
|
|
|
})
|
2019-10-03 11:32:15 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
w.Update(gtx.Ops)
|
2019-09-17 10:42:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|