Documentation ¶
Overview ¶
Package animations contains my attempt to create animation kind of "animations" in imgui.
Index ¶
- Constants
- func Ease(alg EasingAlgorithmType, t float32) float32
- type Animation
- type AnimatorWidget
- func (a *AnimatorWidget) Build()
- func (a *AnimatorWidget) CurrentPercentageProgress() float32
- func (a *AnimatorWidget) Duration(duration time.Duration) *AnimatorWidget
- func (a *AnimatorWidget) EasingAlgorithm(alg EasingAlgorithmType) *AnimatorWidget
- func (a *AnimatorWidget) FPS(fps int) *AnimatorWidget
- func (a *AnimatorWidget) ID(newID string) *AnimatorWidget
- func (a *AnimatorWidget) IsRunning() bool
- func (a *AnimatorWidget) Start(playMode PlayMode)
- func (a *AnimatorWidget) StartCycle(numberOfCycles int, playMode PlayMode)
- func (a *AnimatorWidget) StartKeyFrames(beginKF, destinationKF KeyFrame, cyclesCount int, playMode PlayMode)
- func (a *AnimatorWidget) Trigger(triggerType TriggerType, playMode PlayMode, f TriggerFunc) *AnimatorWidget
- type ColorFlowAnimation
- func ColorFlow(widget giu.Widget, applying []giu.StyleColorID, colors ...func() color.RGBA) *ColorFlowAnimation
- func ColorFlowColors(widget giu.Widget, applying []giu.StyleColorID, colors ...color.Color) *ColorFlowAnimation
- func ColorFlowStyle(widget giu.Widget, normal, destiny giu.StyleColorID) *ColorFlowAnimation
- func (c *ColorFlowAnimation) BuildAnimation(percentage, _ float32, sourceKeyFrame, destinyKeyFrame KeyFrame, _ PlayMode, ...)
- func (c *ColorFlowAnimation) BuildNormal(currentKeyFrame KeyFrame, _ StarterFunc)
- func (c *ColorFlowAnimation) Init()
- func (c *ColorFlowAnimation) KeyFramesCount() int
- func (c *ColorFlowAnimation) Reset()
- type EasingAlgorithm
- type EasingAlgorithmType
- type KeyFrame
- type MoveAnimation
- func (m *MoveAnimation) BuildAnimation(animationPercentage, _ float32, srcFrame, destFrame KeyFrame, mode PlayMode, ...)
- func (m *MoveAnimation) BuildNormal(currentKF KeyFrame, starter StarterFunc)
- func (m *MoveAnimation) DefaultStartPos() *MoveAnimation
- func (m *MoveAnimation) Init()
- func (m *MoveAnimation) KeyFramesCount() int
- func (m *MoveAnimation) Reset()
- func (m *MoveAnimation) StartPos(startPosStep func(startPos imgui.Vec2) *MoveStep) *MoveAnimation
- type MoveStep
- type PlayMode
- type StarterFunc
- type TransitionAnimation
- func (t *TransitionAnimation) BuildAnimation(percentage, _ float32, bf, df KeyFrame, _ PlayMode, starter StarterFunc)
- func (t *TransitionAnimation) BuildNormal(f KeyFrame, starter StarterFunc)
- func (t *TransitionAnimation) Init()
- func (t *TransitionAnimation) KeyFramesCount() int
- func (t *TransitionAnimation) Reset()
- type TriggerFunc
- type TriggerType
Constants ¶
const ( // DefaultFPS is FPS value that should suit most use-cases. // Animator takes this value by default and it could be changed by (*Animator).FPS(). DefaultFPS = 60 // DefaultDuration is animation's duration set by default. // You can change this by (*Animator).Durations(). DefaultDuration = time.Second / 4 )
Variables ¶
This section is empty.
Functions ¶
func Ease ¶
func Ease(alg EasingAlgorithmType, t float32) float32
Ease takes EasingAlgorithmType and plain percentage value t and returns eased value. The following condition is expected to be met, however they are not restricted anyhow: 0 <= t <= 1.
Types ¶
type Animation ¶
type Animation interface { // Init is called once, immediately on start. Init() // Reset is called whenever needs to restart animation. Reset() // KeyFramesCount is used mainly by the AnimatorWidget. // It returns animation number of key frames. KeyFramesCount() int // BuildNormal is called every frame when animation is not running // starter is animation link to Animator.Start BuildNormal(currentKeyFrame KeyFrame, starterFunc StarterFunc) // BuildAnimation is called when running an animation. // It receives several important arguments: // - animationPercentage after applying specified by Animator // easing algorithm. // ATTENTION: this value may be less than 0 or greater than 1 // - pure percentage status of animation before applying // any algorithm. // it is always in range <0, 1> (0 <= arbitraryPercentage <= 1) // NOTE: this value should NOT be used in most cases, because it will // disable user from specifying Easing Algorithm and most use-cases // does not want this, however you may want to use for comparing something. // - base and destination Key Frames - your animation should be played from first to the second. // - animation's Play Mode - use it if it is important to know what is the exact play direction. // - starter functions set (see StarterFunc) // starter is animation link to (*Animator).Start() method. BuildAnimation( animationPercentage, arbitraryPercentage float32, baseKeyFrame, destinationKeyFrame KeyFrame, mode PlayMode, starterFunc StarterFunc, ) }
Animation is an interface implemented by each animation. Every type that implements Animation interface is liable to be used as an argument of Animator method.
type AnimatorWidget ¶
type AnimatorWidget struct {
// contains filtered or unexported fields
}
AnimatorWidget is animation manager for Animation. It is a giu.Widget (so you can use it in any giu.Layout). This type provides a wide API that allows you to manage your animation such as Start* functions or parameters like FPS or Duration. It is actually responsible for advancement of animation. NOTE: This type should be concurrent-safe. If you find any data race please open an issue in source repository.
func Animator ¶
func Animator(a Animation) *AnimatorWidget
Animator creates animation new AnimatorWidget.
func (*AnimatorWidget) CurrentPercentageProgress ¶
func (a *AnimatorWidget) CurrentPercentageProgress() float32
CurrentPercentageProgress returns animation float value from range <0, 1> representing current progress of an animation. If animation is not running, it will return 0.
func (*AnimatorWidget) Duration ¶
func (a *AnimatorWidget) Duration(duration time.Duration) *AnimatorWidget
Duration allows to specify duration value. CAUTION: it will take effect after next call to Start - not applied to currently plaid animation.
func (*AnimatorWidget) EasingAlgorithm ¶
func (a *AnimatorWidget) EasingAlgorithm(alg EasingAlgorithmType) *AnimatorWidget
EasingAlgorithm allows to specify easing algorithm.
func (*AnimatorWidget) FPS ¶
func (a *AnimatorWidget) FPS(fps int) *AnimatorWidget
FPS allows to specify FPS value. CAUTION: it will take effect after next call to Start - not applied to currently plaid animation.
func (*AnimatorWidget) ID ¶
func (a *AnimatorWidget) ID(newID string) *AnimatorWidget
ID sets animation custom ID to this AnimatorWidget It may be really important when using TransitionAnimation, because sometimes when using sub-animators inside of Transition, it may happen that the second AnimatorWidget will receive the same ID as the previous one. It may cause unexpected behaviours.
func (*AnimatorWidget) IsRunning ¶
func (a *AnimatorWidget) IsRunning() bool
IsRunning returns true if the animation is already running.
func (*AnimatorWidget) Start ¶
func (a *AnimatorWidget) Start(playMode PlayMode)
Start starts the animation. It plays one single frame forwards/backwards (depending on playMode).
func (*AnimatorWidget) StartCycle ¶
func (a *AnimatorWidget) StartCycle(numberOfCycles int, playMode PlayMode)
StartCycle plays an animation from start to end (optionally from end to start)
func (*AnimatorWidget) StartKeyFrames ¶
func (a *AnimatorWidget) StartKeyFrames(beginKF, destinationKF KeyFrame, cyclesCount int, playMode PlayMode)
StartKeyFrames initializes animation playback from beginKF to destination KF in direction specified by playMode.
func (*AnimatorWidget) Trigger ¶
func (a *AnimatorWidget) Trigger(triggerType TriggerType, playMode PlayMode, f TriggerFunc) *AnimatorWidget
Trigger sets automatic triggering of animation.
Example: (*AnimatorWidget).Trigger(TriggerOnChange, imgui.IsItemHovered)
type ColorFlowAnimation ¶
ColorFlowAnimation makes a smooth flow from one color to another on all specified StyleColor variables.
func ColorFlow ¶
func ColorFlow( widget giu.Widget, applying []giu.StyleColorID, colors ...func() color.RGBA, ) *ColorFlowAnimation
ColorFlow creates a new ColorFlowAnimation.
func ColorFlowColors ¶
func ColorFlowColors( widget giu.Widget, applying []giu.StyleColorID, colors ...color.Color, ) *ColorFlowAnimation
ColorFlowColors takes a colors list instead of list of functions returning colors.
func ColorFlowStyle ¶
func ColorFlowStyle( widget giu.Widget, normal, destiny giu.StyleColorID, ) *ColorFlowAnimation
ColorFlowStyle wraps ColorFlow so that it automatically obtains the color for specified style values.
func (*ColorFlowAnimation) BuildAnimation ¶
func (c *ColorFlowAnimation) BuildAnimation( percentage, _ float32, sourceKeyFrame, destinyKeyFrame KeyFrame, _ PlayMode, _ StarterFunc, )
BuildAnimation implements Animation.
func (*ColorFlowAnimation) BuildNormal ¶
func (c *ColorFlowAnimation) BuildNormal(currentKeyFrame KeyFrame, _ StarterFunc)
BuildNormal builds animation in normal, not-triggered state.
func (*ColorFlowAnimation) KeyFramesCount ¶
func (c *ColorFlowAnimation) KeyFramesCount() int
KeyFramesCount implements Animation.
type EasingAlgorithm ¶
type EasingAlgorithmType ¶
type EasingAlgorithmType byte
EasingAlgorithmType represents animation type of easing algorithm used for animation. Refer https://easings.net/
const ( EasingAlgNone EasingAlgorithmType = iota EasingAlgInSine EasingAlgOutSine EasingAlgInOutSine EasingAlgInBack EasingAlgOutBack EasingAlgInOutBack EasingAlgInElastic EasingAlgOutElastic EasingAlgInOutElastic EasingAlgInBounce EasingAlgOutBounce EasingAlgInOutBounce EasingAlgMax )
type KeyFrame ¶
type KeyFrame byte
KeyFrame represents the most important states of an animation. Each animation declares an algorithm of calculating states between its KeyFrames.
type MoveAnimation ¶
type MoveAnimation struct {
// contains filtered or unexported fields
}
MoveAnimation moves animation widget from start position to destination. You can also specify animation Bézier curve's points.
func Move ¶
func Move(w func(starter StarterFunc) giu.Widget, steps ...*MoveStep) *MoveAnimation
Move creates new *MoveAnimations NOTE: You may want to take animation look on StartPos or DefaultStartPos methods to specify animation starting position. otherwise the first step specified will be treated as start position.
func (*MoveAnimation) BuildAnimation ¶
func (m *MoveAnimation) BuildAnimation( animationPercentage, _ float32, srcFrame, destFrame KeyFrame, mode PlayMode, starter StarterFunc, )
BuildAnimation implements Animation.
func (*MoveAnimation) BuildNormal ¶
func (m *MoveAnimation) BuildNormal(currentKF KeyFrame, starter StarterFunc)
BuildNormal implements Animation.
func (*MoveAnimation) DefaultStartPos ¶
func (m *MoveAnimation) DefaultStartPos() *MoveAnimation
DefaultStartPos will set animation default value of MoveStep as animation starting step. NOTE: You will lose possibility of setting up any additional properties of MoveStep (like bezier points).
func (*MoveAnimation) KeyFramesCount ¶
func (m *MoveAnimation) KeyFramesCount() int
KeyFramesCount implements Animation interface.
func (*MoveAnimation) StartPos ¶
func (m *MoveAnimation) StartPos(startPosStep func(startPos imgui.Vec2) *MoveStep) *MoveAnimation
StartPos allows to specify custom StartPos (item will be moved there immediately). argument function will receive cursor position returned by imgui.GetCursorPos while initializing animation.
type MoveStep ¶
type MoveStep struct {
// contains filtered or unexported fields
}
MoveStep represents animation single key frame in context of MoveAnimation. If Relative() not set, positionDelta is relative to this in animation previous step.
type StarterFunc ¶
type StarterFunc interface { Start(mode PlayMode) StartKeyFrames(beginKF, destinyKF KeyFrame, cyclesCount int, mode PlayMode) StartCycle(cyclesCount int, mode PlayMode) }
StarterFunc contains animation reference to all Starters of AnimatorWidget
type TransitionAnimation ¶
type TransitionAnimation struct {
// contains filtered or unexported fields
}
TransitionAnimation is a smooth transition between two renderers. It may apply to Windows (giu.WindowWidget) as well as to particular widgets/layouts.
func Transition ¶
func Transition(renderers ...func(starter StarterFunc)) *TransitionAnimation
Transition creates a new TransitionAnimation.
func (*TransitionAnimation) BuildAnimation ¶
func (t *TransitionAnimation) BuildAnimation( percentage, _ float32, bf, df KeyFrame, _ PlayMode, starter StarterFunc, )
BuildAnimation implements Animation interface.
func (*TransitionAnimation) BuildNormal ¶
func (t *TransitionAnimation) BuildNormal(f KeyFrame, starter StarterFunc)
BuildNormal implements Animation interface.
func (*TransitionAnimation) Init ¶
func (t *TransitionAnimation) Init()
Init implements Animation interface.
func (*TransitionAnimation) KeyFramesCount ¶
func (t *TransitionAnimation) KeyFramesCount() int
KeyFramesCount implements Animation interface.
func (*TransitionAnimation) Reset ¶
func (t *TransitionAnimation) Reset()
Reset implements Animation interface.
type TriggerFunc ¶
type TriggerFunc func() bool
TriggerFunc is a function determining whether the animation should be auto-triggered. See also TriggerType.
type TriggerType ¶
type TriggerType byte
TriggerType represents a strategy of automated triggering of an animation.
const ( // TriggerNever is animation default value. // Animation will not be started automatically. TriggerNever TriggerType = iota // TriggerOnTrue will start animation whenever trigger becomes true. TriggerOnTrue // TriggerOnChange will trigger animation, when value of trigger's function // will change. TriggerOnChange )