Replies: 2 comments
|
You need to clone the output of |
0 replies
|
Thank you! In the mean time I dug up a two years old message on Discord and got it to work with Message::Frame(timestamp, duration) => {
self.svg.animate(&duration); // This is the actual work that needs to be done in the frame.
let callback = ctx.link().callback(identity);
let previous_timestamp = timestamp;
self.animation = Some(Box::from(request_animation_frame(move |timestamp| {
let duration = Duration::from_millis((timestamp - previous_timestamp) as u64);
let msg = Message::Frame(timestamp, duration);
callback.emit(msg);
})));
}Do you think it's right? If so, maybe I'll try to write an example. At least two people asked for an example of using RAF, and I never wrote one before, so it couldl be a nice new challenge :-) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi! Thank you for all your efforts around Gloo. It's very nice.
I'm heaving trouble figuring out how to use
gloo_render::request_animation_frameand would really appreciate a simple, yet practical example. Probably I'm just missing something basic, as I am quite inexperienced with Rust. An example could go a long way. Below are a few things I tried so far.The simplest approach, basically as I would do it in JS.
This compiles, but produces no output. My understanding is that as soon as the reference to an
AnimationFramegoes out of scope, the request is cancelled and thestepcallback never called. So the solution has to somehow keep the reference alive. With this in mind I tried the following (in context of a Yew app):I'm getting the following:
This example is Yew specific, so probably only good for demonstration. With a basic example, I hopefully be able to integrate it with my Yew code.
All reactions