Fix horizontal alignment in icon view in generic wxListCtrl.
Ensure that all the items in the same column have the same width, so that their labels are centred. Closes #9227. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70066 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -453,6 +453,7 @@ All (GUI):
|
|||||||
- Added wxFilePickerCtrl::SetInitialDirectory().
|
- Added wxFilePickerCtrl::SetInitialDirectory().
|
||||||
- Added wxDataViewItemAttr::SetBackgroundColour() and implemented it in generic
|
- Added wxDataViewItemAttr::SetBackgroundColour() and implemented it in generic
|
||||||
wxDataViewCtrl (Andrew Xu).
|
wxDataViewCtrl (Andrew Xu).
|
||||||
|
- Fix item alignment in icon view in the generic wxListCtrl.
|
||||||
|
|
||||||
MSW:
|
MSW:
|
||||||
|
|
||||||
|
@@ -571,8 +571,14 @@ void MyFrame::InitWithIconItems(bool withText, bool sameIcon)
|
|||||||
|
|
||||||
if ( withText )
|
if ( withText )
|
||||||
{
|
{
|
||||||
m_listCtrl->InsertItem(i, wxString::Format(wxT("Label %d"), i),
|
// Make labels of different widths to test the layout.
|
||||||
image);
|
wxString label;
|
||||||
|
if ( !(i % 5) )
|
||||||
|
label.Printf("Longer label %d", i);
|
||||||
|
else
|
||||||
|
label.Printf("Label %d", i);
|
||||||
|
|
||||||
|
m_listCtrl->InsertItem(i, label, image);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -3629,6 +3629,9 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
|
|||||||
|
|
||||||
int x = EXTRA_BORDER_X;
|
int x = EXTRA_BORDER_X;
|
||||||
int y = EXTRA_BORDER_Y;
|
int y = EXTRA_BORDER_Y;
|
||||||
|
|
||||||
|
// Note that "row" here is vertical, i.e. what is called
|
||||||
|
// "column" in many other places in wxWidgets.
|
||||||
int maxWidthInThisRow = 0;
|
int maxWidthInThisRow = 0;
|
||||||
|
|
||||||
m_linesPerPage = 0;
|
m_linesPerPage = 0;
|
||||||
@@ -3650,8 +3653,20 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
|
|||||||
if (currentlyVisibleLines > m_linesPerPage)
|
if (currentlyVisibleLines > m_linesPerPage)
|
||||||
m_linesPerPage = currentlyVisibleLines;
|
m_linesPerPage = currentlyVisibleLines;
|
||||||
|
|
||||||
if ( y + sizeLine.y >= clientHeight )
|
// Have we reached the end of the row either because no
|
||||||
|
// more items would fit or because there are simply no more
|
||||||
|
// items?
|
||||||
|
if ( y + sizeLine.y >= clientHeight
|
||||||
|
|| i == count - 1)
|
||||||
{
|
{
|
||||||
|
// Adjust all items in this row to have the same
|
||||||
|
// width to ensure that they all align horizontally.
|
||||||
|
size_t firstRowLine = i - currentlyVisibleLines + 1;
|
||||||
|
for (size_t j = firstRowLine; j <= i; j++)
|
||||||
|
{
|
||||||
|
GetLine(j)->m_gi->ExtendWidth(maxWidthInThisRow);
|
||||||
|
}
|
||||||
|
|
||||||
currentlyVisibleLines = 0;
|
currentlyVisibleLines = 0;
|
||||||
y = EXTRA_BORDER_Y;
|
y = EXTRA_BORDER_Y;
|
||||||
maxWidthInThisRow += MARGIN_BETWEEN_ROWS;
|
maxWidthInThisRow += MARGIN_BETWEEN_ROWS;
|
||||||
@@ -3660,10 +3675,6 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
|
|||||||
maxWidthInThisRow = 0;
|
maxWidthInThisRow = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have reached the last item.
|
|
||||||
if ( i == count - 1 )
|
|
||||||
entireWidth += maxWidthInThisRow;
|
|
||||||
|
|
||||||
if ( (tries == 0) &&
|
if ( (tries == 0) &&
|
||||||
(entireWidth + SCROLL_UNIT_X > clientWidth) )
|
(entireWidth + SCROLL_UNIT_X > clientWidth) )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user