-- ^ This will send events to the first widget in the list that would
-- take them. It is useful especially for lifting views to widgets and
-- composing them with widgets.
makeFromWidgets :: [[Widget k]] -> Widget k
makeFromWidgets widgets =
  Widget {
    isFocused = any isFocused $ concat widgets,
    content =
      fmap combineEventHandlers .
      makeGeneric Widget.uioFrame .
      (map . map) content $ widgets
    }
  where
    combineEventHandlers (frame, userIOss) =
      Widget.UserIO {
        Widget.uioFrame = frame,
        Widget.uioMaybeEnter = mEnter,
        Widget.uioEventMap = eventMap
        }
      where
        eventMap = mconcat . map Widget.uioEventMap $ concat userIOss
        mEnter = msum . map Widget.uioMaybeEnter $ concat userIOss
makeFromWidgets :: [[Widget k]] -> Widget k
makeFromWidgets widgets =
  Widget {
    isFocused = any isFocused $ concat widgets,
    content =
      fmap combineEventHandlers .
      makeGeneric Widget.uioFrame .
      (map . map) content $ widgets
    }
  where
    combineEventHandlers (frame, userIOss) =
      Widget.UserIO {
        Widget.uioFrame = frame,
        Widget.uioMaybeEnter = mEnter,
        Widget.uioEventMap = eventMap
        }
      where
        eventMap = mconcat . map Widget.uioEventMap $ concat userIOss
        mEnter = msum . map Widget.uioMaybeEnter $ concat userIOss
makeFromWidgets widgets =
  Widget {
    isFocused = any isFocused $ concat widgets,
    content =
      fmap combineEventHandlers .
      makeGeneric Widget.uioFrame .
      (map . map) content $ widgets
    }
  where
    combineEventHandlers (frame, userIOss) =
      Widget.UserIO {
        Widget.uioFrame = frame,
        Widget.uioMaybeEnter = mEnter,
        Widget.uioEventMap = eventMap
        }
      where
        eventMap = mconcat . map Widget.uioEventMap $ concat userIOss
        mEnter = msum . map Widget.uioMaybeEnter $ concat userIOss