Fix centering of item label in generic wxListCtrl

The item label was not centered if the icon is wider than the label.
This commit is contained in:
taler21 2024-02-08 08:44:20 +01:00
parent 36583f13e1
commit 82b5f85418
2 changed files with 13 additions and 12 deletions

View file

@ -190,10 +190,11 @@ public:
wxASSERT_MSG( m_rectAll.width <= w, wxASSERT_MSG( m_rectAll.width <= w,
wxT("width can only be increased") ); wxT("width can only be increased") );
int delta = (w - m_rectAll.width) / 2;
m_rectAll.width = w; m_rectAll.width = w;
m_rectLabel.x += (w - m_rectLabel.width) / 2; m_rectLabel.x += delta;
m_rectIcon.x += (w - m_rectIcon.width) / 2; m_rectIcon.x += delta;
m_rectHighlight.x += (w - m_rectHighlight.width) / 2; m_rectHighlight.x += delta;
} }
}; };

View file

@ -518,7 +518,7 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing )
} }
} }
void wxListLineData::SetPosition( int x, int y, int spacing ) void wxListLineData::SetPosition( int x, int y, int WXUNUSED(spacing) )
{ {
wxCHECK_RET( !m_items.empty(), wxT("no subitems at all??") ); wxCHECK_RET( !m_items.empty(), wxT("no subitems at all??") );
@ -533,19 +533,19 @@ void wxListLineData::SetPosition( int x, int y, int spacing )
if ( item->HasImage() ) if ( item->HasImage() )
{ {
m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4; m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 +
(m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2;
m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4; m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
} }
if ( item->HasText() ) if ( item->HasText() )
{ {
if (m_gi->m_rectAll.width > spacing) m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) +
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2); (m_gi->m_rectAll.width - m_gi->m_rectLabel.width) / 2;
else m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height +
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) + (spacing / 2) - (m_gi->m_rectLabel.width / 2); (EXTRA_HEIGHT/2) - m_gi->m_rectLabel.height;
m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height; m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - (EXTRA_WIDTH/2);
m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2; m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - (EXTRA_HEIGHT/2);
m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2;
} }
else // no text, highlight the icon else // no text, highlight the icon
{ {