From 12b76e1fb6b466e043e96de91a11e5daa7a9af95 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 14 May 2023 20:18:04 +0100 Subject: [PATCH] Add ability to disable animations for widgets where that is an optional extra Fixes #1813 --- app/settings.go | 15 ++++++++++----- container/tabs.go | 2 +- settings.go | 2 ++ test/testapp.go | 4 ++++ theme/themedtestapp.go | 4 ++++ widget/button.go | 5 ++++- widget/entry.go | 7 ++++++- widget/select.go | 5 ++++- 8 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/settings.go b/app/settings.go index 423cb92d6f..f95f327860 100644 --- a/app/settings.go +++ b/app/settings.go @@ -13,11 +13,12 @@ import ( // SettingsSchema is used for loading and storing global settings type SettingsSchema struct { // these items are used for global settings load - ThemeName string `json:"theme"` - Scale float32 `json:"scale"` - PrimaryColor string `json:"primary_color"` - CloudName string `json:"cloud_name"` - CloudConfig string `json:"cloud_config"` + ThemeName string `json:"theme"` + Scale float32 `json:"scale"` + PrimaryColor string `json:"primary_color"` + CloudName string `json:"cloud_name"` + CloudConfig string `json:"cloud_config"` + DisableAnimations bool `json:"no_animations"` } // StoragePath returns the location of the settings storage @@ -70,6 +71,10 @@ func (s *settings) SetTheme(theme fyne.Theme) { s.applyTheme(theme, s.variant) } +func (s *settings) ShowAnimations() bool { + return !s.schema.DisableAnimations +} + func (s *settings) ThemeVariant() fyne.ThemeVariant { return s.variant } diff --git a/container/tabs.go b/container/tabs.go index 49a78ea604..8d798ec8c9 100644 --- a/container/tabs.go +++ b/container/tabs.go @@ -412,7 +412,7 @@ func (r *baseTabsRenderer) moveIndicator(pos fyne.Position, siz fyne.Size, anima r.lastIndicatorHidden = r.indicator.Hidden r.lastIndicatorMutex.Unlock() - if animate { + if animate && fyne.CurrentApp().Settings().ShowAnimations() { r.positionAnimation = canvas.NewPositionAnimation(r.indicator.Position(), pos, canvas.DurationShort, func(p fyne.Position) { r.indicator.Move(p) r.indicator.Refresh() diff --git a/settings.go b/settings.go index dcf19cf80c..b6ad42c144 100644 --- a/settings.go +++ b/settings.go @@ -29,4 +29,6 @@ type Settings interface { AddChangeListener(chan Settings) BuildType() BuildType + + ShowAnimations() bool } diff --git a/test/testapp.go b/test/testapp.go index d3e61838c8..086a39c2f3 100644 --- a/test/testapp.go +++ b/test/testapp.go @@ -207,6 +207,10 @@ func (s *testSettings) SetTheme(theme fyne.Theme) { s.apply() } +func (s *testSettings) ShowAnimations() bool { + return false +} + func (s *testSettings) Theme() fyne.Theme { s.propertyLock.RLock() defer s.propertyLock.RUnlock() diff --git a/theme/themedtestapp.go b/theme/themedtestapp.go index 2448729616..8c9664c437 100644 --- a/theme/themedtestapp.go +++ b/theme/themedtestapp.go @@ -95,5 +95,9 @@ func (t *themedApp) Scale() float32 { return 1.0 } +func (s *themedApp) ShowAnimations() bool { + return false +} + func (t *themedApp) AddChangeListener(chan fyne.Settings) { } diff --git a/widget/button.go b/widget/button.go index 04b7ff1664..711b2b7d6f 100644 --- a/widget/button.go +++ b/widget/button.go @@ -261,7 +261,10 @@ func (b *Button) tapAnimation() { return } b.tapAnim.Stop() - b.tapAnim.Start() + + if fyne.CurrentApp().Settings().ShowAnimations() { + b.tapAnim.Start() + } } type buttonRenderer struct { diff --git a/widget/entry.go b/widget/entry.go index 7818a0697b..2962aad3e2 100644 --- a/widget/entry.go +++ b/widget/entry.go @@ -1560,6 +1560,9 @@ type entryContentRenderer struct { } func (r *entryContentRenderer) Destroy() { + if !fyne.CurrentApp().Settings().ShowAnimations() { + return + } r.content.entry.cursorAnim.stop() } @@ -1607,7 +1610,9 @@ func (r *entryContentRenderer) Refresh() { if focusedAppearance { r.cursor.Show() - r.content.entry.cursorAnim.start() + if fyne.CurrentApp().Settings().ShowAnimations() { + r.content.entry.cursorAnim.start() + } } else { r.content.entry.cursorAnim.stop() r.cursor.Hide() diff --git a/widget/select.go b/widget/select.go index a940e33f18..b171d85722 100644 --- a/widget/select.go +++ b/widget/select.go @@ -251,7 +251,10 @@ func (s *Select) tapAnimation() { return } s.tapAnim.Stop() - s.tapAnim.Start() + + if fyne.CurrentApp().Settings().ShowAnimations() { + s.tapAnim.Start() + } } func (s *Select) updateSelected(text string) {