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)
2019-08-15 17:47:46 -04:00
e1.SetText("text 1")
2019-08-15 09:16:00 -04:00
e1.Focus()
e2 := giowrap.NewEditor(ctx.Faces.For(regular, ui.Sp(24)), true)
2019-08-15 17:47:46 -04:00
e2.SetText("text 2")
2019-08-15 09:16:00 -04:00
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))
2019-08-15 17:47:46 -04:00
lbl := giowrap.NewLabel(
2019-08-15 09:16:00 -04:00
ctx.Faces.For(regular, ui.Sp(24)),
2019-08-15 17:47:46 -04:00
"push",
2019-08-15 09:16:00 -04:00
text.Center,
)
bg := giowrap.NewBackground(giowrap.Rgb(0x3c98c6), ui.Dp(4))
2019-08-15 17:47:46 -04:00
btn := giowrap.Clickable(bg(lbl))
2019-08-15 09:16:00 -04:00
for {
select {
case <-t.C:
w.Invalidate()
case e := <-w.Events():
switch e := e.(type) {
case app.DestroyEvent:
return
case app.DrawEvent:
2019-08-15 17:47:46 -04:00
ctx = ctx.Reset(e)
2019-08-15 09:16:00 -04:00
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()
2019-08-15 17:47:46 -04:00
if btn.Clicked(ctx) {
2019-08-15 09:16:00 -04:00
log.Print("Clicked: " + e2.Text() )
}
}
}
}
}()
app.Main()
}