Skip to content

Commit

Permalink
Add ability to disable animations for widgets where that is an option…
Browse files Browse the repository at this point in the history
…al extra

Fixes fyne-io#1813
  • Loading branch information
andydotxyz committed May 14, 2023
1 parent 01205ce commit 12b76e1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
15 changes: 10 additions & 5 deletions app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion container/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ type Settings interface {

AddChangeListener(chan Settings)
BuildType() BuildType

ShowAnimations() bool
}
4 changes: 4 additions & 0 deletions test/testapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions theme/themedtestapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
5 changes: 4 additions & 1 deletion widget/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,9 @@ type entryContentRenderer struct {
}

func (r *entryContentRenderer) Destroy() {
if !fyne.CurrentApp().Settings().ShowAnimations() {
return
}
r.content.entry.cursorAnim.stop()
}

Expand Down Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion widget/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 12b76e1

Please sign in to comment.