From 07ba8917e0be04843ba316fb9d968d185499b5bb Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 10 Oct 2019 10:29:00 -0400 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ fast/go.mod | 8 +++++++ fast/go.sum | 11 ++++++++++ fast/main.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ slow/go.mod | 8 +++++++ slow/go.sum | 9 ++++++++ slow/main.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 155 insertions(+) create mode 100644 .gitignore create mode 100644 fast/go.mod create mode 100644 fast/go.sum create mode 100644 fast/main.go create mode 100644 slow/go.mod create mode 100644 slow/go.sum create mode 100644 slow/main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..37dee28 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +fast/fast +slow/slow diff --git a/fast/go.mod b/fast/go.mod new file mode 100644 index 0000000..6736388 --- /dev/null +++ b/fast/go.mod @@ -0,0 +1,8 @@ +module git.wow.st/gmp/giotest/fast + +go 1.13 + +require ( + gioui.org/ui v0.0.0-20190918172808-816f0e901fc6 + golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 +) diff --git a/fast/go.sum b/fast/go.sum new file mode 100644 index 0000000..d87fb24 --- /dev/null +++ b/fast/go.sum @@ -0,0 +1,11 @@ +gioui.org v0.0.0-20190918172808-816f0e901fc6 h1:cLijG4iiMdm+SX/Py5GXgVxuj7PpEKSHBA7LbR4tSzs= +gioui.org v0.0.0-20191002205528-32bda106e7ff h1:pLleCPnIUzrPrjM+kad+jVhU31lzoEfINETZkLcTMRQ= +gioui.org/ui v0.0.0-20190918172808-816f0e901fc6 h1:LvHEYxyOW7g+PhOiAm8Delc3AUv9EH219oDvaUMeKBw= +gioui.org/ui v0.0.0-20190918172808-816f0e901fc6/go.mod h1:PssKPKlqVIeyaed+0w492Xc2NgX5M3n6oZKOAj5rxoE= +gioui.org/ui v0.0.0-20190926171558-ce74bc0cbaea h1:rv21Wx1Inf27NY453rrrP6tuEG65PyWPhnP2Jx+Qb8k= +golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 h1:uc17S921SPw5F2gJo7slQ3aqvr2RwpL7eb3+DZncu3s= +golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/fast/main.go b/fast/main.go new file mode 100644 index 0000000..6ced490 --- /dev/null +++ b/fast/main.go @@ -0,0 +1,60 @@ +// 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)) + } + } +} diff --git a/slow/go.mod b/slow/go.mod new file mode 100644 index 0000000..5a55337 --- /dev/null +++ b/slow/go.mod @@ -0,0 +1,8 @@ +module git.wow.st/gmp/giotest/slow + +go 1.13 + +require ( + gioui.org v0.0.0-20191010132702-163d9037e6c8 + golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 +) diff --git a/slow/go.sum b/slow/go.sum new file mode 100644 index 0000000..79fb29d --- /dev/null +++ b/slow/go.sum @@ -0,0 +1,9 @@ +gioui.org v0.0.0-20191010132702-163d9037e6c8 h1:/Z760sQoOvY1RMAoC4hWn00quB4w4UuEOdg/csh9aCs= +gioui.org v0.0.0-20191010132702-163d9037e6c8/go.mod h1:+CEjc9B//HrBfWsQOVxjCyih7HGIj3Pww1xFHVDZyyk= +golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U= +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/slow/main.go b/slow/main.go new file mode 100644 index 0000000..22c1f4b --- /dev/null +++ b/slow/main.go @@ -0,0 +1,57 @@ +// 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)) + } + } +}