Cleanups and comments.
This commit is contained in:
parent
74951e8ce5
commit
92cb4d20a4
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"git.wow.st/gmp/giowrap"
|
"git.wow.st/gmp/giowrap"
|
||||||
|
|
||||||
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ func main() {
|
||||||
"push",
|
"push",
|
||||||
text.Center,
|
text.Center,
|
||||||
)
|
)
|
||||||
bg := giowrap.NewBackground(giowrap.Rgb(0x3c98c6), ui.Dp(4))
|
bg := giowrap.NewBackground(color.RGBA{A: 0xff, R: 0x3c, G: 0x98, B: 0xc6}, ui.Dp(4))
|
||||||
btn := giowrap.Clickable(bg(lbl))
|
btn := giowrap.Clickable(bg(lbl))
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -53,15 +54,14 @@ func main() {
|
||||||
return
|
return
|
||||||
case app.DrawEvent:
|
case app.DrawEvent:
|
||||||
ctx = ctx.Reset(e)
|
ctx = ctx.Reset(e)
|
||||||
ctx = giowrap.LayoutWithContext(ctx,
|
ctx = OuterInset(
|
||||||
OuterInset(
|
|
||||||
f(
|
f(
|
||||||
e1,
|
e1,
|
||||||
giowrap.Flexible(5),
|
giowrap.Flexible(5),
|
||||||
InnerInset(e2),
|
InnerInset(e2),
|
||||||
giowrap.Flexible(10),
|
giowrap.Flexible(10),
|
||||||
btn,
|
btn,
|
||||||
)))
|
)).Layout(ctx)
|
||||||
ctx.Draw()
|
ctx.Draw()
|
||||||
if btn.Clicked(ctx) {
|
if btn.Clicked(ctx) {
|
||||||
log.Print("Clicked: " + e2.Text() )
|
log.Print("Clicked: " + e2.Text() )
|
||||||
|
|
48
main.go
48
main.go
|
@ -52,25 +52,6 @@ func (ctx Context) Draw() {
|
||||||
|
|
||||||
type Layout func(Context) Context
|
type Layout func(Context) Context
|
||||||
|
|
||||||
func LayoutWithContext(ctx Context, ws ...Widget) Context {
|
|
||||||
for _, w := range ws {
|
|
||||||
ctx = w.Layout(ctx)
|
|
||||||
}
|
|
||||||
return ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
type fWidget struct {
|
|
||||||
l Layout
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewfWidget(l Layout) fWidget {
|
|
||||||
return fWidget{ l: l }
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fw fWidget) Layout(ctx Context) Context {
|
|
||||||
return fw.l(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Widget interface {
|
type Widget interface {
|
||||||
Layout(Context) Context
|
Layout(Context) Context
|
||||||
}
|
}
|
||||||
|
@ -111,28 +92,25 @@ func (e *Editor) Layout(ctx Context) Context {
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) Text() string {
|
func (e *Editor) Text() string { return e.e.Text() }
|
||||||
return e.e.Text()
|
func (e *Editor) SetText(s string) { e.e.SetText(s) }
|
||||||
|
func (e *Editor) Focus() { e.e.Focus() }
|
||||||
|
|
||||||
|
type fWidget struct {
|
||||||
|
l Layout
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) SetText(s string) {
|
func NewfWidget(l Layout) fWidget {
|
||||||
e.e.SetText(s)
|
return fWidget{ l: l }
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) Focus() {
|
func (fw fWidget) Layout(ctx Context) Context {
|
||||||
e.e.Focus()
|
return fw.l(ctx)
|
||||||
}
|
|
||||||
|
|
||||||
func Rgb(c uint32) color.RGBA {
|
|
||||||
return Argb((0xff << 24) | c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Argb(c uint32) color.RGBA {
|
|
||||||
return color.RGBA{A: uint8(c >> 24), R: uint8(c >> 16), G: uint8(c >> 8), B: uint8(c)}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Flex WidgetCombinator
|
type Flex WidgetCombinator
|
||||||
|
|
||||||
|
// This "Widget" does nothing except set the Flexible key of ctx.extra.
|
||||||
func Flexible(v float32) Widget {
|
func Flexible(v float32) Widget {
|
||||||
return NewfWidget(func(ctx Context) Context {
|
return NewfWidget(func(ctx Context) Context {
|
||||||
ctx.extra["Flexible"] = v
|
ctx.extra["Flexible"] = v
|
||||||
|
@ -140,6 +118,7 @@ func Flexible(v float32) Widget {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewFlex returns a WidgetCombinator that wraps the layout.Flex element.
|
||||||
func NewFlex(axis layout.Axis, mainAxisAlignment layout.MainAxisAlignment, crossAxisAlignment layout.CrossAxisAlignment) Flex {
|
func NewFlex(axis layout.Axis, mainAxisAlignment layout.MainAxisAlignment, crossAxisAlignment layout.CrossAxisAlignment) Flex {
|
||||||
f := layout.Flex{
|
f := layout.Flex{
|
||||||
Axis: axis,
|
Axis: axis,
|
||||||
|
@ -171,6 +150,7 @@ func NewFlex(axis layout.Axis, mainAxisAlignment layout.MainAxisAlignment, cross
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NewInset returns a WidgetCombinator that wraps the layout.Inset element.
|
||||||
func NewInset(top, right, bottom, left ui.Value) WidgetCombinator {
|
func NewInset(top, right, bottom, left ui.Value) WidgetCombinator {
|
||||||
ins := layout.Inset{ Top: top, Right: right, Bottom: bottom, Left: left }
|
ins := layout.Inset{ Top: top, Right: right, Bottom: bottom, Left: left }
|
||||||
return func(ws ...Widget) Widget {
|
return func(ws ...Widget) Widget {
|
||||||
|
@ -264,6 +244,7 @@ func rrect(ops *ui.Ops, width, height, se, sw, nw, ne float32) {
|
||||||
b.End()
|
b.End()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//cWidget is a clickable Widget that provides the Clicked() method.
|
||||||
type cWidget struct {
|
type cWidget struct {
|
||||||
w Widget
|
w Widget
|
||||||
click *gesture.Click
|
click *gesture.Click
|
||||||
|
@ -285,6 +266,7 @@ func (w cWidget) Clicked(ctx Context) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Clickable converts any Widget into a clickable Widget.
|
||||||
func Clickable(w Widget) cWidget {
|
func Clickable(w Widget) cWidget {
|
||||||
return cWidget{ w: w, click: new(gesture.Click) }
|
return cWidget{ w: w, click: new(gesture.Click) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user