Skip to content

Commit

Permalink
Add 'Since' that was missing from the animation APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 6, 2021
1 parent 7b39025 commit 3a081f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,33 @@ import "time"
type AnimationCurve func(float32) float32

// AnimationRepeatForever is an AnimationCount value that indicates it should not stop looping.
//
// Since 2.0.0
const AnimationRepeatForever = -1

var (
// AnimationEaseInOut is the default easing, it starts slowly, accelerates to the middle and slows to the end.
//
// Since 2.0.0
AnimationEaseInOut = animationEaseInOut
// AnimationEaseIn starts slowly and accelerates to the end.
//
// Since 2.0.0
AnimationEaseIn = animationEaseIn
// AnimationEaseOut starts at speed and slows to the end.
//
// Since 2.0.0
AnimationEaseOut = animationEaseOut
// AnimationLinear is a linear mapping for animations that progress uniformly through their duration.
//
// Since 2.0.0
AnimationLinear = animationLinear
)

// Animation represents an animated element within a Fyne canvas.
// These animations may control individual objects or entire scenes.
//
// Since 2.0.0
type Animation struct {
AutoReverse bool
Curve AnimationCurve
Expand All @@ -35,6 +47,8 @@ type Animation struct {
// NewAnimation creates a very basic animation where the callback function will be called for every
// rendered frame between time.Now() and the specified duration. The callback values start at 0.0 and
// will be 1.0 when the animation completes.
//
// Since 2.0.0
func NewAnimation(d time.Duration, fn func(float32)) *Animation {
return &Animation{Duration: d, Tick: fn}
}
Expand Down
10 changes: 10 additions & 0 deletions canvas/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ import (

const (
// DurationStandard is the time a standard interface animation will run.
//
// Since 2.0.0
DurationStandard = time.Millisecond * 300
// DurationShort is the time a subtle or small transition should use.
//
// Since 2.0.0
DurationShort = time.Millisecond * 150
)

// NewColorRGBAAnimation sets up a new animation that will transition from the start to stop Color over
// the specified Duration. The colour transition will move linearly through the RGB colour space.
// The content of fn should apply the color values to an object and refresh it.
// You should call Start() on the returned animation to start it.
//
// Since 2.0.0
func NewColorRGBAAnimation(start, stop color.Color, d time.Duration, fn func(color.Color)) *fyne.Animation {
r1, g1, b1, a1 := start.RGBA()
r2, g2, b2, a2 := stop.RGBA()
Expand All @@ -42,6 +48,8 @@ func NewColorRGBAAnimation(start, stop color.Color, d time.Duration, fn func(col
// NewPositionAnimation sets up a new animation that will transition from the start to stop Position over
// the specified Duration. The content of fn should apply the position value to an object for the change
// to be visible. You should call Start() on the returned animation to start it.
//
// Since 2.0.0
func NewPositionAnimation(start, stop fyne.Position, d time.Duration, fn func(fyne.Position)) *fyne.Animation {
xDelta := float32(stop.X - start.X)
yDelta := float32(stop.Y - start.Y)
Expand All @@ -56,6 +64,8 @@ func NewPositionAnimation(start, stop fyne.Position, d time.Duration, fn func(fy
// NewSizeAnimation sets up a new animation that will transition from the start to stop Size over
// the specified Duration. The content of fn should apply the size value to an object for the change
// to be visible. You should call Start() on the returned animation to start it.
//
// Since 2.0.0
func NewSizeAnimation(start, stop fyne.Size, d time.Duration, fn func(fyne.Size)) *fyne.Animation {
widthDelta := float32(stop.Width - start.Width)
heightDelta := float32(stop.Height - start.Height)
Expand Down

0 comments on commit 3a081f4

Please sign in to comment.