From f08568a6dfc3890dcc8ea76c11f1a4cd436a57c1 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 5 May 2020 11:33:41 +0200 Subject: [PATCH] widget: report whether Value changed after Enum.Update and Bool.Update Signed-off-by: Elias Naur --- widget/bool.go | 7 +++++-- widget/enum.go | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/widget/bool.go b/widget/bool.go index cbef01c8..ec459ac3 100644 --- a/widget/bool.go +++ b/widget/bool.go @@ -14,8 +14,10 @@ type Bool struct { gesture gesture.Click } -// Update the checked state according to incoming events. -func (b *Bool) Update(gtx *layout.Context) { +// Update the checked state according to incoming events, +// and reports whether Value changed. +func (b *Bool) Update(gtx *layout.Context) bool { + was := b.Value for _, e := range b.gesture.Events(gtx) { switch e.Type { case gesture.TypeClick: @@ -26,6 +28,7 @@ func (b *Bool) Update(gtx *layout.Context) { b.Value = !b.Value } } + return b.Value != was } func (b *Bool) Layout(gtx *layout.Context) { diff --git a/widget/enum.go b/widget/enum.go index 0b10bada..6068740d 100644 --- a/widget/enum.go +++ b/widget/enum.go @@ -21,8 +21,10 @@ func index(vs []string, t string) int { return -1 } -// Update the Value according to incoming events. -func (e *Enum) Update(gtx *layout.Context) { +// Update the Value according to incoming events, and +// reports whether Value changed. +func (e *Enum) Update(gtx *layout.Context) bool { + was := e.Value for i := range e.clicks { for _, ev := range e.clicks[i].Events(gtx) { switch ev.Type { @@ -31,6 +33,7 @@ func (e *Enum) Update(gtx *layout.Context) { } } } + return e.Value != was } // Layout adds the event handler for key.