mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: redefine Enum.Changed and Bool.Changed to consider only user interaction
Ignore programmatic value changes to avoid feedback loops. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+5
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user