animator icon indicating copy to clipboard operation
animator copied to clipboard

[Feature] Abstract away object ownership for improved clarity/readability

Open sudara opened this issue 3 years ago • 0 comments

Just to make this a formal feature request:

I think it would be really sweet for clarity/readability if we added constructors that take ownership of incoming class objects. I'm usually playing with animations on the stack, so I'd love be able to "trust" the animator to just take some parameters and handle ownership on its own.

Right now, a simple fade out looks like so (with animator being a class member).

auto fadeOut = std::make_unique<friz::Parametric> (friz::Parametric::CurveType::kEaseInQuartic, 0.0f, 1.0f, 60);
auto animation = std::make_unique<friz::Animation<1>> (friz::Animation<1>::SourceList { std::move (fadeOut) }, 0);
animation->OnUpdate ([&] (int id, const friz::Animation<1>::ValueList& val) {
    this->setAlpha (val[0]);
});
animator.AddAnimation (std::move (animation));

If there was an owning constructor, it could look like this

auto fadeOut = friz::Parametric (friz::Parametric::CurveType::kEaseInQuartic, 0.0f, 1.0f, 60);
auto animation = friz::Animation<1>::SourceList { fadeOut }, 0);
animation->OnUpdate ([&] (int id, const auto& val) {
    this->setAlpha (val[0]);
});
animator.AddAnimation (animation);

Thinking of other ways to cut down on verbosity, especially for a single tween like a fade out.... It would be nice in these cases to abstract away SourceList and the template parameter.... maybe Animation could have a constructor that can take a Parametric and automatically wrap it in a friz::Animation<1>::SourceList?...

auto animation = friz::Animation({friz::Parametric::CurveType::kEaseInQuartic, 0.0f, 1.0f, 60}); // constructs an Animation<1>
animation->OnUpdate ([&] (int id, const auto& val) {
    this->setAlpha (val[0]);
});
animator.AddAnimation (animation);

In general I wonder if a SourceList can be abstracted away behind the scenes, maybe with variadic templates (yikes?) vs. needing the user to be aware of them? Or with maybe with an ability to call .add(anotherParametric) on an animation (tween) which then updates its internal state....Hmm...

Thanks for this great lib!

sudara avatar Jun 09 '22 14:06 sudara