58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package main
|
|
|
|
// A simple Gio program. See https://gioui.org for more information.
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"gioui.org/app"
|
|
"gioui.org/layout"
|
|
"gioui.org/text"
|
|
"gioui.org/text/shape"
|
|
"gioui.org/unit"
|
|
|
|
"golang.org/x/image/font/gofont/goregular"
|
|
"golang.org/x/image/font/sfnt"
|
|
)
|
|
|
|
func main() {
|
|
go func() {
|
|
w := app.NewWindow()
|
|
if err := loop(w); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}()
|
|
app.Main()
|
|
}
|
|
|
|
func loop(w *app.Window) error {
|
|
regular, err := sfnt.Parse(goregular.TTF)
|
|
if err != nil {
|
|
panic("failed to load font")
|
|
}
|
|
family := &shape.Family{Regular: regular}
|
|
gtx := &layout.Context{Queue: w.Queue()}
|
|
lst := &layout.List{Axis: layout.Vertical}
|
|
for {
|
|
e := <-w.Events()
|
|
switch e := e.(type) {
|
|
case app.DestroyEvent:
|
|
return e.Err
|
|
case app.UpdateEvent:
|
|
stime := time.Now()
|
|
gtx.Reset(&e.Config, e.Size)
|
|
for i := 0; i < 200; i++ {
|
|
lst.Layout(gtx, 200, func(i int) {
|
|
text.Label{Size: unit.Dp(16), Text: fmt.Sprintf("label %d", i)}.Layout(gtx, family)
|
|
})
|
|
}
|
|
w.Update(gtx.Ops)
|
|
log.Printf("Frame time: %s\n", time.Since(stime))
|
|
}
|
|
}
|
|
}
|