- // container visible, draw it:
- if ((y + m_PosY < view_y2) && (y + m_PosY + m_Height > view_y1))
+ int y1 = y + m_PosY;
+ int y2 = y + m_PosY + m_Height;
+
+ // If the container is visible, draw it.
+ // This calculation checks for:
+ // (1) the cell is wholly within the view, OR
+ // (2) the cell overlaps, above the view, OR
+ // (3) the cell overlaps, below the view, OR
+ // (4) the cell overlaps, above and below the view.
+ if ((y1 <= view_y2 && y1 >= view_y1) ||
+ (y2 <= view_y2 && y2 >= view_y1) ||
+ (y1 <= view_y2 && y1 >= view_y1) ||
+ (y1 <= view_y1 && y2 >= view_y2))
+
+ // Old calculation, which I believe is wrong (JACS).
+// if ((y + m_PosY < view_y2) && (y + m_PosY + m_Height > view_y1))