giotest/fast/main.go

61 lines
1.2 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/ui"
"gioui.org/ui/app"
"gioui.org/ui/layout"
"gioui.org/ui/measure"
"gioui.org/ui/text"
"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")
}
var faces measure.Faces
ops := new(ui.Ops)
q := w.Queue()
face := faces.For(regular, ui.Sp(16))
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()
c := e.Config
ops.Reset()
faces.Reset(&c)
for lst.Init(&c, q, ops, layout.RigidConstraints(e.Size), 200); lst.More(); lst.Next() {
lst.End(text.Label{Face: face, Text: fmt.Sprintf("label %d",lst.Index())}.Layout(ops, lst.Constraints()))
}
lst.Layout()
w.Update(ops)
log.Printf("Frame time: %s\n", time.Since(stime))
}
}
}