@@ 177,8 177,7 @@ type (
)
func uiMain() {
- gofont.Register()
- theme = material.NewTheme()
+ theme = material.NewTheme(gofont.Collection())
theme.Color.Primary = rgb(0x3c98c6)
iconLib.create = mustIcon(icons.ContentCreate)
iconLib.send = mustIcon(icons.ContentSend)
@@ 251,12 250,12 @@ func (a *App) run() error {
}
}
case system.FrameEvent:
- gtx := layout.NewContext(&ops, e.Queue, e.Config, e.Size)
+ gtx := layout.NewContext(&ops, e)
a.env.insets = layout.Inset{
Top: e.Insets.Top,
Left: e.Insets.Left,
Right: e.Insets.Right,
- Bottom: unit.Add(gtx, unit.Dp(8), e.Insets.Bottom),
+ Bottom: unit.Add(gtx.Metric, unit.Dp(8), e.Insets.Bottom),
}
a.Layout(gtx)
if a.profiling {
@@ 285,15 284,13 @@ func (t *Transition) Event(gtx layout.Context) interface{} {
}
func (t *Transition) Layout(gtx layout.Context) layout.Dimensions {
- var stack op.StackOp
- stack.Push(gtx.Ops)
- defer stack.Pop()
+ defer op.Push(gtx.Ops).Pop()
prev, page := t.prev, t.page
if prev != nil {
if t.reverse {
prev, page = page, prev
}
- now := gtx.Now()
+ now := gtx.Now
if t.time.IsZero() {
t.time = now
}
@@ 315,13 312,13 @@ func (t *Transition) Layout(gtx layout.Context) layout.Dimensions {
op.InvalidateOp{}.Add(gtx.Ops)
center := size.Mul(.5)
clipCenter := f32.Point{X: diameter / 2, Y: diameter / 2}
- off := op.TransformOp{}.Offset(center.Sub(clipCenter))
- off.Add(gtx.Ops)
+ off := f32.Affine2D{}.Offset(center.Sub(clipCenter))
+ op.Affine(off).Add(gtx.Ops)
clip.Rect{
Rect: f32.Rectangle{Max: f32.Point{X: diameter, Y: diameter}},
NE: radius, NW: radius, SE: radius, SW: radius,
}.Op(gtx.Ops).Add(gtx.Ops)
- off.Invert().Add(gtx.Ops)
+ op.Affine(off.Invert()).Add(gtx.Ops)
fill{rgb(0xffffff)}.Layout(gtx)
}
return page.Layout(gtx)
@@ 427,7 424,7 @@ func (a *App) layoutTimings(gtx layout.Context) layout.Dimensions {
a.lastMallocs = mstats.Mallocs
return layout.NE.Layout(gtx, func(gtx C) D {
in := a.env.insets
- in.Top = unit.Max(gtx, unit.Dp(16), in.Top)
+ in.Top = unit.Max(gtx.Metric, unit.Dp(16), in.Top)
return in.Layout(gtx, func(gtx C) D {
txt := fmt.Sprintf("m: %d %s", mallocs, a.profile.Timings)
lbl := material.Caption(theme, txt)
@@ 458,7 455,7 @@ func newContactsPage(env *Env) *contactsPage {
func (p *contactsPage) Start(stop <-chan struct{}) {}
func (p *contactsPage) Event(gtx layout.Context) interface{} {
- for _, e := range p.searchEdit.Events(gtx) {
+ for _, e := range p.searchEdit.Events() {
switch e := e.(type) {
case widget.ChangeEvent:
p.queryContacts(p.searchEdit.Text())
@@ 538,8 535,8 @@ func (p *contactsPage) contact(gtx layout.Context, index int) layout.Dimensions
in := layout.Inset{
Top: unit.Dp(16),
Bottom: unit.Dp(16),
- Left: unit.Max(gtx, unit.Dp(16), p.env.insets.Left),
- Right: unit.Max(gtx, unit.Dp(16), p.env.insets.Right),
+ Left: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Left),
+ Right: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Right),
}
contact := p.contacts[index]
click := &p.clicks[index]
@@ 575,10 572,10 @@ func (t *Topbar) Event(gtx layout.Context) interface{} {
func (t *Topbar) Layout(gtx layout.Context, insets layout.Inset, w layout.Widget) layout.Dimensions {
insets = layout.Inset{
- Top: unit.Add(gtx, insets.Top, unit.Dp(16)),
+ Top: unit.Add(gtx.Metric, insets.Top, unit.Dp(16)),
Bottom: unit.Dp(16),
- Left: unit.Max(gtx, insets.Left, unit.Dp(16)),
- Right: unit.Max(gtx, insets.Right, unit.Dp(16)),
+ Left: unit.Max(gtx.Metric, insets.Left, unit.Dp(16)),
+ Right: unit.Max(gtx.Metric, insets.Right, unit.Dp(16)),
}
return layout.Stack{Alignment: layout.SW}.Layout(gtx,
layout.Expanded(fill{theme.Color.Primary}.Layout),
@@ 589,7 586,7 @@ func (t *Topbar) Layout(gtx layout.Context, insets layout.Inset, w layout.Widget
if !t.Back {
return layout.Dimensions{}
}
- ico := (&icon{src: icons.NavigationArrowBack, size: unit.Dp(24)}).image(gtx, rgb(0xffffff))
+ ico := (&icon{src: icons.NavigationArrowBack, size: unit.Dp(24)}).image(gtx.Metric, rgb(0xffffff))
ico.Add(gtx.Ops)
paint.PaintOp{Rect: f32.Rectangle{Max: toPointF(ico.Size())}}.Add(gtx.Ops)
dims := layout.Dimensions{Size: ico.Size()}
@@ 639,7 636,7 @@ func (p *signInPage) Start(stop <-chan struct{}) {
}
func (p *signInPage) Event(gtx layout.Context) interface{} {
- if p.submit.Clicked(gtx) {
+ if p.submit.Clicked() {
for _, f := range p.fields {
*f.Value = f.edit.Text()
}
@@ 665,8 662,8 @@ func (p *signInPage) Layout(gtx layout.Context) layout.Dimensions {
func (p *signInPage) layoutSigninForm(gtx layout.Context) layout.Dimensions {
l := p.list
inset := layout.Inset{
- Left: unit.Max(gtx, unit.Dp(32), p.env.insets.Left),
- Right: unit.Max(gtx, unit.Dp(32), p.env.insets.Right),
+ Left: unit.Max(gtx.Metric, unit.Dp(32), p.env.insets.Left),
+ Right: unit.Max(gtx.Metric, unit.Dp(32), p.env.insets.Right),
}
return l.Layout(gtx, len(p.fields)+1, func(gtx C, i int) D {
in := inset
@@ 678,7 675,7 @@ func (p *signInPage) layoutSigninForm(gtx layout.Context) layout.Dimensions {
}
return in.Layout(gtx, p.fields[i].Layout)
default:
- in.Bottom = unit.Max(gtx, unit.Dp(32), p.env.insets.Bottom)
+ in.Bottom = unit.Max(gtx.Metric, unit.Dp(32), p.env.insets.Bottom)
return layout.E.Layout(gtx, func(gtx C) D {
return in.Layout(gtx, material.Button(theme, p.submit, "Sign in").Layout)
})
@@ 707,12 704,10 @@ type Background struct {
}
func (b *Background) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
- var macro op.MacroOp
- macro.Record(gtx.Ops)
+ macro := op.Record(gtx.Ops)
dims := b.Inset.Layout(gtx, w)
- macro.Stop()
- var stack op.StackOp
- stack.Push(gtx.Ops)
+ call := macro.Stop()
+ defer op.Push(gtx.Ops).Pop()
size := dims.Size
width, height := float32(size.X), float32(size.Y)
if r := float32(gtx.Px(b.Radius)); r > 0 {
@@ 730,8 725,7 @@ func (b *Background) Layout(gtx layout.Context, w layout.Widget) layout.Dimensio
}
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: width, Y: height}}}.Add(gtx.Ops)
- macro.Add()
- stack.Pop()
+ call.Add(gtx.Ops)
return dims
}
@@ 765,7 759,7 @@ func (p *threadsPage) Event(gtx layout.Context) interface{} {
p.env.redraw()
default:
}
- if p.fab.Clicked(gtx) {
+ if p.fab.Clicked() {
return ShowContactsEvent{}
}
for i := range p.clicks {
@@ 812,8 806,8 @@ func (p *threadsPage) Layout(gtx layout.Context) layout.Dimensions {
layout.Stacked(func(gtx C) D {
return layout.SE.Layout(gtx, func(gtx C) D {
return layout.Inset{
- Right: unit.Max(gtx, unit.Dp(16), p.env.insets.Right),
- Bottom: unit.Max(gtx, unit.Dp(16), p.env.insets.Bottom),
+ Right: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Right),
+ Bottom: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Bottom),
}.Layout(gtx,
material.IconButton(theme, p.fab, iconLib.create).Layout,
)
@@ 833,7 827,7 @@ func (p *threadsPage) layoutThreads(gtx layout.Context) layout.Dimensions {
case 0:
in.Top = unit.Dp(4)
case len(p.threads) - 1:
- in.Bottom = unit.Max(gtx, unit.Dp(4), p.env.insets.Bottom)
+ in.Bottom = unit.Max(gtx.Metric, unit.Dp(4), p.env.insets.Bottom)
}
return in.Layout(gtx, func(gtx C) D {
return p.thread(gtx, i)
@@ 860,8 854,8 @@ func (p *threadsPage) thread(gtx layout.Context, index int) layout.Dimensions {
}
click := &p.clicks[index]
in := layout.Inset{
- Left: unit.Max(gtx, unit.Dp(16), p.env.insets.Left),
- Right: unit.Max(gtx, unit.Dp(16), p.env.insets.Right),
+ Left: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Left),
+ Right: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Right),
}
return in.Layout(gtx, func(gtx C) D {
in := layout.Inset{Top: unit.Dp(8), Bottom: unit.Dp(8)}
@@ 976,20 970,20 @@ func (p *threadPage) Event(gtx layout.Context) interface{} {
p.fetchMessages()
default:
}
- for _, e := range p.msgEdit.Events(gtx) {
+ for _, e := range p.msgEdit.Events() {
if _, ok := e.(widget.SubmitEvent); ok {
p.sendMessage()
}
}
- if p.send.Clicked(gtx) {
+ if p.send.Clicked() {
p.sendMessage()
}
- if p.invite.Clicked(gtx) {
+ if p.invite.Clicked() {
if err := p.env.client.Send(p.thread.ID, "Invitation sent"); err != nil {
log.Printf("failed to send invitation: %v", err)
}
}
- if p.accept.Clicked(gtx) {
+ if p.accept.Clicked() {
if err := p.env.client.Send(p.thread.ID, "Invitation accepted"); err != nil {
log.Printf("failed to send invitation accept: %v", err)
}
@@ 1034,9 1028,9 @@ func (p *threadPage) Layout(gtx layout.Context) layout.Dimensions {
layout.Rigid(func(gtx C) D {
return layout.Inset{
Top: unit.Dp(16),
- Left: unit.Max(gtx, unit.Dp(16), p.env.insets.Left),
- Right: unit.Max(gtx, unit.Dp(16), p.env.insets.Right),
- Bottom: unit.Max(gtx, unit.Dp(16), p.env.insets.Bottom),
+ Left: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Left),
+ Right: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Right),
+ Bottom: unit.Max(gtx.Metric, unit.Dp(16), p.env.insets.Bottom),
}.Layout(gtx, func(gtx C) D {
switch {
case p.thread.PendingInvitation:
@@ 1104,8 1098,8 @@ func (p *threadPage) message(gtx layout.Context, index int) layout.Dimensions {
msgCol = theme.Color.Text
timecol = rgb(0x888888)
}
- in.Left = unit.Max(gtx, in.Left, p.env.insets.Left)
- in.Right = unit.Max(gtx, in.Right, p.env.insets.Right)
+ in.Left = unit.Max(gtx.Metric, in.Left, p.env.insets.Left)
+ in.Right = unit.Max(gtx.Metric, in.Right, p.env.insets.Right)
return in.Layout(gtx, func(gtx C) D {
return align.Layout(gtx, func(gtx C) D {
bg := Background{
@@ 1142,7 1136,7 @@ func (p *threadPage) message(gtx layout.Context, index int) layout.Dimensions {
child := layout.Rigid(func(gtx C) D {
in := layout.Inset{Left: unit.Dp(12)}
return in.Layout(gtx, func(gtx C) D {
- checkmark := p.checkmark.image(gtx, timecol)
+ checkmark := p.checkmark.image(gtx.Metric, timecol)
sz := checkmark.Size()
if msg.Sent {
checkmark.Add(gtx.Ops)
@@ 1240,24 1234,21 @@ type clipCircle struct {
}
func (cc *clipCircle) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
- var macro op.MacroOp
- macro.Record(gtx.Ops)
+ macro := op.Record(gtx.Ops)
dims := w(gtx)
- macro.Stop()
+ call := macro.Stop()
max := dims.Size.X
if dy := dims.Size.Y; dy > max {
max = dy
}
szf := float32(max)
rr := szf * .5
- var stack op.StackOp
- stack.Push(gtx.Ops)
+ defer op.Push(gtx.Ops).Pop()
clip.Rect{
Rect: f32.Rectangle{Max: f32.Point{X: szf, Y: szf}},
NE: rr, NW: rr, SE: rr, SW: rr,
}.Op(gtx.Ops).Add(gtx.Ops)
- macro.Add()
- stack.Pop()
+ call.Add(gtx.Ops)
return dims
}
@@ 1265,7 1256,7 @@ func toPointF(p image.Point) f32.Point {
return f32.Point{X: float32(p.X), Y: float32(p.Y)}
}
-func (ic *icon) image(c unit.Converter, col color.RGBA) paint.ImageOp {
+func (ic *icon) image(c unit.Metric, col color.RGBA) paint.ImageOp {
sz := c.Px(ic.size)
if sz == ic.imgSize {
return ic.op