72 lines
1.4 KiB
Go
72 lines
1.4 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}
|
|
times := make([]int64, 100)
|
|
timesIndex := 0
|
|
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)
|
|
dur := time.Since(stime)
|
|
//fmt.Printf("Frame time: %s\n", dur)
|
|
times[timesIndex] = dur.Nanoseconds()
|
|
timesIndex++
|
|
if timesIndex == 100 {
|
|
timesIndex = 0
|
|
var avg int64
|
|
for i := 0; i < 100; i++ {
|
|
avg += times[i]
|
|
}
|
|
avg = avg / 100000
|
|
fmt.Printf("Average frame time: %d microseconds\n", avg)
|
|
}
|
|
}
|
|
}
|
|
}
|