Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
github.com/gucio321/giu-animations/v2
This is a module for giu providing an animation system.
@gucio321 Head Developer | @sirthunderek Logo Designer | @Garnn Editor |
For complete code, please check out examples
Please make sure that you're using the same version of giu as this project (technically, you need to use giu version that uses the same imgui-go version as yours)
At the moment, there are three implementations of animations:
giu.Widget
).Lets shortly discuss particular types of animations:
Lets look at the API:
func Transition(renderers ...func(starter func(mode PlayMode))) *TransitionAnimation {...}
renderers
are just key frames of trasition.
In each stage appropiate renderer is called.
The argument to the renderers is a pointer to Animator.Start (see later)
so that you can call it to play the animation.
func ColorFlow(
widget giu.Widget,
applying []giu.StyleColorID,
colors ...func() color.RGBA,
) *ColorFlowAnimation {...}
There is also a variant of the above method called ColorFlowStyle
, which does not need
colors list. These colors are obtained
by function like this:
func() color.RGBA {
return imgui.CurrentStyle().GetStyleColor(styleID)
}
func Move(w func(starter StarterFunc) giu.Widget, steps ...*MoveStep) *MoveAnimation {...}
This will move w
around the steps.
Lets take a closer look on steps now:
Step
or StepVec
methods.Absolute()
method of the MoveStep, its position becomes
absolute so that it does not rely on any previous step.Bezier
method and specify as many points as you wish.One more important thing to mention is the first step.
By default, position of the first step you specify will be treated
absolute, even though it wasn't set to be. To change this
there are two additional methods of MoveAnimation
.
StartPos
and takes one argument of the following type:
func(startPos imgui.Vec2) *MoveStep
. It is expected to return non-nil MoveStep.
startPos
argument is the position of drawing cursor at the moment of first call of
Animator
.DefaultStartPos
method. It takes no arguments and acts
like most users would like to use StartPos
- it returns Step(startPos)
.These are some additional ways of controlling the flow of animation:
const (
EasingAlgNone EasingAlgorithmType = iota
EasingAlgInSine
EasingAlgOutSine
EasingAlgInOutSine
EasingAlgInQuad
EasingAlgOutQuad
EasingAlgInOutQuad
EasingAlgInCubic
EasingAlgOutCubic
EasingAlgInOutCubic
EasingAlgInQuart
EasingAlgOutQuart
EasingAlgInOutQuart
EasingAlgInQuint
EasingAlgOutQuint
EasingAlgInOutQuint
EasingAlgInExpo
EasingAlgOutExpo
EasingAlgInOutExpo
EasingAlgInCirc
EasingAlgOutCirc
EasingAlgInOutCirc
EasingAlgInBack
EasingAlgOutBack
EasingAlgInOutBack
EasingAlgInElastic
EasingAlgOutElastic
EasingAlgInOutElastic
EasingAlgInBounce
EasingAlgOutBounce
EasingAlgInOutBounce
EasingAlgMax
)
for further reference, see https://easings.net
This interface holds a reference to the part of AnimatorWidget
responsible
for starting animations. At the moment, there are three functions
Start(PlayMode)
go to the next KeyFrame (forwards or backwards)StartCycle(numberOfCycles int, mode PlayMode)
- play animation numberOfCycles
times starting and ending on this frame.StartKF(base, destination KeyFrame, numberOfCycles int, mode PlayMode)
go from base
to destination
in mode
direction (frame by frame) making numberOfCycles
cyclesAfter constructing an animation, you need to create a special type of giu widget
called AnimatorWidget
.
You may want to store it in a temporary variable, but, as you'll see later, animator's api is designed so that you don't need to do so every time.
As an argument to Animator(...)
constuctor, you pass previously created animation.
Animator has some useful methods:
Duration
allows you to specify animation's duration (default is 0.25 s)FPS
sets Frames per second value for animation playback (default is 60)
NOTE it is not real application's FPS! It just describes how often
animation's status is updated.Start
- this method you can use to invoke animation play.IsRunning
returns true, if animation is being played right now.AnimatorWidget
has a special ID method that allows you to specify
your own giu-ID. This ID is used to store an internal animator's state
inside of giu context.
Using this method is extremely important if you want to avoid confusing panics
when using TransitionAnimation along with sub-animators inside that animation.
It may happen, that one animator receives the same ID as the previous one.
This may lead to unexpected behaviour or even panic! Its good practice to set
unique ID everywhere!
Animator provides a simple way of automated starting of animations.
You can do this by using Trigger
method. This method takes three arguments:
TriggerType
(TriggerNever, TriggerOnChange, TriggerOnTrue) tells Animator when
to start the animation.func() bool
(TIP you can use any of imgui
functions like imgui.IsItemHovered
)Key frames are specific frames of an animation, other frames get interpolated according to them. All other states between them are calculated on the go. Key frames system in this module is not very advanced, but it should suit needs of most users. For more information about implementation of this system in particular animation types, see above.
You can use this API to create your own animation.
To do soo, lets take a look at the Animation
interface.
type Animation interface {
Init()
Reset()
KeyFramesCount() int
BuildNormal(currentKeyFrame KeyFrame, starter func())
BuildAnimation(animationPercentage, animationPurePercentage float32, startKeyFrame, destinationKeyFrame KeyFrame, starter func())
}
This is a copy from animation.go, but I've removed comments for clarity
init is called once, during first call of Animator.Build you can put some initialization here.
Reset is called along with (*Animator).Start
Returns a number of key frames the animation implements. This number determines behaviour of Animator while calling Start*
is called when !(*Animator).IsRunning()
It takes a pointer to (*Animator).Start
as an argument
so you can easily start animation from there.
is called instead of BuildNormal when playing an animation.
Along with pointer to (*Animator).Start
, it also receives
current animation progress in percents (0 >= currentPercentage <= 1)
You can do some calculations there.
If you implement something interesting, find any bugs, or improvements and if you would be so kind to open a PR, your contribution is welcome!
For now, this system is used in one of The Greater Heptavirate's projects. But (as I'm an author of that system) I've decided to share it for public - feel free to use if you can find any use case.
This project is shared under (attached) MIT License.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.