Merge branch 'generic-listctrl-center-label'

Fix centering of item label in generic wxListCtrl

See #2340, #24292.
This commit is contained in:
Vadim Zeitlin 2024-02-09 18:36:53 +01:00
commit 82cb7d1074
3 changed files with 15 additions and 12 deletions

View file

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

View file

@ -650,6 +650,8 @@ void MyFrame::InitWithIconItems(bool withText, bool sameIcon)
wxString label;
if ( !(i % 5) )
label.Printf("Longer label %d", i);
else if ( !(i % 4) )
label.Printf("#%d", i);
else
label.Printf("Label %d", i);

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??") );
@ -533,19 +533,19 @@ void wxListLineData::SetPosition( int x, int y, int spacing )
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;
}
if ( item->HasText() )
{
if (m_gi->m_rectAll.width > spacing)
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
else
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
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 - 2;
m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 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;
m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height +
(EXTRA_HEIGHT/2) - m_gi->m_rectLabel.height;
m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - (EXTRA_WIDTH/2);
m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - (EXTRA_HEIGHT/2);
}
else // no text, highlight the icon
{