Functional options.

This commit is contained in:
gmp
2019-08-16 16:38:49 -04:00
parent b9514a08ff
commit 716cd6b562
2 changed files with 176 additions and 48 deletions
+27 -17
View File
@@ -16,6 +16,12 @@ import (
"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)
@@ -25,24 +31,21 @@ func main() {
}
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 := giowrap.NewEditor("text 1",giowrap.EditorFace(ctx.Faces.For(regular, ui.Sp(24))))
e1.Focus()
e2 := giowrap.NewEditor(ctx.Faces.For(regular, ui.Sp(24)), true)
e2.SetText("text 2")
e2 := giowrap.NewEditor("text 2",giowrap.EditorFace(ctx.Faces.For(regular, ui.Sp(24))))
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))
f1 := giowrap.NewFlex(giowrap.FlexAxis(layout.Vertical))
OuterInset := giowrap.NewInset(giowrap.InsetSize(ui.Dp(10)))
InnerInset := giowrap.NewInset(giowrap.InsetSize(ui.Dp(10)))
lbl := giowrap.NewLabel(
ctx.Faces.For(regular, ui.Sp(24)),
"push",
text.Center,
)
bg := giowrap.NewBackground(color.RGBA{A: 0xff, R: 0x3c, G: 0x98, B: 0xc6}, ui.Dp(4))
btn := giowrap.Clickable(bg(lbl))
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 {
@@ -55,15 +58,22 @@ func main() {
case app.DrawEvent:
ctx = ctx.Reset(e)
ctx = OuterInset(
f(
f1(
e1,
giowrap.Flexible(5),
InnerInset(e2),
giowrap.Flexible(10),
btn,
f2(
InnerInset(btn1),
giowrap.Flexible(1),
InnerInset(btn2),
),
)).Layout(ctx)
ctx.Draw()
if btn.Clicked(ctx) {
if btn1.Clicked(ctx) {
log.Print("Clicked: " + e1.Text() )
}
if btn2.Clicked(ctx) {
log.Print("Clicked: " + e2.Text() )
}
}