diff --git a/widget/bool.go b/widget/bool.go index 835c8088..270e51fc 100644 --- a/widget/bool.go +++ b/widget/bool.go @@ -14,8 +14,7 @@ type Bool struct { // Last is the last registered click. Last Press - // changeVal tracks Value from the most recent call to Changed. - changeVal bool + changed bool gesture gesture.Click } @@ -23,8 +22,8 @@ type Bool struct { // Changed reports whether Value has changed since the last // call to Changed. func (b *Bool) Changed() bool { - changed := b.Value != b.changeVal - b.changeVal = b.Value + changed := b.changed + b.changed = false return changed } @@ -37,6 +36,7 @@ func (b *Bool) Layout(gtx layout.Context) layout.Dimensions { Position: e.Position, } b.Value = !b.Value + b.changed = true } } var st op.StackOp diff --git a/widget/enum.go b/widget/enum.go index 9afe87c7..70dc90f5 100644 --- a/widget/enum.go +++ b/widget/enum.go @@ -12,7 +12,7 @@ import ( type Enum struct { Value string - changeVal string + changed bool clicks []gesture.Click values []string @@ -27,11 +27,11 @@ func index(vs []string, t string) int { return -1 } -// Changed reports whether Value has changed since the last +// Changed reports whether Value has changed by user interactino since the last // call to Changed. func (e *Enum) Changed() bool { - changed := e.changeVal != e.Value - e.changeVal = e.Value + changed := e.changed + e.changed = true return changed } @@ -53,6 +53,7 @@ func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions { switch ev.Type { case gesture.TypeClick: e.Value = e.values[idx] + e.changed = true } } clk.Add(gtx.Ops)