giowrap/cmd/hello/main.go

76 lines
1.5 KiB
Go
Raw Normal View History

2019-08-15 09:16:00 -04:00
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("hi there")
e1.Focus()
e2 := giowrap.NewEditor(ctx.Faces.For(regular, ui.Sp(24)), true)
e2.SetText("ok bye")
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.NewButton(
ctx.Faces.For(regular, ui.Sp(24)),
"centered",
text.Center,
)
bg := giowrap.NewBackground(giowrap.Rgb(0x3c98c6), ui.Dp(4))
btn := 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.Reset(e)
ctx = giowrap.LayoutWithContext(ctx,
OuterInset(
f(
e1,
2019-08-15 09:27:04 -04:00
giowrap.Flexible(5),
2019-08-15 09:16:00 -04:00
InnerInset(e2),
2019-08-15 09:27:04 -04:00
giowrap.Flexible(10),
2019-08-15 09:16:00 -04:00
btn,
)))
ctx.Draw()
if lbl.Clicked(ctx) {
log.Print("Clicked: " + e2.Text() )
}
}
}
}
}()
app.Main()
}