From 592575a2745233fcb865fe27768bdab54ce74bbd Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Thu, 18 Jul 2019 17:21:25 -0400 Subject: Animator: function to remove an animation. --- Animator.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Animator.hs b/Animator.hs index e51fc50..fb0e3f6 100644 --- a/Animator.hs +++ b/Animator.hs @@ -55,6 +55,15 @@ addAnimation tm action = do writeIORef (tmCallback tm) (Just cb) return k + +removeAnimation :: Animator -> Int -> IO () +removeAnimation tm k = do + m <- atomicModifyIORef' (tmAnimations tm) $ \m -> (IntMap.delete k m, m) + when (IntMap.null $ IntMap.delete k m) $ do + mcb <- readIORef (tmCallback tm) + mapM_ (widgetRemoveTickCallback $ tmWidget tm) mcb + writeIORef (tmCallback tm) Nothing + tick :: Animator -> Widget -> FrameClock -> IO Bool tick tm widget clock = widgetGetWindow widget >>= \case Nothing -> do writeIORef (tmCallback tm) Nothing -- cgit v1.2.3