Ticket #3353: t3353_olist_cell_clipping_v1.patch

File t3353_olist_cell_clipping_v1.patch, 2.1 KB (added by elexis, 9 years ago)
  • source/gui/COList.cpp

     
    406406
    407407            DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
    408408            xpos += width;
    409409        }
    410410
     411        const unsigned int m_ObjectsCount = m_ObjectsDefs.size();
    411412        for (int i=0; i<(int)pList->m_Items.size(); ++i)
    412413        {
    413414            if (m_ItemsYPositions[i+1] - scroll < 0 ||
    414415                m_ItemsYPositions[i] - scroll > rect.GetHeight())
    415416                continue;
    416417
     418            const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i];
     419
    417420            // Clipping area (we'll have to substract the scrollbar)
    418421            CRect cliparea = GetListRect();
    419422
    420423            if (scrollbar)
    421424            {
     
    427430                    cliparea.left < GetScrollBar(0).GetOuterRect().right)
    428431                    cliparea.left = GetScrollBar(0).GetOuterRect().right;
    429432            }
    430433
    431434            xpos = 0;
    432             for (unsigned int def=0; def< m_ObjectsDefs.size(); ++def)
     435            for (unsigned int def=0; def < m_ObjectsCount; ++def)
    433436            {
    434                 DrawText(m_ObjectsDefs.size() * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]), bz+0.1f, cliparea);
     437                // Determine text position and width
     438                const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
     439
    435440                // Check if it's a decimal value, and if so, assume relative positioning.
     441                float width = m_ObjectsDefs[def].m_Width;;
    436442                if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
    437                     xpos += m_ObjectsDefs[def].m_Width * m_TotalAvalibleColumnWidth;
    438                 else
    439                     xpos += m_ObjectsDefs[def].m_Width;
     443                    width *= m_TotalAvalibleColumnWidth;
     444
     445                // Clip text to the column (to prevent drawing text into the neighboring column)
     446                CRect cliparea2 = cliparea;
     447                cliparea2.right = std::min(cliparea2.right, textPos.x + width);
     448                cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight);
     449
     450                DrawText(m_ObjectsCount * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);
     451                xpos += width;
    440452            }
    441453        }
    442454    }
    443455}