2019-08-15 09:16:00 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.wow.st/gmp/giowrap"
|
|
|
|
|
2019-08-15 18:32:01 -04:00
|
|
|
"image/color"
|
2019-08-15 09:16:00 -04:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2019-08-16 16:38:49 -04:00
|
|
|
func NewButton(face text.Face, t string, c color.RGBA) giowrap.Clickable {
|
|
|
|
lbl := giowrap.NewLabel(t, giowrap.LabelFace(face), giowrap.LabelAlignment(text.Center))
|
|
|
|
bg := giowrap.NewBackground(giowrap.BgColor(c), giowrap.BgRadius(ui.Dp(4)))
|
|
|
|
return giowrap.AsClickable(bg(lbl))
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:16:00 -04:00
|
|
|
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)
|
2019-08-16 16:38:49 -04:00
|
|
|
e1 := giowrap.NewEditor("text 1",giowrap.EditorFace(ctx.Faces.For(regular, ui.Sp(24))))
|
2019-08-15 09:16:00 -04:00
|
|
|
e1.Focus()
|
|
|
|
|
2019-08-16 16:38:49 -04:00
|
|
|
e2 := giowrap.NewEditor("text 2",giowrap.EditorFace(ctx.Faces.For(regular, ui.Sp(24))))
|
2019-08-15 09:16:00 -04:00
|
|
|
|
2019-08-16 16:38:49 -04:00
|
|
|
f1 := giowrap.NewFlex(giowrap.FlexAxis(layout.Vertical))
|
|
|
|
OuterInset := giowrap.NewInset(giowrap.InsetSize(ui.Dp(10)))
|
|
|
|
InnerInset := giowrap.NewInset(giowrap.InsetSize(ui.Dp(10)))
|
2019-08-15 09:16:00 -04:00
|
|
|
|
2019-08-16 16:38:49 -04:00
|
|
|
f2 := giowrap.NewFlex(giowrap.FlexAxis(layout.Horizontal))
|
|
|
|
|
|
|
|
btn1 := NewButton(ctx.Faces.For(regular, ui.Sp(24)),
|
|
|
|
"push1", color.RGBA{A: 0xff, R: 0x3c, G: 0x98, B: 0xc6})
|
|
|
|
btn2 := NewButton(ctx.Faces.For(regular, ui.Sp(24)),
|
|
|
|
"push2", color.RGBA{A: 0xff, R: 0x3c, G: 0x98, B: 0xc6})
|
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 18:32:01 -04:00
|
|
|
ctx = OuterInset(
|
2019-08-16 16:38:49 -04:00
|
|
|
f1(
|
2019-08-15 09:16:00 -04:00
|
|
|
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-16 16:38:49 -04:00
|
|
|
f2(
|
|
|
|
InnerInset(btn1),
|
|
|
|
giowrap.Flexible(1),
|
|
|
|
InnerInset(btn2),
|
|
|
|
),
|
2019-08-15 18:32:01 -04:00
|
|
|
)).Layout(ctx)
|
2019-08-15 09:16:00 -04:00
|
|
|
ctx.Draw()
|
2019-08-16 16:38:49 -04:00
|
|
|
if btn1.Clicked(ctx) {
|
|
|
|
log.Print("Clicked: " + e1.Text() )
|
|
|
|
}
|
|
|
|
if btn2.Clicked(ctx) {
|
2019-08-15 09:16:00 -04:00
|
|
|
log.Print("Clicked: " + e2.Text() )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
app.Main()
|
|
|
|
}
|
|
|
|
|