In order to use javafx.animation.AnimationTimer you have to subclass it and override its handle method. This is not an option if you want to use it directly from frege. So I implemented a 'builder' where you can just pass the function you want to be called on every frame:
data AnimationTimerBuilder = mutable native graphics.AnimationTimerBuilder where
native from graphics.AnimationTimerBuilder.from :: (Long -> IO ()) -> IO AnimationTimer
import javafx.animation.AnimationTimer;
import frege.prelude.PreludeBase;
import frege.runtime.Lambda;
public class AnimationTimerBuilder {
public static AnimationTimer from(Lambda handler) {
return new AnimationTimer() {
@Override
public void handle(long arg0) {
frege.runtime.Delayed.<java.lang.Void>forced(
PreludeBase.TST.performUnsafe(handler.apply(arg0).result().forced())
);
}
};
}
}
Now you can use it like this:
do animTimer <- AnimationTimerBuilder.from $ \time -> do
println "Hi"
println time
animTimer.start
If you could add something similar to your fx utils module, I could drop my version.
In order to use
javafx.animation.AnimationTimeryou have to subclass it and override its handle method. This is not an option if you want to use it directly from frege. So I implemented a 'builder' where you can just pass the function you want to be called on every frame:Now you can use it like this:
If you could add something similar to your fx utils module, I could drop my version.