make config animId (Just (ActiveState pos movements)) setState w =
    w
    & Widget.animFrame %~ mappend frame
    & Widget.eventMap .~ eventMap
    where
        delta = sum $ map (^. mDir) movements
        highlight =
            maybe mempty
            (highlightRect (animId ++ ["highlight"]) . (^. Widget.enterResultRect))
            mEnteredChild
        frame = target config (animId ++ ["target"]) pos `mappend` highlight
        mEnteredChild = fmap ($ targetPos) $ w ^. Widget.mEnter
        targetPos = Direction.Point pos
        nextState =
            ActiveState
            (cap (pos + delta*speed) (w ^. Widget.size)) $
            movements & Lens.mapped . mDir *~ accel
        eventMap = mconcat $
            (mkTickHandler . setState . Just) nextState :
            addMovements pos movements setState :
            finishMove :
            [ stopMovement name mk lessMovements
            | (Movement name mk _, lessMovements) <- zipped movements
            ]
        finishMove = mconcat $ map finishOn $ finishKeys ++ map modKey modifierKeys
        stopMovement name mk newMovements =
            mkKeyMap GLFW.KeyState'Released mk (EventMap.Doc ["Navigation", "Stop FlyNav", name]) .
            setState . Just $ ActiveState pos newMovements
        finishOn mk =
            EventMap.keyEventMap (EventMap.KeyEvent GLFW.KeyState'Released mk)
                (EventMap.Doc ["Navigation", "Stop FlyNav"]) $
                setState Nothing *>
                -- TODO: Just cancel FlyNav in any case if the MaybeEnter is
                -- Nothing...
                maybe (pure mempty) (^. Widget.enterResultEvent)
                    mEnteredChild
make config animId (Just (ActiveState pos movements)) setState w =
    w
    & Widget.animFrame %~ mappend frame
    & Widget.eventMap .~ eventMap
    where
        delta = sum $ map (^. mDir) movements
        highlight =
            maybe mempty
            (highlightRect (animId ++ ["highlight"]) . (^. Widget.enterResultRect))
            mEnteredChild
        frame = target config (animId ++ ["target"]) pos `mappend` highlight
        mEnteredChild = fmap ($ targetPos) $ w ^. Widget.mEnter
        targetPos = Direction.Point pos
        nextState =
            ActiveState
            (cap (pos + delta*speed) (w ^. Widget.size)) $
            movements & Lens.mapped . mDir *~ accel
        eventMap = mconcat $
            (mkTickHandler . setState . Just) nextState :
            addMovements pos movements setState :
            finishMove :
            [ stopMovement name mk lessMovements
            | (Movement name mk _, lessMovements) <- zipped movements
            ]
        finishMove = mconcat $ map finishOn $ finishKeys ++ map modKey modifierKeys
        stopMovement name mk newMovements =
            mkKeyMap GLFW.KeyState'Released mk (EventMap.Doc ["Navigation", "Stop FlyNav", name]) .
            setState . Just $ ActiveState pos newMovements
        finishOn mk =
            EventMap.keyEventMap (EventMap.KeyEvent GLFW.KeyState'Released mk)
                (EventMap.Doc ["Navigation", "Stop FlyNav"]) $
                setState Nothing *>
                -- TODO: Just cancel FlyNav in any case if the MaybeEnter is
                -- Nothing...
                maybe (pure mempty) (^. Widget.enterResultEvent)
                    mEnteredChild
make config animId (Just (ActiveState pos movements)) setState w =
    w
    & Widget.animFrame %~ mappend frame
    & Widget.eventMap .~ eventMap
    where
        delta = sum $ map (^. mDir) movements
        highlight =
            maybe mempty
            (highlightRect (animId ++ ["highlight"]) . (^. Widget.enterResultRect))
            mEnteredChild
        frame = target config (animId ++ ["target"]) pos `mappend` highlight
        mEnteredChild = fmap ($ targetPos) $ w ^. Widget.mEnter
        targetPos = Direction.Point pos
        nextState =
            ActiveState
            (cap (pos + delta*speed) (w ^. Widget.size)) $
            movements & Lens.mapped . mDir *~ accel
        eventMap = mconcat $
            (mkTickHandler . setState . Just) nextState :
            addMovements pos movements setState :
            finishMove :
            [ stopMovement name mk lessMovements
            | (Movement name mk _, lessMovements) <- zipped movements
            ]
        finishMove = mconcat $ map finishOn $ finishKeys ++ map modKey modifierKeys
        stopMovement name mk newMovements =
            mkKeyMap GLFW.KeyState'Released mk (EventMap.Doc ["Navigation", "Stop FlyNav", name]) .
            setState . Just $ ActiveState pos newMovements
        finishOn mk =
            EventMap.keyEventMap (EventMap.KeyEvent GLFW.KeyState'Released mk)
                (EventMap.Doc ["Navigation", "Stop FlyNav"]) $
                setState Nothing *>
                -- TODO: Just cancel FlyNav in any case if the MaybeEnter is
                -- Nothing...
                maybe (pure mempty) (^. Widget.enterResultEvent)
                    mEnteredChild