Closed PSteinhaus closed 3 years ago
Having a second constructor that takes Box<dyn EasingFunction + Send + Sync>
makes sense since that's what the function is stored as internally.
I poked around the code a little and while creating a second constructor is easy (something like Keyframe::new_dynamic(value, time, box)
) I couldn't get the macro working while keeping the same semantics as before. I would still like if sequences could be created with the macro without having to create a Box explicitly.
If you already have something implemented create a PR and I'll merge it. I pushed a few small fixes so once that's done I'll bump the version to 1.0.4.
I couldn't get the macro working while keeping the same semantics as before. I would still like if sequences could be created with the macro without having to create a Box explicitly.
That's the nontrivial part for me as well, as I'm still very much a newbie when it comes to writing macros. I guess I'll just try it out.
In case I can't get it to work either, would you also accept a PR only adding Keyframe::new_dynamic(value, time, box)
as well?
In case I can't get it to work either, would you also accept a PR only adding
Keyframe::new_dynamic(value, time, box)
as well?
Sure, that seems like the easiest option. :)
I've finally come around to actually creating an animation example for ggez, showcasing frame-by-frame animation using keyframe.
During this effort I spent a bit of time working around the fact that both
Keyframe::new
and thekeyframes!
macro need to know the type ofEasingFunction
which they'll get fed at compile time, even though it'll just get saved as a Box internally anyway. Not being able to pass aBox<dyn EasingFunction>
led to massive amounts of code duplication relative to the size of the example.After a while I gave up, realising that the proper way to address this could just be adding another constructor taking a boxed
EasingFunction
directly. This would lead to code like this:being shortened to something like this:
This would be immensely helpful for me, as there's a second portion of code (even worse than the first one), where I need to make basically the same match, but with each case being a bit more complicated (though practically the, same apart from the easing function used).
I considered just starting a PR, but I thought I'd start this issue first to ask how you feel about it.