package main import ( "git.wow.st/gmp/giowrap" "image/color" "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 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)) } 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("text 1",giowrap.EditorFace(ctx.Faces.For(regular, ui.Sp(24)))) e1.Focus() e2 := giowrap.NewEditor("text 2",giowrap.EditorFace(ctx.Faces.For(regular, ui.Sp(24)))) f1 := giowrap.NewFlex(giowrap.FlexAxis(layout.Vertical)) OuterInset := giowrap.NewInset(giowrap.InsetSize(ui.Dp(10))) InnerInset := giowrap.NewInset(giowrap.InsetSize(ui.Dp(10))) 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}) 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 = OuterInset( f1( e1, giowrap.Flexible(5), InnerInset(e2), giowrap.Flexible(10), f2( InnerInset(btn1), giowrap.Flexible(1), InnerInset(btn2), ), )).Layout(ctx) ctx.Draw() if btn1.Clicked(ctx) { log.Print("Clicked: " + e1.Text() ) } if btn2.Clicked(ctx) { log.Print("Clicked: " + e2.Text() ) } } } } }() app.Main() }