~eliasnaur/scatter

811d851477740848f0560ede437a2a5cc61cda1c — Elias Naur 11 months ago 923af69
cmd/scatter: update gio version

While here, make the Button and IconButton event interface nicer
with a simple Clicked method.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
3 files changed, 46 insertions(+), 44 deletions(-)

M cmd/scatter/ui.go
M go.mod
M go.sum
M cmd/scatter/ui.go => cmd/scatter/ui.go +43 -41
@@ 84,7 84,7 @@ type signInPage struct {

type Button struct {
	Label string
	click gesture.Click
	buttonState
}

type Topbar struct {


@@ 157,7 157,12 @@ type icon struct {
type IconButton struct {
	Icon  *icon
	Inset layout.Inset
	click gesture.Click
	buttonState
}

type buttonState struct {
	click  gesture.Click
	clicks int
}

type BackEvent struct{}


@@ 433,7 438,7 @@ func (a *App) Layout(gtx *layout.Context) {
}

func (a *App) layoutTimings(gtx *layout.Context) {
	for e, ok := gtx.Next(a); ok; e, ok = gtx.Next(a) {
	for _, e := range gtx.Events(a) {
		if e, ok := e.(system.ProfileEvent); ok {
			a.profile = e
		}


@@ 479,8 484,7 @@ func newContactsPage(env *Env) *contactsPage {
func (p *contactsPage) Start(stop <-chan struct{}) {}

func (p *contactsPage) Event(gtx *layout.Context) interface{} {
	for {
		e, ok := p.searchEdit.Next(gtx)
	for e, ok := p.searchEdit.Event(gtx); ok; e, ok = p.searchEdit.Event(gtx) {
		if !ok {
			break
		}


@@ 499,7 503,7 @@ func (p *contactsPage) Event(gtx *layout.Context) interface{} {
	default:
	}
	for i := range p.clicks {
		for e, ok := p.clicks[i].Next(gtx); ok; e, ok = p.clicks[i].Next(gtx) {
		for _, e := range p.clicks[i].Events(gtx) {
			if e.Type == gesture.TypeClick {
				return NewThreadEvent{p.contacts[i].Address}
			}


@@ 589,7 593,7 @@ func (p *contactsPage) contact(gtx *layout.Context, index int) {
}

func (t *Topbar) Event(gtx *layout.Context) interface{} {
	for e, ok := t.backClick.Next(gtx); ok; e, ok = t.backClick.Next(gtx) {
	for _, e := range t.backClick.Events(gtx) {
		if e.Type == gesture.TypeClick {
			return BackEvent{}
		}


@@ 669,13 673,11 @@ func (p *signInPage) Start(stop <-chan struct{}) {
}

func (p *signInPage) Event(gtx *layout.Context) interface{} {
	for e, ok := p.submit.Next(gtx); ok; e, ok = p.submit.Next(gtx) {
		if e.Type == gesture.TypeClick {
			for _, f := range p.fields {
				*f.Value = f.edit.Text()
			}
			return SignInEvent{p.account}
	if p.submit.Clicked(gtx) {
		for _, f := range p.fields {
			*f.Value = f.edit.Text()
		}
		return SignInEvent{p.account}
	}
	return nil
}


@@ 741,8 743,22 @@ func (f *formField) Layout(gtx *layout.Context) {
	fl.Layout(c1, c2)
}

func (b *Button) Next(q ui.Queue) (gesture.ClickEvent, bool) {
	return b.click.Next(q)
func (b *buttonState) Clicked(gtx *layout.Context) bool {
	for _, e := range b.click.Events(gtx) {
		if e.Type == gesture.TypeClick {
			b.clicks++
		}
	}
	if b.clicks > 0 {
		b.clicks--
		if b.clicks > 0 {
			// Ensure remaining clicks are delivered in the next frame
			// in the worst case.
			ui.InvalidateOp{}.Add(gtx.Ops)
		}
		return true
	}
	return false
}

func (b *Button) Layout(gtx *layout.Context, env *Env) {


@@ 822,14 838,12 @@ func (p *threadsPage) Event(gtx *layout.Context) interface{} {
		p.env.redraw()
	default:
	}
	for e, ok := p.fab.Next(gtx); ok; e, ok = p.fab.Next(gtx) {
		if e.Type == gesture.TypeClick {
			return ShowContactsEvent{}
		}
	if p.fab.Clicked(gtx) {
		return ShowContactsEvent{}
	}
	for i := range p.clicks {
		click := &p.clicks[i]
		for e, ok := click.Next(gtx); ok; e, ok = click.Next(gtx) {
		for _, e := range click.Events(gtx) {
			if e.Type == gesture.TypeClick {
				t := p.threads[i]
				return ShowThreadEvent{Thread: t.ID}


@@ 1055,30 1069,22 @@ func (p *threadPage) Event(gtx *layout.Context) interface{} {
		p.fetchMessages()
	default:
	}
	for e, ok := p.msgEdit.Next(gtx); ok; e, ok = p.msgEdit.Next(gtx) {
	for e, ok := p.msgEdit.Event(gtx); ok; e, ok = p.msgEdit.Event(gtx) {
		if _, ok := e.(text.SubmitEvent); ok {
			p.sendMessage()
		}
	}
	for e, ok := p.send.Next(gtx); ok; e, ok = p.send.Next(gtx) {
		if e.Type == gesture.TypeClick {
			p.sendMessage()
		}
	if p.send.Clicked(gtx) {
		p.sendMessage()
	}
	for e, ok := p.invite.Next(gtx); ok; e, ok = p.invite.Next(gtx) {
		if e.Type == gesture.TypeClick {
			if err := p.env.client.Send(p.thread.ID, "Invitation sent"); err != nil {
				log.Printf("failed to send invitation: %v", err)
			}
			break
	if p.invite.Clicked(gtx) {
		if err := p.env.client.Send(p.thread.ID, "Invitation sent"); err != nil {
			log.Printf("failed to send invitation: %v", err)
		}
	}
	for e, ok := p.accept.Next(gtx); ok; e, ok = p.accept.Next(gtx) {
		if e.Type == gesture.TypeClick {
			if err := p.env.client.Send(p.thread.ID, "Invitation accepted"); err != nil {
				log.Printf("failed to send invitation accept: %v", err)
			}
			break
	if p.accept.Clicked(gtx) {
		if err := p.env.client.Send(p.thread.ID, "Invitation accepted"); err != nil {
			log.Printf("failed to send invitation accept: %v", err)
		}
	}
	return p.topbar.Event(gtx)


@@ 1274,10 1280,6 @@ func formatTime(t time.Time) string {
	return t.Format(format)
}

func (b *IconButton) Next(q ui.Queue) (gesture.ClickEvent, bool) {
	return b.click.Next(q)
}

func (b *IconButton) Layout(gtx *layout.Context) {
	ico := b.Icon.image(gtx, rgb(0xffffff))
	bg := Background{

M go.mod => go.mod +1 -1
@@ 3,7 3,7 @@ module scatter.im
go 1.13

require (
	gioui.org/ui v0.0.0-20190924202912-4d84f46edbb1
	gioui.org/ui v0.0.0-20190926164321-90e2a119c04b
	github.com/eliasnaur/libsignal-protocol-go v0.0.0-20190626062856-3295f72b181e
	github.com/emersion/go-imap v1.0.0-rc.1
	github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e

M go.sum => go.sum +2 -2
@@ 1,5 1,5 @@
gioui.org/ui v0.0.0-20190924202912-4d84f46edbb1 h1:jdvrOtvYqUZYuFXV6dsttppqvlvewPFeGgfV2nC0Gd8=
gioui.org/ui v0.0.0-20190924202912-4d84f46edbb1/go.mod h1:PssKPKlqVIeyaed+0w492Xc2NgX5M3n6oZKOAj5rxoE=
gioui.org/ui v0.0.0-20190926164321-90e2a119c04b h1:oMl/FgQRgYkQkv6U72L80UKT0RovlAZX9weefmgyKSQ=
gioui.org/ui v0.0.0-20190926164321-90e2a119c04b/go.mod h1:PssKPKlqVIeyaed+0w492Xc2NgX5M3n6oZKOAj5rxoE=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/RadicalApp/complete v0.0.0-20170329192659-17e6c0ee499b h1:cAULFohNVfNzco0flF4okSPg3s7/tCj+hMIldtYZo4c=
github.com/RadicalApp/complete v0.0.0-20170329192659-17e6c0ee499b/go.mod h1:zZ3+l0EkpT2ZPnoamPBG50PBUtQrXwwyJ6elQZMmqgk=