connect :: (Alignment, Bounds) -> (Alignment, Element) -> Bounds
connect (parentAlign, parent) (childAlign, child) =
  Bounds x y (x + w) (y + h)
  where
    (x, y) = (xParent + xOff + xAlign, yParent + yOff + yAlign)
    (w, h) = elementSize child
    (xParent, yParent) = boundsAnchor parentAlign parent
    (xOff, yOff) = elemOffset child
    (xAlign, yAlign) =
      case childAlign of
        TL -> (0, 0)
        BL -> (0, -h)
        L  -> (0, -0.5 * h)
        TR -> (-w, 0)
        BR -> (-w, -h)
        R  -> (-w, -0.5 * h)
        T  -> (-0.5 * w, 0)
        B  -> (-0.5 * w, -h)
        C  -> (-0.5 * w, -0.5 * h)
connect :: (Alignment, Bounds) -> (Alignment, Element) -> Bounds
connect (parentAlign, parent) (childAlign, child) =
  Bounds x y (x + w) (y + h)
  where
    (x, y) = (xParent + xOff + xAlign, yParent + yOff + yAlign)
    (w, h) = elementSize child
    (xParent, yParent) = boundsAnchor parentAlign parent
    (xOff, yOff) = elemOffset child
    (xAlign, yAlign) =
      case childAlign of
        TL -> (0, 0)
        BL -> (0, -h)
        L  -> (0, -0.5 * h)
        TR -> (-w, 0)
        BR -> (-w, -h)
        R  -> (-w, -0.5 * h)
        T  -> (-0.5 * w, 0)
        B  -> (-0.5 * w, -h)
        C  -> (-0.5 * w, -0.5 * h)
connect (parentAlign, parent) (childAlign, child) =
  Bounds x y (x + w) (y + h)
  where
    (x, y) = (xParent + xOff + xAlign, yParent + yOff + yAlign)
    (w, h) = elementSize child
    (xParent, yParent) = boundsAnchor parentAlign parent
    (xOff, yOff) = elemOffset child
    (xAlign, yAlign) =
      case childAlign of
        TL -> (0, 0)
        BL -> (0, -h)
        L  -> (0, -0.5 * h)
        TR -> (-w, 0)
        BR -> (-w, -h)
        R  -> (-w, -0.5 * h)
        T  -> (-0.5 * w, 0)
        B  -> (-0.5 * w, -h)
        C  -> (-0.5 * w, -0.5 * h)