diff --git a/app/app_theme_wasm.go b/app/app_theme_wasm.go index a67a820b23..8bcc5f34fc 100644 --- a/app/app_theme_wasm.go +++ b/app/app_theme_wasm.go @@ -23,7 +23,7 @@ func defaultVariant() fyne.ThemeVariant { func init() { if matchMedia := js.Global().Call("matchMedia", "(prefers-color-scheme: dark)"); matchMedia.Truthy() { - matchMedia.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) interface{} { + matchMedia.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) any { fyne.CurrentApp().Settings().(*settings).setupTheme() return nil })) diff --git a/app/preferences.go b/app/preferences.go index 9ada3f675c..33ff6bfe4d 100644 --- a/app/preferences.go +++ b/app/preferences.go @@ -80,7 +80,7 @@ func (p *preferences) saveToFile(path string) error { defer file.Close() encode := json.NewEncoder(file) - p.InMemoryPreferences.ReadValues(func(values map[string]interface{}) { + p.InMemoryPreferences.ReadValues(func(values map[string]any) { err = encode.Encode(&values) }) @@ -120,7 +120,7 @@ func (p *preferences) loadFromFile(path string) (err error) { p.loadingInProgress = true p.prefLock.Unlock() - p.InMemoryPreferences.WriteValues(func(values map[string]interface{}) { + p.InMemoryPreferences.WriteValues(func(values map[string]any) { err = decode.Decode(&values) if err != nil { return @@ -170,9 +170,9 @@ func newPreferences(app *fyneApp) *preferences { return p } -func convertLists(values map[string]interface{}) { +func convertLists(values map[string]any) { for k, v := range values { - if items, ok := v.([]interface{}); ok { + if items, ok := v.([]any); ok { if len(items) == 0 { continue } diff --git a/app/preferences_test.go b/app/preferences_test.go index 7a189aacfb..9f0de61e2c 100644 --- a/app/preferences_test.go +++ b/app/preferences_test.go @@ -17,7 +17,7 @@ func loadPreferences(id string) *preferences { func TestPreferences_Remove(t *testing.T) { p := loadPreferences("dummy") - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["keyString"] = "value" val["keyInt"] = 4 }) @@ -34,7 +34,7 @@ func TestPreferences_Remove(t *testing.T) { func TestPreferences_Save(t *testing.T) { p := loadPreferences("dummy") - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["keyString"] = "value" val["keyStringList"] = []string{"1", "2", "3"} val["keyInt"] = 4 @@ -68,7 +68,7 @@ func TestPreferences_Save(t *testing.T) { func TestPreferences_Save_OverwriteFast(t *testing.T) { p := loadPreferences("dummy2") - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["key"] = "value" }) @@ -76,7 +76,7 @@ func TestPreferences_Save_OverwriteFast(t *testing.T) { defer os.Remove(path) p.saveToFile(path) - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["key2"] = "value2" }) p.saveToFile(path) diff --git a/app/settings.go b/app/settings.go index cc0d32ed42..bac0469530 100644 --- a/app/settings.go +++ b/app/settings.go @@ -38,8 +38,8 @@ type settings struct { themeSpecified bool variant fyne.ThemeVariant - changeListeners sync.Map // map[chan fyne.Settings]bool - watcher interface{} // normally *fsnotify.Watcher or nil - avoid import in this file + changeListeners sync.Map // map[chan fyne.Settings]bool + watcher any // normally *fsnotify.Watcher or nil - avoid import in this file schema SettingsSchema } @@ -104,7 +104,7 @@ func (s *settings) AddChangeListener(listener chan fyne.Settings) { } func (s *settings) apply() { - s.changeListeners.Range(func(key, _ interface{}) bool { + s.changeListeners.Range(func(key, _ any) bool { listener := key.(chan fyne.Settings) select { case listener <- s: diff --git a/app/settings_desktop_test.go b/app/settings_desktop_test.go index 0ffcd93bea..90d810c48b 100644 --- a/app/settings_desktop_test.go +++ b/app/settings_desktop_test.go @@ -45,7 +45,7 @@ func TestWatchFile(t *testing.T) { f.Close() defer os.Remove(path) - called := make(chan interface{}, 1) + called := make(chan any, 1) watchFile(path, func() { called <- true }) @@ -66,7 +66,7 @@ func TestFileWatcher_FileDeleted(t *testing.T) { f.Close() defer os.Remove(path) - called := make(chan interface{}, 1) + called := make(chan any, 1) watcher := watchFile(path, func() { called <- true }) diff --git a/cmd/fyne/internal/commands/mock_runner_test.go b/cmd/fyne/internal/commands/mock_runner_test.go index 21dfa0e46d..c22f0e75fe 100644 --- a/cmd/fyne/internal/commands/mock_runner_test.go +++ b/cmd/fyne/internal/commands/mock_runner_test.go @@ -10,7 +10,7 @@ import ( ) type expectedValue struct { - dir interface{} + dir any env []string osEnv bool args []string diff --git a/cmd/fyne/internal/commands/release.go b/cmd/fyne/internal/commands/release.go index 43fe05cf67..6110da3f0d 100644 --- a/cmd/fyne/internal/commands/release.go +++ b/cmd/fyne/internal/commands/release.go @@ -499,7 +499,7 @@ func (r *Releaser) validate() error { return nil } -func (r *Releaser) writeEntitlements(tmpl *template.Template, entitlementData interface{}) (cleanup func(), err error) { +func (r *Releaser) writeEntitlements(tmpl *template.Template, entitlementData any) (cleanup func(), err error) { entitlementPath := filepath.Join(r.dir, "entitlements.plist") entitlements, err := os.Create(entitlementPath) if err != nil { diff --git a/cmd/fyne/internal/mobile/build.go b/cmd/fyne/internal/mobile/build.go index db3100d43c..39c591fbd6 100644 --- a/cmd/fyne/internal/mobile/build.go +++ b/cmd/fyne/internal/mobile/build.go @@ -232,7 +232,7 @@ func extractPkgs(nm string, path string) (map[string]bool, error) { var xout io.Writer = os.Stderr -func printcmd(format string, args ...interface{}) { +func printcmd(format string, args ...any) { cmd := fmt.Sprintf(format+"\n", args...) if tmpdir != "" { cmd = strings.Replace(cmd, tmpdir, "$WORK", -1) diff --git a/cmd/fyne_demo/tutorials/widget.go b/cmd/fyne_demo/tutorials/widget.go index d40738ece0..2eb45b4f30 100644 --- a/cmd/fyne_demo/tutorials/widget.go +++ b/cmd/fyne_demo/tutorials/widget.go @@ -35,7 +35,7 @@ var ( progress *widget.ProgressBar fprogress *widget.ProgressBar infProgress *widget.ProgressBarInfinite - endProgress chan interface{} + endProgress chan any ) func makeAccordionTab(_ fyne.Window) fyne.CanvasObject { @@ -377,7 +377,7 @@ func makeProgressTab(_ fyne.Window) fyne.CanvasObject { } infProgress = widget.NewProgressBarInfinite() - endProgress = make(chan interface{}, 1) + endProgress = make(chan any, 1) startProgress() return container.NewVBox( diff --git a/data/binding/binding.go b/data/binding/binding.go index 2034217b33..8183f7b7c8 100644 --- a/data/binding/binding.go +++ b/data/binding/binding.go @@ -74,26 +74,26 @@ func (b *base) RemoveListener(l DataListener) { } func (b *base) trigger() { - b.listeners.Range(func(key, _ interface{}) bool { + b.listeners.Range(func(key, _ any) bool { queueItem(key.(DataListener).DataChanged) return true }) } -// Untyped supports binding a interface{} value. +// Untyped supports binding a any value. // // Since: 2.1 type Untyped interface { DataItem - Get() (interface{}, error) - Set(interface{}) error + Get() (any, error) + Set(any) error } -// NewUntyped returns a bindable interface{} value that is managed internally. +// NewUntyped returns a bindable any value that is managed internally. // // Since: 2.1 func NewUntyped() Untyped { - var blank interface{} = nil + var blank any = nil v := &blank return &boundUntyped{val: reflect.ValueOf(v).Elem()} } @@ -104,14 +104,14 @@ type boundUntyped struct { val reflect.Value } -func (b *boundUntyped) Get() (interface{}, error) { +func (b *boundUntyped) Get() (any, error) { b.lock.RLock() defer b.lock.RUnlock() return b.val.Interface(), nil } -func (b *boundUntyped) Set(val interface{}) error { +func (b *boundUntyped) Set(val any) error { b.lock.Lock() defer b.lock.Unlock() if b.val.Interface() == val { @@ -124,7 +124,7 @@ func (b *boundUntyped) Set(val interface{}) error { return nil } -// ExternalUntyped supports binding a interface{} value to an external value. +// ExternalUntyped supports binding a any value to an external value. // // Since: 2.1 type ExternalUntyped interface { @@ -132,11 +132,11 @@ type ExternalUntyped interface { Reload() error } -// BindUntyped returns a bindable interface{} value that is bound to an external type. +// BindUntyped returns a bindable any value that is bound to an external type. // The parameter must be a pointer to the type you wish to bind. // // Since: 2.1 -func BindUntyped(v interface{}) ExternalUntyped { +func BindUntyped(v any) ExternalUntyped { t := reflect.TypeOf(v) if t.Kind() != reflect.Ptr { fyne.LogError("Invalid type passed to BindUntyped, must be a pointer", nil) @@ -144,7 +144,7 @@ func BindUntyped(v interface{}) ExternalUntyped { } if v == nil { - var blank interface{} + var blank any v = &blank // never allow a nil value pointer } @@ -157,10 +157,10 @@ func BindUntyped(v interface{}) ExternalUntyped { type boundExternalUntyped struct { boundUntyped - old interface{} + old any } -func (b *boundExternalUntyped) Set(val interface{}) error { +func (b *boundExternalUntyped) Set(val any) error { b.lock.Lock() defer b.lock.Unlock() if b.old == val { diff --git a/data/binding/binding_test.go b/data/binding/binding_test.go index 7191bab1df..a9e2d5394b 100644 --- a/data/binding/binding_test.go +++ b/data/binding/binding_test.go @@ -8,7 +8,7 @@ import ( ) func syncMapLen(m *sync.Map) (n int) { - m.Range(func(_, _ interface{}) bool { + m.Range(func(_, _ any) bool { n++ return true }) diff --git a/data/binding/binditems_test.go b/data/binding/binditems_test.go index 0bd517e978..3ed9847beb 100644 --- a/data/binding/binditems_test.go +++ b/data/binding/binditems_test.go @@ -41,7 +41,7 @@ func TestBindFloat(t *testing.T) { } func TestBindUntyped(t *testing.T) { - var val interface{} + var val any val = 0.5 f := BindUntyped(&val) v, err := f.Get() diff --git a/data/binding/bindlists.go b/data/binding/bindlists.go index 9b2430f4f7..5aa8c9ae68 100644 --- a/data/binding/bindlists.go +++ b/data/binding/bindlists.go @@ -1545,22 +1545,22 @@ func (b *boundExternalStringListItem) setIfChanged(val string) error { return nil } -// UntypedList supports binding a list of interface{} values. +// UntypedList supports binding a list of any values. // // Since: 2.1 type UntypedList interface { DataList - Append(value interface{}) error - Get() ([]interface{}, error) - GetValue(index int) (interface{}, error) - Prepend(value interface{}) error - Remove(value interface{}) error - Set(list []interface{}) error - SetValue(index int, value interface{}) error + Append(value any) error + Get() ([]any, error) + GetValue(index int) (any, error) + Prepend(value any) error + Remove(value any) error + Set(list []any) error + SetValue(index int, value any) error } -// ExternalUntypedList supports binding a list of interface{} values from an external variable. +// ExternalUntypedList supports binding a list of any values from an external variable. // // Since: 2.1 type ExternalUntypedList interface { @@ -1569,18 +1569,18 @@ type ExternalUntypedList interface { Reload() error } -// NewUntypedList returns a bindable list of interface{} values. +// NewUntypedList returns a bindable list of any values. // // Since: 2.1 func NewUntypedList() UntypedList { - return &boundUntypedList{val: &[]interface{}{}} + return &boundUntypedList{val: &[]any{}} } -// BindUntypedList returns a bound list of interface{} values, based on the contents of the passed slice. +// BindUntypedList returns a bound list of any values, based on the contents of the passed slice. // If your code changes the content of the slice this refers to you should call Reload() to inform the bindings. // // Since: 2.1 -func BindUntypedList(v *[]interface{}) ExternalUntypedList { +func BindUntypedList(v *[]any) ExternalUntypedList { if v == nil { return NewUntypedList().(ExternalUntypedList) } @@ -1598,10 +1598,10 @@ type boundUntypedList struct { listBase updateExternal bool - val *[]interface{} + val *[]any } -func (l *boundUntypedList) Append(val interface{}) error { +func (l *boundUntypedList) Append(val any) error { l.lock.Lock() defer l.lock.Unlock() @@ -1610,14 +1610,14 @@ func (l *boundUntypedList) Append(val interface{}) error { return l.doReload() } -func (l *boundUntypedList) Get() ([]interface{}, error) { +func (l *boundUntypedList) Get() ([]any, error) { l.lock.RLock() defer l.lock.RUnlock() return *l.val, nil } -func (l *boundUntypedList) GetValue(i int) (interface{}, error) { +func (l *boundUntypedList) GetValue(i int) (any, error) { l.lock.RLock() defer l.lock.RUnlock() @@ -1628,10 +1628,10 @@ func (l *boundUntypedList) GetValue(i int) (interface{}, error) { return (*l.val)[i], nil } -func (l *boundUntypedList) Prepend(val interface{}) error { +func (l *boundUntypedList) Prepend(val any) error { l.lock.Lock() defer l.lock.Unlock() - *l.val = append([]interface{}{val}, *l.val...) + *l.val = append([]any{val}, *l.val...) return l.doReload() } @@ -1643,10 +1643,10 @@ func (l *boundUntypedList) Reload() error { return l.doReload() } -// Remove takes the specified interface{} out of the list. +// Remove takes the specified any out of the list. // // Since: 2.5 -func (l *boundUntypedList) Remove(val interface{}) error { +func (l *boundUntypedList) Remove(val any) error { l.lock.Lock() defer l.lock.Unlock() @@ -1676,7 +1676,7 @@ func (l *boundUntypedList) Remove(val interface{}) error { return l.doReload() } -func (l *boundUntypedList) Set(v []interface{}) error { +func (l *boundUntypedList) Set(v []any) error { l.lock.Lock() defer l.lock.Unlock() *l.val = v @@ -1721,7 +1721,7 @@ func (l *boundUntypedList) doReload() (retErr error) { return } -func (l *boundUntypedList) SetValue(i int, v interface{}) error { +func (l *boundUntypedList) SetValue(i int, v any) error { l.lock.RLock() len := l.Length() l.lock.RUnlock() @@ -1741,7 +1741,7 @@ func (l *boundUntypedList) SetValue(i int, v interface{}) error { return item.(Untyped).Set(v) } -func bindUntypedListItem(v *[]interface{}, i int, external bool) Untyped { +func bindUntypedListItem(v *[]any, i int, external bool) Untyped { if external { ret := &boundExternalUntypedListItem{old: (*v)[i]} ret.val = v @@ -1755,11 +1755,11 @@ func bindUntypedListItem(v *[]interface{}, i int, external bool) Untyped { type boundUntypedListItem struct { base - val *[]interface{} + val *[]any index int } -func (b *boundUntypedListItem) Get() (interface{}, error) { +func (b *boundUntypedListItem) Get() (any, error) { b.lock.Lock() defer b.lock.Unlock() @@ -1770,14 +1770,14 @@ func (b *boundUntypedListItem) Get() (interface{}, error) { return (*b.val)[b.index], nil } -func (b *boundUntypedListItem) Set(val interface{}) error { +func (b *boundUntypedListItem) Set(val any) error { b.lock.Lock() defer b.lock.Unlock() return b.doSet(val) } -func (b *boundUntypedListItem) doSet(val interface{}) error { +func (b *boundUntypedListItem) doSet(val any) error { (*b.val)[b.index] = val b.trigger() @@ -1787,10 +1787,10 @@ func (b *boundUntypedListItem) doSet(val interface{}) error { type boundExternalUntypedListItem struct { boundUntypedListItem - old interface{} + old any } -func (b *boundExternalUntypedListItem) setIfChanged(val interface{}) error { +func (b *boundExternalUntypedListItem) setIfChanged(val any) error { if val == b.old { return nil } diff --git a/data/binding/bindtrees.go b/data/binding/bindtrees.go index d7f39e1d82..daf686bb30 100644 --- a/data/binding/bindtrees.go +++ b/data/binding/bindtrees.go @@ -1719,22 +1719,22 @@ func (t *boundExternalStringTreeItem) setIfChanged(val string) error { return nil } -// UntypedTree supports binding a tree of interface{} values. +// UntypedTree supports binding a tree of any values. // // Since: 2.4 type UntypedTree interface { DataTree - Append(parent, id string, value interface{}) error - Get() (map[string][]string, map[string]interface{}, error) - GetValue(id string) (interface{}, error) - Prepend(parent, id string, value interface{}) error + Append(parent, id string, value any) error + Get() (map[string][]string, map[string]any, error) + GetValue(id string) (any, error) + Prepend(parent, id string, value any) error Remove(id string) error - Set(ids map[string][]string, values map[string]interface{}) error - SetValue(id string, value interface{}) error + Set(ids map[string][]string, values map[string]any) error + SetValue(id string, value any) error } -// ExternalUntypedTree supports binding a tree of interface{} values from an external variable. +// ExternalUntypedTree supports binding a tree of any values from an external variable. // // Since: 2.4 type ExternalUntypedTree interface { @@ -1743,22 +1743,22 @@ type ExternalUntypedTree interface { Reload() error } -// NewUntypedTree returns a bindable tree of interface{} values. +// NewUntypedTree returns a bindable tree of any values. // // Since: 2.4 func NewUntypedTree() UntypedTree { - t := &boundUntypedTree{val: &map[string]interface{}{}} + t := &boundUntypedTree{val: &map[string]any{}} t.ids = make(map[string][]string) t.items = make(map[string]DataItem) return t } -// BindUntypedTree returns a bound tree of interface{} values, based on the contents of the passed values. +// BindUntypedTree returns a bound tree of any values, based on the contents of the passed values. // The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. // If your code changes the content of the maps this refers to you should call Reload() to inform the bindings. // // Since: 2.4 -func BindUntypedTree(ids *map[string][]string, v *map[string]interface{}) ExternalUntypedTree { +func BindUntypedTree(ids *map[string][]string, v *map[string]any) ExternalUntypedTree { if v == nil { return NewUntypedTree().(ExternalUntypedTree) } @@ -1780,10 +1780,10 @@ type boundUntypedTree struct { treeBase updateExternal bool - val *map[string]interface{} + val *map[string]any } -func (t *boundUntypedTree) Append(parent, id string, val interface{}) error { +func (t *boundUntypedTree) Append(parent, id string, val any) error { t.lock.Lock() defer t.lock.Unlock() ids, ok := t.ids[parent] @@ -1798,14 +1798,14 @@ func (t *boundUntypedTree) Append(parent, id string, val interface{}) error { return t.doReload() } -func (t *boundUntypedTree) Get() (map[string][]string, map[string]interface{}, error) { +func (t *boundUntypedTree) Get() (map[string][]string, map[string]any, error) { t.lock.RLock() defer t.lock.RUnlock() return t.ids, *t.val, nil } -func (t *boundUntypedTree) GetValue(id string) (interface{}, error) { +func (t *boundUntypedTree) GetValue(id string) (any, error) { t.lock.RLock() defer t.lock.RUnlock() @@ -1816,7 +1816,7 @@ func (t *boundUntypedTree) GetValue(id string) (interface{}, error) { return nil, errOutOfBounds } -func (t *boundUntypedTree) Prepend(parent, id string, val interface{}) error { +func (t *boundUntypedTree) Prepend(parent, id string, val any) error { t.lock.Lock() defer t.lock.Unlock() ids, ok := t.ids[parent] @@ -1864,7 +1864,7 @@ func (t *boundUntypedTree) Reload() error { return t.doReload() } -func (t *boundUntypedTree) Set(ids map[string][]string, v map[string]interface{}) error { +func (t *boundUntypedTree) Set(ids map[string][]string, v map[string]any) error { t.lock.Lock() defer t.lock.Unlock() t.ids = ids @@ -1931,7 +1931,7 @@ func (t *boundUntypedTree) doReload() (retErr error) { return } -func (t *boundUntypedTree) SetValue(id string, v interface{}) error { +func (t *boundUntypedTree) SetValue(id string, v any) error { t.lock.Lock() (*t.val)[id] = v t.lock.Unlock() @@ -1943,7 +1943,7 @@ func (t *boundUntypedTree) SetValue(id string, v interface{}) error { return item.(Untyped).Set(v) } -func bindUntypedTreeItem(v *map[string]interface{}, id string, external bool) Untyped { +func bindUntypedTreeItem(v *map[string]any, id string, external bool) Untyped { if external { ret := &boundExternalUntypedTreeItem{old: (*v)[id]} ret.val = v @@ -1957,11 +1957,11 @@ func bindUntypedTreeItem(v *map[string]interface{}, id string, external bool) Un type boundUntypedTreeItem struct { base - val *map[string]interface{} + val *map[string]any id string } -func (t *boundUntypedTreeItem) Get() (interface{}, error) { +func (t *boundUntypedTreeItem) Get() (any, error) { t.lock.Lock() defer t.lock.Unlock() @@ -1973,14 +1973,14 @@ func (t *boundUntypedTreeItem) Get() (interface{}, error) { return nil, errOutOfBounds } -func (t *boundUntypedTreeItem) Set(val interface{}) error { +func (t *boundUntypedTreeItem) Set(val any) error { t.lock.Lock() defer t.lock.Unlock() return t.doSet(val) } -func (t *boundUntypedTreeItem) doSet(val interface{}) error { +func (t *boundUntypedTreeItem) doSet(val any) error { (*t.val)[t.id] = val t.trigger() @@ -1990,10 +1990,10 @@ func (t *boundUntypedTreeItem) doSet(val interface{}) error { type boundExternalUntypedTreeItem struct { boundUntypedTreeItem - old interface{} + old any } -func (t *boundExternalUntypedTreeItem) setIfChanged(val interface{}) error { +func (t *boundExternalUntypedTreeItem) setIfChanged(val any) error { if val == t.old { return nil } diff --git a/data/binding/gen.go b/data/binding/gen.go index 6b444a8ad6..4e9746559a 100644 --- a/data/binding/gen.go +++ b/data/binding/gen.go @@ -973,7 +973,7 @@ package binding return f, nil } -func writeFile(f *os.File, t *template.Template, d interface{}) { +func writeFile(f *os.File, t *template.Template, d any) { if err := t.Execute(f, d); err != nil { fyne.LogError("Unable to write file "+f.Name(), err) } @@ -1058,7 +1058,7 @@ import ( {Name: "Int", Type: "int", Default: "0", Format: "%d", SupportsPreferences: true}, {Name: "Rune", Type: "rune", Default: "rune(0)"}, {Name: "String", Type: "string", Default: "\"\"", SupportsPreferences: true}, - {Name: "Untyped", Type: "interface{}", Default: "nil", Since: "2.1"}, + {Name: "Untyped", Type: "any", Default: "nil", Since: "2.1"}, {Name: "URI", Type: "fyne.URI", Default: "fyne.URI(nil)", Since: "2.1", FromString: "uriFromString", ToString: "uriToString", Comparator: "compareURI"}, } @@ -1070,7 +1070,7 @@ import ( writeFile(listFile, list, b) writeFile(treeFile, tree, b) if b.Name == "Untyped" { - continue // interface{} is special, we have it in binding.go instead + continue // any is special, we have it in binding.go instead } writeFile(itemFile, item, b) diff --git a/data/binding/mapbinding.go b/data/binding/mapbinding.go index f6ec68cfbc..cfc2468075 100644 --- a/data/binding/mapbinding.go +++ b/data/binding/mapbinding.go @@ -16,7 +16,7 @@ type DataMap interface { Keys() []string } -// ExternalUntypedMap is a map data binding with all values untyped (interface{}), connected to an external data source. +// ExternalUntypedMap is a map data binding with all values untyped (any), connected to an external data source. // // Since: 2.0 type ExternalUntypedMap interface { @@ -24,30 +24,30 @@ type ExternalUntypedMap interface { Reload() error } -// UntypedMap is a map data binding with all values Untyped (interface{}). +// UntypedMap is a map data binding with all values Untyped (any). // // Since: 2.0 type UntypedMap interface { DataMap Delete(string) - Get() (map[string]interface{}, error) - GetValue(string) (interface{}, error) - Set(map[string]interface{}) error - SetValue(string, interface{}) error + Get() (map[string]any, error) + GetValue(string) (any, error) + Set(map[string]any) error + SetValue(string, any) error } -// NewUntypedMap creates a new, empty map binding of string to interface{}. +// NewUntypedMap creates a new, empty map binding of string to any. // // Since: 2.0 func NewUntypedMap() UntypedMap { - return &mapBase{items: make(map[string]reflectUntyped), val: &map[string]interface{}{}} + return &mapBase{items: make(map[string]reflectUntyped), val: &map[string]any{}} } -// BindUntypedMap creates a new map binding of string to interface{} based on the data passed. +// BindUntypedMap creates a new map binding of string to any based on the data passed. // If your code changes the content of the map this refers to you should call Reload() to inform the bindings. // // Since: 2.0 -func BindUntypedMap(d *map[string]interface{}) ExternalUntypedMap { +func BindUntypedMap(d *map[string]any) ExternalUntypedMap { if d == nil { return NewUntypedMap().(ExternalUntypedMap) } @@ -65,17 +65,17 @@ func BindUntypedMap(d *map[string]interface{}) ExternalUntypedMap { // Since: 2.0 type Struct interface { DataMap - GetValue(string) (interface{}, error) - SetValue(string, interface{}) error + GetValue(string) (any, error) + SetValue(string, any) error Reload() error } -// BindStruct creates a new map binding of string to interface{} using the struct passed as data. -// The key for each item is a string representation of each exported field with the value set as an interface{}. +// BindStruct creates a new map binding of string to any using the struct passed as data. +// The key for each item is a string representation of each exported field with the value set as an any. // Only exported fields are included. // // Since: 2.0 -func BindStruct(i interface{}) Struct { +func BindStruct(i any) Struct { if i == nil { return NewUntypedMap().(Struct) } @@ -88,7 +88,7 @@ func BindStruct(i interface{}) Struct { s := &boundStruct{orig: i} s.items = make(map[string]reflectUntyped) - s.val = &map[string]interface{}{} + s.val = &map[string]any{} s.updateExternal = true v := reflect.ValueOf(i).Elem() @@ -109,8 +109,8 @@ func BindStruct(i interface{}) Struct { type reflectUntyped interface { DataItem - get() (interface{}, error) - set(interface{}) error + get() (any, error) + set(any) error } type mapBase struct { @@ -118,7 +118,7 @@ type mapBase struct { updateExternal bool items map[string]reflectUntyped - val *map[string]interface{} + val *map[string]any } func (b *mapBase) GetItem(key string) (DataItem, error) { @@ -155,18 +155,18 @@ func (b *mapBase) Delete(key string) { b.trigger() } -func (b *mapBase) Get() (map[string]interface{}, error) { +func (b *mapBase) Get() (map[string]any, error) { b.lock.RLock() defer b.lock.RUnlock() if b.val == nil { - return map[string]interface{}{}, nil + return map[string]any{}, nil } return *b.val, nil } -func (b *mapBase) GetValue(key string) (interface{}, error) { +func (b *mapBase) GetValue(key string) (any, error) { b.lock.RLock() defer b.lock.RUnlock() @@ -184,7 +184,7 @@ func (b *mapBase) Reload() error { return b.doReload() } -func (b *mapBase) Set(v map[string]interface{}) error { +func (b *mapBase) Set(v map[string]any) error { b.lock.Lock() defer b.lock.Unlock() @@ -198,7 +198,7 @@ func (b *mapBase) Set(v map[string]interface{}) error { return b.doReload() } -func (b *mapBase) SetValue(key string, d interface{}) error { +func (b *mapBase) SetValue(key string, d any) error { b.lock.Lock() defer b.lock.Unlock() @@ -260,7 +260,7 @@ func (b *mapBase) setItem(key string, d reflectUntyped) { type boundStruct struct { mapBase - orig interface{} + orig any } func (b *boundStruct) Reload() (retErr error) { @@ -305,7 +305,7 @@ func (b *boundStruct) Reload() (retErr error) { return } -func bindUntypedMapValue(m *map[string]interface{}, k string, external bool) reflectUntyped { +func bindUntypedMapValue(m *map[string]any, k string, external bool) reflectUntyped { if external { ret := &boundExternalMapValue{old: (*m)[k]} ret.val = m @@ -319,11 +319,11 @@ func bindUntypedMapValue(m *map[string]interface{}, k string, external bool) ref type boundMapValue struct { base - val *map[string]interface{} + val *map[string]any key string } -func (b *boundMapValue) get() (interface{}, error) { +func (b *boundMapValue) get() (any, error) { if v, ok := (*b.val)[b.key]; ok { return v, nil } @@ -331,7 +331,7 @@ func (b *boundMapValue) get() (interface{}, error) { return nil, errKeyNotFound } -func (b *boundMapValue) set(val interface{}) error { +func (b *boundMapValue) set(val any) error { (*b.val)[b.key] = val b.trigger() @@ -341,10 +341,10 @@ func (b *boundMapValue) set(val interface{}) error { type boundExternalMapValue struct { boundMapValue - old interface{} + old any } -func (b *boundExternalMapValue) setIfChanged(val interface{}) error { +func (b *boundExternalMapValue) setIfChanged(val any) error { if val == b.old { return nil } @@ -359,11 +359,11 @@ type boundReflect struct { val reflect.Value } -func (b *boundReflect) get() (interface{}, error) { +func (b *boundReflect) get() (any, error) { return b.val.Interface(), nil } -func (b *boundReflect) set(val interface{}) (err error) { +func (b *boundReflect) set(val any) (err error) { defer func() { if r := recover(); r != nil { err = errors.New("unable to set bool in data binding") diff --git a/data/binding/mapbinding_test.go b/data/binding/mapbinding_test.go index ffdb1fe83c..fb33aab0f5 100644 --- a/data/binding/mapbinding_test.go +++ b/data/binding/mapbinding_test.go @@ -138,7 +138,7 @@ func TestBindStruct_Reload(t *testing.T) { } func TestBindUntypedMap(t *testing.T) { - m := map[string]interface{}{ + m := map[string]any{ "foo": "bar", "val": 5, "bas": 0.2, @@ -168,7 +168,7 @@ func TestBindUntypedMap(t *testing.T) { } func TestExternalUntypedMap_Reload(t *testing.T) { - m := map[string]interface{}{ + m := map[string]any{ "foo": "bar", "val": 5, "bas": 0.2, @@ -207,7 +207,7 @@ func TestExternalUntypedMap_Reload(t *testing.T) { assert.True(t, calledChild) calledMap, calledChild = false, false - m = map[string]interface{}{ + m = map[string]any{ "foo": "bar", "val": 5, } @@ -220,7 +220,7 @@ func TestExternalUntypedMap_Reload(t *testing.T) { assert.True(t, calledChild) calledMap, calledChild = false, false - m = map[string]interface{}{ + m = map[string]any{ "foo": "bar", "val": 5, "new": "longer", @@ -235,7 +235,7 @@ func TestExternalUntypedMap_Reload(t *testing.T) { } func TestUntypedMap_Delete(t *testing.T) { - m := map[string]interface{}{ + m := map[string]any{ "foo": "bar", "val": 5, } @@ -261,7 +261,7 @@ func TestUntypedMap_Delete(t *testing.T) { } func TestUntypedMap_Set(t *testing.T) { - m := map[string]interface{}{ + m := map[string]any{ "foo": "bar", "val": 5, } @@ -279,7 +279,7 @@ func TestUntypedMap_Set(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 5, v) - m = map[string]interface{}{ + m = map[string]any{ "foo": "new", "bas": "another", "val": 7, @@ -295,7 +295,7 @@ func TestUntypedMap_Set(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 7, v) - m = map[string]interface{}{ + m = map[string]any{ "val": 9, } err = b.Set(m) diff --git a/data/binding/pref_helper.go b/data/binding/pref_helper.go index 5ee5b4eece..e37c367d3a 100644 --- a/data/binding/pref_helper.go +++ b/data/binding/pref_helper.go @@ -24,7 +24,7 @@ func (b *preferenceBindings) getItem(key string) preferenceItem { func (b *preferenceBindings) list() []preferenceItem { ret := []preferenceItem{} - b.items.Range(func(_, val interface{}) bool { + b.items.Range(func(_, val any) bool { ret = append(ret, val.(preferenceItem)) return true }) diff --git a/data/binding/preference_test.go b/data/binding/preference_test.go index ba511f2283..49852d5c14 100644 --- a/data/binding/preference_test.go +++ b/data/binding/preference_test.go @@ -142,7 +142,7 @@ func TestPreferenceBindingTriggers(t *testing.T) { bind1 := BindPreferenceString(key, p) bind2 := BindPreferenceString(key, p) - ch := make(chan interface{}, 2) + ch := make(chan any, 2) bind1.AddListener(NewDataListener(func() { ch <- struct{}{} })) diff --git a/data/binding/sprintf.go b/data/binding/sprintf.go index 3389cf9c54..faa39b5f64 100644 --- a/data/binding/sprintf.go +++ b/data/binding/sprintf.go @@ -35,7 +35,7 @@ func NewSprintf(format string, b ...DataItem) String { } func (s *sprintfString) DataChanged() { - data := make([]interface{}, 0, len(s.source)) + data := make([]any, 0, len(s.source)) s.err = nil for _, value := range s.source { @@ -112,7 +112,7 @@ func (s *sprintfString) Get() (string, error) { } func (s *sprintfString) Set(str string) error { - data := make([]interface{}, 0, len(s.source)) + data := make([]any, 0, len(s.source)) s.err = nil for _, value := range s.source { diff --git a/dialog/file.go b/dialog/file.go index 64ac9f3382..05c8648caf 100644 --- a/dialog/file.go +++ b/dialog/file.go @@ -71,7 +71,7 @@ type fileDialog struct { // FileDialog is a dialog containing a file picker for use in opening or saving files. type FileDialog struct { - callback interface{} + callback any onClosedCallback func(bool) parent fyne.Window dialog *fileDialog diff --git a/driver/native_android.go b/driver/native_android.go index bd7f383b96..59150cb0dc 100644 --- a/driver/native_android.go +++ b/driver/native_android.go @@ -9,7 +9,7 @@ import "fyne.io/fyne/v2/internal/driver/mobile/app" // On Android this provides the JVM pointers required to execute various NDK calls or use JNI APIs. // // Since: 2.3 -func RunNative(fn func(interface{}) error) error { +func RunNative(fn func(any) error) error { return app.RunOnJVM(func(vm, env, ctx uintptr) error { data := &AndroidContext{VM: vm, Env: env, Ctx: ctx} return fn(data) diff --git a/driver/native_other.go b/driver/native_other.go index 8dac0d8d5c..1addadd1be 100644 --- a/driver/native_other.go +++ b/driver/native_other.go @@ -8,6 +8,6 @@ package driver // The call for most platforms will just execute passing an `UnknownContext` and returning any error reported. // // Since: 2.3 -func RunNative(fn func(interface{}) error) error { +func RunNative(fn func(any) error) error { return fn(&UnknownContext{}) } diff --git a/driver/native_test.go b/driver/native_test.go index e8d6affd12..d1be55131c 100644 --- a/driver/native_test.go +++ b/driver/native_test.go @@ -7,7 +7,7 @@ import ( ) func TestRunNative(t *testing.T) { - err := RunNative(func(i interface{}) error { + err := RunNative(func(i any) error { native, ok := i.(*UnknownContext) assert.True(t, ok) diff --git a/internal/async/chan_interface.go b/internal/async/chan_interface.go index 9c39f6f605..2b825ae057 100755 --- a/internal/async/chan_interface.go +++ b/internal/async/chan_interface.go @@ -5,9 +5,9 @@ package async // UnboundedInterfaceChan is a channel with an unbounded buffer for caching // Interface objects. A channel must be closed via Close method. type UnboundedInterfaceChan struct { - in, out chan interface{} + in, out chan any close chan struct{} - q []interface{} + q []any } // NewUnboundedInterfaceChan returns a unbounded channel with unlimited capacity. @@ -15,8 +15,8 @@ func NewUnboundedInterfaceChan() *UnboundedInterfaceChan { ch := &UnboundedInterfaceChan{ // The size of Interface is less than 16 bytes, we use 16 to fit // a CPU cache line (L2, 256 Bytes), which may reduce cache misses. - in: make(chan interface{}, 16), - out: make(chan interface{}, 16), + in: make(chan any, 16), + out: make(chan any, 16), close: make(chan struct{}), } go ch.processing() @@ -25,11 +25,11 @@ func NewUnboundedInterfaceChan() *UnboundedInterfaceChan { // In returns the send channel of the given channel, which can be used to // send values to the channel. -func (ch *UnboundedInterfaceChan) In() chan<- interface{} { return ch.in } +func (ch *UnboundedInterfaceChan) In() chan<- any { return ch.in } // Out returns the receive channel of the given channel, which can be used // to receive values from the channel. -func (ch *UnboundedInterfaceChan) Out() <-chan interface{} { return ch.out } +func (ch *UnboundedInterfaceChan) Out() <-chan any { return ch.out } // Close closes the channel. func (ch *UnboundedInterfaceChan) Close() { ch.close <- struct{}{} } @@ -40,7 +40,7 @@ func (ch *UnboundedInterfaceChan) processing() { // reallocation size at the subsequent for loop should also be // changed too. Furthermore, there is no memory leak since the // queue is garbage collected. - ch.q = make([]interface{}, 0, 1<<10) + ch.q = make([]any, 0, 1<<10) for { select { case e, ok := <-ch.in: @@ -76,7 +76,7 @@ func (ch *UnboundedInterfaceChan) processing() { // If the remaining capacity is too small, we prefer to // reallocate the entire buffer. if cap(ch.q) < 1<<5 { - ch.q = make([]interface{}, 0, 1<<10) + ch.q = make([]any, 0, 1<<10) } } } diff --git a/internal/async/chan_test.go b/internal/async/chan_test.go index 5996a746a2..3b9dfbb2e8 100644 --- a/internal/async/chan_test.go +++ b/internal/async/chan_test.go @@ -16,7 +16,7 @@ func TestUnboundedChann(t *testing.T) { wg := sync.WaitGroup{} for i := 0; i < N; i++ { - t.Run("interface{}", func(t *testing.T) { + t.Run("any", func(t *testing.T) { t.Run("send", func(t *testing.T) { // Ensure send to an unbounded channel does not block. c := async.NewUnboundedInterfaceChan() @@ -175,7 +175,7 @@ func TestUnboundedChann(t *testing.T) { } func BenchmarkUnboundedChann(b *testing.B) { - b.Run("interface{}", func(b *testing.B) { + b.Run("any", func(b *testing.B) { b.Run("sync", func(b *testing.B) { c := async.NewUnboundedInterfaceChan() b.ResetTimer() diff --git a/internal/async/gen.go b/internal/async/gen.go index fb95af7c83..a366f158fb 100644 --- a/internal/async/gen.go +++ b/internal/async/gen.go @@ -40,7 +40,7 @@ func main() { Imports: "", }, "chan_interface.go": { - Type: "interface{}", + Type: "any", Name: "Interface", Imports: "", }, @@ -237,7 +237,7 @@ package async {{.Imports}} var item{{.Name}}Pool = sync.Pool{ - New: func() interface{} { return &item{{.Name}}{next: nil, v: nil} }, + New: func() any { return &item{{.Name}}{next: nil, v: nil} }, } // In puts the given value at the tail of the queue. diff --git a/internal/async/queue_canvasobject.go b/internal/async/queue_canvasobject.go index c0acb5c718..c3be6862f9 100755 --- a/internal/async/queue_canvasobject.go +++ b/internal/async/queue_canvasobject.go @@ -10,7 +10,7 @@ import ( ) var itemCanvasObjectPool = sync.Pool{ - New: func() interface{} { return &itemCanvasObject{next: nil, v: nil} }, + New: func() any { return &itemCanvasObject{next: nil, v: nil} }, } // In puts the given value at the tail of the queue. diff --git a/internal/cache/base.go b/internal/cache/base.go index 422a08503d..2128970202 100644 --- a/internal/cache/base.go +++ b/internal/cache/base.go @@ -149,7 +149,7 @@ func CleanCanvases(refreshingCanvases []fyne.Canvas) { // ResetThemeCaches clears all the svg and text size cache maps func ResetThemeCaches() { - svgs.Range(func(key, value interface{}) bool { + svgs.Range(func(key, value any) bool { svgs.Delete(key) return true }) diff --git a/internal/cache/base_test.go b/internal/cache/base_test.go index b85177b6df..72ae9c1892 100644 --- a/internal/cache/base_test.go +++ b/internal/cache/base_test.go @@ -267,7 +267,7 @@ func testClearAll() { expiredObjects = make([]fyne.CanvasObject, 0, 50) skippedCleanWithCanvasRefresh = false canvases = make(map[fyne.CanvasObject]*canvasInfo, 1024) - svgs.Range(func(key, _ interface{}) bool { + svgs.Range(func(key, _ any) bool { svgs.Delete(key) return true }) diff --git a/internal/cache/svg.go b/internal/cache/svg.go index 0a10771386..20b17038ff 100644 --- a/internal/cache/svg.go +++ b/internal/cache/svg.go @@ -45,7 +45,7 @@ type svgInfo struct { // destroyExpiredSvgs destroys expired svgs cache data. func destroyExpiredSvgs(now time.Time) { expiredSvgs := make([]string, 0, 20) - svgs.Range(func(key, value interface{}) bool { + svgs.Range(func(key, value any) bool { s, sinfo := key.(string), value.(*svgInfo) if sinfo.isExpired(now) { expiredSvgs = append(expiredSvgs, s) diff --git a/internal/cache/svg_test.go b/internal/cache/svg_test.go index 6a06fc6892..3f0899e27b 100644 --- a/internal/cache/svg_test.go +++ b/internal/cache/svg_test.go @@ -10,7 +10,7 @@ import ( ) func syncMapLen(m *sync.Map) (n int) { - m.Range(func(_, _ interface{}) bool { + m.Range(func(_, _ any) bool { n++ return true }) diff --git a/internal/cache/texture_common.go b/internal/cache/texture_common.go index 97576d8ebd..abfd54f644 100644 --- a/internal/cache/texture_common.go +++ b/internal/cache/texture_common.go @@ -30,7 +30,7 @@ func GetTexture(obj fyne.CanvasObject) (TextureType, bool) { // gl context to ensure textures are deleted from gl. func RangeExpiredTexturesFor(canvas fyne.Canvas, f func(fyne.CanvasObject)) { now := timeNow() - textures.Range(func(key, value interface{}) bool { + textures.Range(func(key, value any) bool { obj, tinfo := key.(fyne.CanvasObject), value.(*textureInfo) if tinfo.isExpired(now) && tinfo.canvas == canvas { f(obj) @@ -44,7 +44,7 @@ func RangeExpiredTexturesFor(canvas fyne.Canvas, f func(fyne.CanvasObject)) { // Note: If this is used to free textures, then it should be called inside a current // gl context to ensure textures are deleted from gl. func RangeTexturesFor(canvas fyne.Canvas, f func(fyne.CanvasObject)) { - textures.Range(func(key, value interface{}) bool { + textures.Range(func(key, value any) bool { obj, tinfo := key.(fyne.CanvasObject), value.(*textureInfo) if tinfo.canvas == canvas { f(obj) diff --git a/internal/driver/common/canvas.go b/internal/driver/common/canvas.go index c70c0f13ff..4c8a774ab6 100644 --- a/internal/driver/common/canvas.go +++ b/internal/driver/common/canvas.go @@ -537,7 +537,7 @@ type RenderCacheNode struct { // it may for instance point to a GL texture // it should free all associated resources when released // i.e. it should not simply be a texture reference integer - painterData interface{} + painterData any } // Obj returns the node object. diff --git a/internal/driver/common/window.go b/internal/driver/common/window.go index eb518bf9a5..0a3c1f0c83 100644 --- a/internal/driver/common/window.go +++ b/internal/driver/common/window.go @@ -46,7 +46,7 @@ func (w *Window) WaitForEvents() { } var DonePool = sync.Pool{ - New: func() interface{} { + New: func() any { return make(chan struct{}) }, } diff --git a/internal/driver/context.go b/internal/driver/context.go index 162a15a417..925eabb0e7 100644 --- a/internal/driver/context.go +++ b/internal/driver/context.go @@ -5,5 +5,5 @@ package driver type WithContext interface { RunWithContext(f func()) RescaleContext() - Context() interface{} + Context() any } diff --git a/internal/driver/glfw/canvas_test.go b/internal/driver/glfw/canvas_test.go index 57a8845857..d7d73cc3d9 100644 --- a/internal/driver/glfw/canvas_test.go +++ b/internal/driver/glfw/canvas_test.go @@ -556,7 +556,7 @@ func TestGlCanvas_SetContent(t *testing.T) { var _ fyne.Layout = (*recordingLayout)(nil) type recordingLayout struct { - layoutEvents []interface{} + layoutEvents []any } func (l *recordingLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) { @@ -567,7 +567,7 @@ func (l *recordingLayout) MinSize([]fyne.CanvasObject) fyne.Size { return fyne.NewSize(6, 9) } -func (l *recordingLayout) popLayoutEvent() (e interface{}) { +func (l *recordingLayout) popLayoutEvent() (e any) { e, l.layoutEvents = pop(l.layoutEvents) return } diff --git a/internal/driver/glfw/window.go b/internal/driver/glfw/window.go index a491722dc2..34a99d21dd 100644 --- a/internal/driver/glfw/window.go +++ b/internal/driver/glfw/window.go @@ -457,7 +457,7 @@ func (w *window) processMouseMoved(xpos float64, ypos float64) { } } -func (w *window) objIsDragged(obj interface{}) bool { +func (w *window) objIsDragged(obj any) bool { if w.mouseDragged != nil && obj != nil { draggedObj, _ := obj.(fyne.Draggable) return draggedObj == w.mouseDragged @@ -926,7 +926,7 @@ func (w *window) RescaleContext() { runOnMain(w.rescaleOnMain) } -func (w *window) Context() interface{} { +func (w *window) Context() any { return nil } diff --git a/internal/driver/glfw/window_test.go b/internal/driver/glfw/window_test.go index c0e8718ed5..0fcfd9dd1b 100644 --- a/internal/driver/glfw/window_test.go +++ b/internal/driver/glfw/window_test.go @@ -1810,9 +1810,9 @@ type hoverableObject struct { var _ desktop.Hoverable = (*hoverable)(nil) type hoverable struct { - mouseInEvents []interface{} - mouseOutEvents []interface{} - mouseMovedEvents []interface{} + mouseInEvents []any + mouseOutEvents []any + mouseMovedEvents []any } func (h *hoverable) MouseIn(e *desktop.MouseEvent) { @@ -1827,17 +1827,17 @@ func (h *hoverable) MouseOut() { h.mouseOutEvents = append(h.mouseOutEvents, true) } -func (h *hoverable) popMouseInEvent() (e interface{}) { +func (h *hoverable) popMouseInEvent() (e any) { e, h.mouseInEvents = pop(h.mouseInEvents) return } -func (h *hoverable) popMouseMovedEvent() (e interface{}) { +func (h *hoverable) popMouseMovedEvent() (e any) { e, h.mouseMovedEvents = pop(h.mouseMovedEvents) return } -func (h *hoverable) popMouseOutEvent() (e interface{}) { +func (h *hoverable) popMouseOutEvent() (e any) { e, h.mouseOutEvents = pop(h.mouseOutEvents) return } @@ -1850,8 +1850,8 @@ type draggableObject struct { var _ fyne.Draggable = (*draggable)(nil) type draggable struct { - events []interface{} - endEvents []interface{} + events []any + endEvents []any } func (d *draggable) Dragged(e *fyne.DragEvent) { @@ -1862,12 +1862,12 @@ func (d *draggable) DragEnd() { d.endEvents = append(d.endEvents, true) } -func (d *draggable) popDragEvent() (e interface{}) { +func (d *draggable) popDragEvent() (e any) { e, d.events = pop(d.events) return } -func (d *draggable) popDragEndEvent() (e interface{}) { +func (d *draggable) popDragEndEvent() (e any) { e, d.endEvents = pop(d.endEvents) return } @@ -1886,7 +1886,7 @@ type mouseableObject struct { var _ desktop.Mouseable = (*mouseable)(nil) type mouseable struct { - mouseEvents []interface{} + mouseEvents []any } func (m *mouseable) MouseDown(e *desktop.MouseEvent) { @@ -1897,7 +1897,7 @@ func (m *mouseable) MouseUp(e *desktop.MouseEvent) { m.mouseEvents = append(m.mouseEvents, e) } -func (m *mouseable) popMouseEvent() (e interface{}) { +func (m *mouseable) popMouseEvent() (e any) { e, m.mouseEvents = pop(m.mouseEvents) return } @@ -1916,8 +1916,8 @@ type tappableObject struct { var _ fyne.Tappable = (*tappable)(nil) type tappable struct { - tapEvents []interface{} - secondaryTapEvents []interface{} + tapEvents []any + secondaryTapEvents []any } func (t *tappable) Tapped(e *fyne.PointEvent) { @@ -1928,12 +1928,12 @@ func (t *tappable) TappedSecondary(e *fyne.PointEvent) { t.secondaryTapEvents = append(t.secondaryTapEvents, e) } -func (t *tappable) popTapEvent() (e interface{}) { +func (t *tappable) popTapEvent() (e any) { e, t.tapEvents = pop(t.tapEvents) return } -func (t *tappable) popSecondaryTapEvent() (e interface{}) { +func (t *tappable) popSecondaryTapEvent() (e any) { e, t.secondaryTapEvents = pop(t.secondaryTapEvents) return } @@ -2004,14 +2004,14 @@ var _ fyne.Scrollable = (*scrollable)(nil) type scrollable struct { *canvas.Rectangle - events []interface{} + events []any } func (s *scrollable) Scrolled(e *fyne.ScrollEvent) { s.events = append(s.events, e) } -func (s *scrollable) popScrollEvent() (e interface{}) { +func (s *scrollable) popScrollEvent() (e any) { e, s.events = pop(s.events) return } @@ -2020,7 +2020,7 @@ func (s *scrollable) popScrollEvent() (e interface{}) { // Test helper // -func pop(s []interface{}) (interface{}, []interface{}) { +func pop(s []any) (any, []any) { if len(s) == 0 { return nil, s } diff --git a/internal/driver/mobile/app/app.go b/internal/driver/mobile/app/app.go index de56614499..8c6c926282 100644 --- a/internal/driver/mobile/app/app.go +++ b/internal/driver/mobile/app/app.go @@ -36,10 +36,10 @@ type App interface { // - touch.Event // from the golang.org/x/mobile/event/etc packages. Other packages may // define other event types that are carried on this channel. - Events() <-chan interface{} + Events() <-chan any // Send sends an event on the events channel. It does not block. - Send(event interface{}) + Send(event any) // Publish flushes any pending drawing commands, such as OpenGL calls, and // swaps the back buffer to the screen. @@ -48,13 +48,13 @@ type App interface { // TODO: replace filters (and the Events channel) with a NextEvent method? // Filter calls each registered event filter function in sequence. - Filter(event interface{}) interface{} + Filter(event any) any // RegisterFilter registers a event filter function to be called by Filter. The // function can return a different event, or return nil to consume the event, // but the function can also return its argument unchanged, where its purpose // is to trigger a side effect rather than modify the event. - RegisterFilter(f func(interface{}) interface{}) + RegisterFilter(f func(any) any) ShowVirtualKeyboard(KeyboardType) HideVirtualKeyboard() @@ -99,7 +99,7 @@ func (a *app) sendLifecycle(to lifecycle.Stage) { } type app struct { - filters []func(interface{}) interface{} + filters []func(any) any events *async.UnboundedInterfaceChan lifecycleStage lifecycle.Stage @@ -110,11 +110,11 @@ type app struct { worker gl.Worker } -func (a *app) Events() <-chan interface{} { +func (a *app) Events() <-chan any { return a.events.Out() } -func (a *app) Send(event interface{}) { +func (a *app) Send(event any) { a.events.In() <- event } @@ -131,14 +131,14 @@ func (a *app) Publish() PublishResult { return <-a.publishResult } -func (a *app) Filter(event interface{}) interface{} { +func (a *app) Filter(event any) any { for _, f := range a.filters { event = f(event) } return event } -func (a *app) RegisterFilter(f func(interface{}) interface{}) { +func (a *app) RegisterFilter(f func(any) any) { a.filters = append(a.filters, f) } @@ -163,7 +163,7 @@ func (a *app) ShowFileSavePicker(callback func(string, func()), filter *FileFilt // TODO: does Android need this?? It seems to work without it (Nexus 7, // KitKat). If only x11 needs this, should we move this to x11.go?? func (a *app) registerGLViewportFilter() { - a.RegisterFilter(func(e interface{}) interface{} { + a.RegisterFilter(func(e any) any { if e, ok := e.(size.Event); ok { a.glctx.Viewport(0, 0, e.WidthPx, e.HeightPx) } diff --git a/internal/driver/mobile/app/doc.go b/internal/driver/mobile/app/doc.go index 47fc6ade95..3ee21814e4 100644 --- a/internal/driver/mobile/app/doc.go +++ b/internal/driver/mobile/app/doc.go @@ -66,8 +66,8 @@ goroutine as other code that calls OpenGL. }) } -An event is represented by the empty interface type interface{}. Any value can -be an event. Commonly used types include Event types defined by the following +An event is represented by the any type, so any value can be an event. +Commonly used types include Event types defined by the following packages: - golang.org/x/mobile/event/lifecycle - golang.org/x/mobile/event/mouse diff --git a/internal/driver/mobile/event/lifecycle/lifecycle.go b/internal/driver/mobile/event/lifecycle/lifecycle.go index c755bf6665..7bd394585f 100644 --- a/internal/driver/mobile/event/lifecycle/lifecycle.go +++ b/internal/driver/mobile/event/lifecycle/lifecycle.go @@ -52,7 +52,7 @@ type Event struct { // For OpenGL apps, a non-nil DrawContext is a gl.Context. // // TODO: make this an App method if we move away from an event channel? - DrawContext interface{} + DrawContext any } func (e Event) String() string { diff --git a/internal/driver/mobile/window.go b/internal/driver/mobile/window.go index c3ad9d03b2..3c044b9768 100644 --- a/internal/driver/mobile/window.go +++ b/internal/driver/mobile/window.go @@ -218,6 +218,6 @@ func (w *window) RescaleContext() { // TODO } -func (w *window) Context() interface{} { +func (w *window) Context() any { return fyne.CurrentApp().Driver().(*mobileDriver).glctx } diff --git a/internal/preferences.go b/internal/preferences.go index c49ca720b9..d61d19fc4f 100644 --- a/internal/preferences.go +++ b/internal/preferences.go @@ -9,7 +9,7 @@ import ( // InMemoryPreferences provides an implementation of the fyne.Preferences API that is stored in memory. type InMemoryPreferences struct { - values map[string]interface{} + values map[string]any lock sync.RWMutex changeListeners []func() } @@ -161,7 +161,7 @@ func (p *InMemoryPreferences) IntWithFallback(key string, fallback int) int { // ReadValues provides read access to the underlying value map - for internal use only... // You should not retain a reference to the map nor write to the values in the callback function -func (p *InMemoryPreferences) ReadValues(fn func(map[string]interface{})) { +func (p *InMemoryPreferences) ReadValues(fn func(map[string]any)) { p.lock.RLock() fn(p.values) p.lock.RUnlock() @@ -244,7 +244,7 @@ func (p *InMemoryPreferences) StringWithFallback(key, fallback string) string { // WriteValues provides write access to the underlying value map - for internal use only... // You should not retain a reference to the map passed to the callback function -func (p *InMemoryPreferences) WriteValues(fn func(map[string]interface{})) { +func (p *InMemoryPreferences) WriteValues(fn func(map[string]any)) { p.lock.Lock() fn(p.values) p.lock.Unlock() @@ -254,7 +254,7 @@ func (p *InMemoryPreferences) WriteValues(fn func(map[string]interface{})) { // NewInMemoryPreferences creates a new preferences implementation stored in memory func NewInMemoryPreferences() *InMemoryPreferences { - return &InMemoryPreferences{values: make(map[string]interface{})} + return &InMemoryPreferences{values: make(map[string]any)} } func (p *InMemoryPreferences) fireChange() { @@ -275,7 +275,7 @@ func (p *InMemoryPreferences) fireChange() { wg.Wait() } -func (p *InMemoryPreferences) get(key string) (interface{}, bool) { +func (p *InMemoryPreferences) get(key string) (any, bool) { p.lock.RLock() defer p.lock.RUnlock() @@ -291,7 +291,7 @@ func (p *InMemoryPreferences) remove(key string) { p.fireChange() } -func (p *InMemoryPreferences) set(key string, value interface{}) { +func (p *InMemoryPreferences) set(key string, value any) { p.lock.Lock() if reflect.TypeOf(value).Kind() == reflect.Slice { diff --git a/internal/preferences_test.go b/internal/preferences_test.go index 89e0b4c355..968c2b8453 100644 --- a/internal/preferences_test.go +++ b/internal/preferences_test.go @@ -16,7 +16,7 @@ func TestPrefs_SetBool(t *testing.T) { func TestPrefs_Bool(t *testing.T) { p := NewInMemoryPreferences() - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["testBool"] = true }) @@ -62,7 +62,7 @@ func TestPrefs_SetFloat(t *testing.T) { func TestPrefs_Float(t *testing.T) { p := NewInMemoryPreferences() - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["testFloat"] = 1.2 }) @@ -73,7 +73,7 @@ func TestPrefs_FloatWithFallback(t *testing.T) { p := NewInMemoryPreferences() assert.Equal(t, 1.0, p.FloatWithFallback("testFloat", 1.0)) - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["testFloat"] = 1.2 }) assert.Equal(t, 1.2, p.FloatWithFallback("testFloat", 1.0)) @@ -99,7 +99,7 @@ func TestPrefs_SetInt(t *testing.T) { func TestPrefs_Int(t *testing.T) { p := NewInMemoryPreferences() - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["testInt"] = 5 }) assert.Equal(t, 5, p.Int("testInt")) @@ -109,7 +109,7 @@ func TestPrefs_IntWithFallback(t *testing.T) { p := NewInMemoryPreferences() assert.Equal(t, 2, p.IntWithFallback("testInt", 2)) - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["testInt"] = 5 }) assert.Equal(t, 5, p.IntWithFallback("testInt", 2)) @@ -136,7 +136,7 @@ func TestPrefs_SetString(t *testing.T) { func TestPrefs_String(t *testing.T) { p := NewInMemoryPreferences() - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["test"] = "value" }) @@ -147,7 +147,7 @@ func TestPrefs_StringWithFallback(t *testing.T) { p := NewInMemoryPreferences() assert.Equal(t, "default", p.StringWithFallback("test", "default")) - p.WriteValues(func(val map[string]interface{}) { + p.WriteValues(func(val map[string]any) { val["test"] = "value" }) assert.Equal(t, "value", p.StringWithFallback("test", "default")) diff --git a/internal/test/util.go b/internal/test/util.go index 0829fbddf8..2f0631356d 100644 --- a/internal/test/util.go +++ b/internal/test/util.go @@ -19,7 +19,7 @@ import ( // The test `t` fails if the given image is not equal to the loaded master image. // In this case the given image is written into a file in `testdata/failed/` (relative to the test). // This path is also reported, thus the file can be used as new master. -func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, msgAndArgs ...interface{}) bool { +func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, msgAndArgs ...any) bool { wd, err := os.Getwd() require.NoError(t, err) masterPath := filepath.Join(wd, "testdata", masterFilename) diff --git a/shortcut_test.go b/shortcut_test.go index cb29428b87..4a6c03e4f2 100644 --- a/shortcut_test.go +++ b/shortcut_test.go @@ -8,7 +8,7 @@ import ( ) func syncMapLen(m *sync.Map) (n int) { - m.Range(func(_, _ interface{}) bool { + m.Range(func(_, _ any) bool { n++ return true }) diff --git a/test/test.go b/test/test.go index c675ad08b1..53c568d9d9 100644 --- a/test/test.go +++ b/test/test.go @@ -37,7 +37,7 @@ func AssertCanvasTappableAt(t *testing.T, c fyne.Canvas, pos fyne.Position) bool // This path is also reported, thus the file can be used as new master. // // Since 2.3 -func AssertObjectRendersToImage(t *testing.T, masterFilename string, o fyne.CanvasObject, msgAndArgs ...interface{}) bool { +func AssertObjectRendersToImage(t *testing.T, masterFilename string, o fyne.CanvasObject, msgAndArgs ...any) bool { c := NewCanvasWithPainter(software.NewPainter()) c.SetPadded(false) size := o.MinSize().Max(o.Size()) @@ -59,7 +59,7 @@ func AssertObjectRendersToImage(t *testing.T, masterFilename string, o fyne.Canv // The only exception to this are text elements which do not contain line breaks unless the text includes them. // // Since 2.3 -func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o fyne.CanvasObject, msgAndArgs ...interface{}) bool { +func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o fyne.CanvasObject, msgAndArgs ...any) bool { c := NewCanvas() c.SetPadded(false) size := o.MinSize().Max(o.Size()) @@ -74,7 +74,7 @@ func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o fyne.Can // The test `t` fails if the given image is not equal to the loaded master image. // In this case the given image is written into a file in `testdata/failed/` (relative to the test). // This path is also reported, thus the file can be used as new master. -func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, msgAndArgs ...interface{}) bool { +func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, msgAndArgs ...any) bool { return test.AssertImageMatches(t, masterFilename, img, msgAndArgs...) } @@ -85,7 +85,7 @@ func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, ms // This path is also reported, thus the file can be used as new master. // // Since 2.3 -func AssertRendersToImage(t *testing.T, masterFilename string, c fyne.Canvas, msgAndArgs ...interface{}) bool { +func AssertRendersToImage(t *testing.T, masterFilename string, c fyne.Canvas, msgAndArgs ...any) bool { return test.AssertImageMatches(t, masterFilename, c.Capture(), msgAndArgs...) } @@ -101,7 +101,7 @@ func AssertRendersToImage(t *testing.T, masterFilename string, c fyne.Canvas, ms // The only exception to this are text elements which do not contain line breaks unless the text includes them. // // Since: 2.0 -func AssertRendersToMarkup(t *testing.T, masterFilename string, c fyne.Canvas, msgAndArgs ...interface{}) bool { +func AssertRendersToMarkup(t *testing.T, masterFilename string, c fyne.Canvas, msgAndArgs ...any) bool { wd, err := os.Getwd() require.NoError(t, err) @@ -323,7 +323,7 @@ func findTappable(c fyne.Canvas, pos fyne.Position) (o fyne.CanvasObject, p fyne return } -func prepareTap(obj interface{}, pos fyne.Position) (*fyne.PointEvent, fyne.Canvas) { +func prepareTap(obj any, pos fyne.Position) (*fyne.PointEvent, fyne.Canvas) { d := fyne.CurrentApp().Driver() ev := &fyne.PointEvent{Position: pos} var c fyne.Canvas @@ -339,7 +339,7 @@ func tap(c fyne.Canvas, obj fyne.Tappable, ev *fyne.PointEvent) { obj.Tapped(ev) } -func handleFocusOnTap(c fyne.Canvas, obj interface{}) { +func handleFocusOnTap(c fyne.Canvas, obj any) { if c == nil { return } diff --git a/widget/entry_test.go b/widget/entry_test.go index 0c9eb5d3ab..ca0d9eff26 100644 --- a/widget/entry_test.go +++ b/widget/entry_test.go @@ -2161,7 +2161,7 @@ func clickPrimary(c fyne.Canvas, obj desktop.Mouseable, ev *fyne.PointEvent) { } } -func handleFocusOnTap(c fyne.Canvas, obj interface{}) { +func handleFocusOnTap(c fyne.Canvas, obj any) { if c == nil { return } diff --git a/widget/gridwrap.go b/widget/gridwrap.go index 0221c9bb08..0b600089f0 100644 --- a/widget/gridwrap.go +++ b/widget/gridwrap.go @@ -480,7 +480,7 @@ type gridWrapLayout struct { func newGridWrapLayout(list *GridWrap) fyne.Layout { l := &gridWrapLayout{list: list} - l.slicePool.New = func() interface{} { + l.slicePool.New = func() any { s := make([]gridItemAndID, 0) return &s } diff --git a/widget/list.go b/widget/list.go index 23636edbb2..53bca499b1 100644 --- a/widget/list.go +++ b/widget/list.go @@ -545,7 +545,7 @@ type listLayout struct { func newListLayout(list *List) fyne.Layout { l := &listLayout{list: list} - l.slicePool.New = func() interface{} { + l.slicePool.New = func() any { s := make([]listItemAndID, 0) return &s }