Move Grid{} to a new file. Run go fmt.

This commit is contained in:
gmp
2019-08-27 09:24:30 -04:00
parent f96cdb619a
commit 9f60b99984
7 changed files with 544 additions and 398 deletions
+53 -40
View File
@@ -14,25 +14,25 @@ import (
"gioui.org/ui"
"gioui.org/ui/app"
"gioui.org/ui/paint"
"gioui.org/ui/f32"
"gioui.org/ui/gesture"
"gioui.org/ui/layout"
"gioui.org/ui/measure"
"gioui.org/ui/paint"
"gioui.org/ui/pointer"
"gioui.org/ui/text"
"golang.org/x/image/font/sfnt"
"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)
var (
FPS int = 100
frames int64
frametime int64 // nanoseconds
FPS int = 100
frames int64
frametime int64 // nanoseconds
maxframetime int64
mux sync.Mutex
Profile bool = false
mux sync.Mutex
Profile bool = false
)
func NewButton(face text.Face, t string, c color.RGBA) giowrap.Clickable {
@@ -56,25 +56,27 @@ func main() {
a1 = ms.Alloc
runtime.GC()
runtime.ReadMemStats(ms)
log.Printf("Alloc: %d - %d = %d (%d per frame)", a1, ms.Alloc, a1 - ms.Alloc, (a1 - ms.Alloc) / (3 * uint64(FPS)))
log.Printf("Frametime: %d max Frametime: %d us\n", frametime / (frames * 1000), maxframetime / 1000)
log.Printf("Alloc: %d - %d = %d (%d per frame)", a1, ms.Alloc, a1-ms.Alloc, (a1-ms.Alloc)/(3*uint64(FPS)))
log.Printf("Frametime: %d max Frametime: %d us\n", frametime/(frames*1000), maxframetime/1000)
frames = 0
frametime = 0
maxframetime = 0
mux.Unlock()
}
}()
switch os.Args[1] {
case "", "main1":
log.Print("main1()")
go main1()
case "main2":
log.Print("main2()")
go main2()
default:
log.Fatal(`Usage:
if len(os.Args) > 1 {
switch os.Args[1] {
case "", "main1":
log.Print("main1()")
go main1()
case "main2":
log.Print("main2()")
go main2()
default:
log.Fatal(`Usage:
hello [main1|main2]
`)
}
}
app.Main()
}
@@ -86,11 +88,11 @@ func main1() {
log.Fatal("Cannot parse font.")
}
ctx := giowrap.NewContext(w)
t := time.NewTicker(time.Second/time.Duration(FPS))
e1 := giowrap.NewEditor("text 1",giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
t := time.NewTicker(time.Second / time.Duration(FPS))
e1 := giowrap.NewEditor("text 1", giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
e1.Focus()
e2 := giowrap.NewEditor("text 2",giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
e2 := giowrap.NewEditor("text 2", giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
f1 := giowrap.NewFlex(giowrap.Axis(layout.Vertical))
OuterInset := giowrap.NewInset(giowrap.Size(ui.Dp(10)))
@@ -118,7 +120,7 @@ func main1() {
case app.UpdateEvent:
ctx.Reset(e)
OuterInset(
f1(
f1(
e1,
giowrap.Flexible(5),
InnerInset(e2),
@@ -131,21 +133,27 @@ func main1() {
)).Layout(ctx)
ctx.Update()
if btn1.Clicked(ctx) {
log.Print("Clicked: " + e1.Text() )
log.Print("Clicked: " + e1.Text())
}
if btn2.Clicked(ctx) {
log.Print("Clicked: " + e2.Text() )
log.Print("Clicked: " + e2.Text())
}
}
dur := time.Since(stime).Nanoseconds()
mux.Lock()
frames = frames + 1
frametime = frametime + dur
if dur > maxframetime { maxframetime = dur }
if dur > maxframetime {
maxframetime = dur
}
mux.Unlock()
}
if profiled { continue }
if time.Since(startTime) < time.Second * 10 { continue }
if profiled {
continue
}
if time.Since(startTime) < time.Second*10 {
continue
}
if Profile {
profiled = true
f, err := os.Create("memprofile.pprof")
@@ -170,26 +178,26 @@ func main2() {
if err != nil {
log.Fatal("Cannot parse font.")
}
t := time.NewTicker(time.Second/time.Duration(FPS))
t := time.NewTicker(time.Second / time.Duration(FPS))
e1 := &text.Editor{
Face: faces.For(regular, ui.Sp(24)),
Face: faces.For(regular, ui.Sp(24)),
SingleLine: true,
}
e1.Focus()
e1.SetText("text 1")
e2 := &text.Editor{
Face: faces.For(regular, ui.Sp(24)),
Face: faces.For(regular, ui.Sp(24)),
SingleLine: true,
}
e2.Focus()
e2.SetText("text 2")
f1 := layout.Flex{ Axis: layout.Vertical }
f1 := layout.Flex{Axis: layout.Vertical}
OuterInset := layout.UniformInset(ui.Dp(10))
InnerInset := layout.UniformInset(ui.Dp(10))
f2 := layout.Flex{ Axis: layout.Horizontal }
f2 := layout.Flex{Axis: layout.Horizontal}
btn1 := text.Label{
Face: faces.For(regular, ui.Sp(24)),
@@ -240,7 +248,7 @@ func main2() {
cs = b1ins.Begin(c, ops, cs)
dims = btn1.Layout(ops, cs)
dims = b1ins.End(dims)
pointer.RectAreaOp{image.Rect(0,0,dims.Size.X,dims.Size.Y)}.Add(ops)
pointer.RectAreaOp{image.Rect(0, 0, dims.Size.X, dims.Size.Y)}.Add(ops)
click1.Add(ops)
bg1.Stop()
wi, h := float32(dims.Size.X), float32(dims.Size.Y)
@@ -257,7 +265,7 @@ func main2() {
cs = b2ins.Begin(c, ops, cs)
dims = btn2.Layout(ops, cs)
dims = b2ins.End(dims)
pointer.RectAreaOp{image.Rect(0,0,dims.Size.X,dims.Size.Y)}.Add(ops)
pointer.RectAreaOp{image.Rect(0, 0, dims.Size.X, dims.Size.Y)}.Add(ops)
click2.Add(ops)
bg2.Stop()
wi, h = float32(dims.Size.X), float32(dims.Size.Y)
@@ -274,12 +282,12 @@ func main2() {
w.Update(ops)
for ev, ok := click1.Next(q); ok; ev, ok = click1.Next(q) {
if ev.Type == gesture.TypeClick {
log.Print("Clicked: " + e1.Text() )
log.Print("Clicked: " + e1.Text())
}
}
for ev, ok := click2.Next(q); ok; ev, ok = click2.Next(q) {
if ev.Type == gesture.TypeClick {
log.Print("Clicked: " + e2.Text() )
log.Print("Clicked: " + e2.Text())
}
}
}
@@ -287,11 +295,17 @@ func main2() {
mux.Lock()
frames = frames + 1
frametime = frametime + dur
if dur > maxframetime { maxframetime = dur }
if dur > maxframetime {
maxframetime = dur
}
mux.Unlock()
}
if profiled { continue }
if time.Since(startTime) < time.Second * 10 { continue }
if profiled {
continue
}
if time.Since(startTime) < time.Second*10 {
continue
}
if Profile {
profiled = true
f, err := os.Create("memprofile.pprof")
@@ -306,4 +320,3 @@ func main2() {
}
}
}