giowrap/cmd/hello/main.go
2019-08-15 17:47:46 -04:00

76 lines
1.5 KiB
Go

package main
import (
"git.wow.st/gmp/giowrap"
"log"
"time"
"gioui.org/ui"
"gioui.org/ui/app"
"gioui.org/ui/layout"
"gioui.org/ui/text"
"golang.org/x/image/font/sfnt"
"golang.org/x/image/font/gofont/goregular"
)
func main() {
go func() {
w := app.NewWindow(nil)
regular, err := sfnt.Parse(goregular.TTF)
if err != nil {
log.Fatal("Cannot parse font.")
}
ctx := giowrap.NewContext(w)
t := time.NewTicker(time.Second/30)
e1 := giowrap.NewEditor(ctx.Faces.For(regular, ui.Sp(24)), true)
e1.SetText("text 1")
e1.Focus()
e2 := giowrap.NewEditor(ctx.Faces.For(regular, ui.Sp(24)), true)
e2.SetText("text 2")
f := giowrap.NewFlex(layout.Vertical, layout.Start, layout.Start)
OuterInset := giowrap.NewInset(ui.Dp(10),ui.Dp(10),ui.Dp(10),ui.Dp(10))
InnerInset := giowrap.NewInset(ui.Dp(10),ui.Dp(10),ui.Dp(10),ui.Dp(10))
lbl := giowrap.NewLabel(
ctx.Faces.For(regular, ui.Sp(24)),
"push",
text.Center,
)
bg := giowrap.NewBackground(giowrap.Rgb(0x3c98c6), ui.Dp(4))
btn := giowrap.Clickable(bg(lbl))
for {
select {
case <-t.C:
w.Invalidate()
case e := <-w.Events():
switch e := e.(type) {
case app.DestroyEvent:
return
case app.DrawEvent:
ctx = ctx.Reset(e)
ctx = giowrap.LayoutWithContext(ctx,
OuterInset(
f(
e1,
giowrap.Flexible(5),
InnerInset(e2),
giowrap.Flexible(10),
btn,
)))
ctx.Draw()
if btn.Clicked(ctx) {
log.Print("Clicked: " + e2.Text() )
}
}
}
}
}()
app.Main()
}