Optimize calculating column widths
Use iterative algorithm instead of recursive one to adjust column widths.
This commit is contained in:
@@ -1010,33 +1010,12 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
|
|||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int lastColumn = m_colWidths.size() - 1;
|
unsigned int lastColumn = m_colWidths.size() - 1;
|
||||||
int width = m_width;
|
|
||||||
int clientWidth = pg->GetClientSize().x;
|
int clientWidth = pg->GetClientSize().x;
|
||||||
|
|
||||||
//
|
|
||||||
// Column to reduce, if needed. Take last one that exceeds minimum width.
|
|
||||||
int reduceCol = -1;
|
|
||||||
|
|
||||||
wxLogTrace("propgrid",
|
wxLogTrace("propgrid",
|
||||||
wxS("ColumnWidthCheck (virtualWidth: %i, clientWidth: %i)"),
|
wxS("ColumnWidthCheck (virtualWidth: %i, clientWidth: %i)"),
|
||||||
width, clientWidth);
|
m_width, clientWidth);
|
||||||
|
|
||||||
//
|
|
||||||
// Check min sizes
|
|
||||||
for ( i=0; i<m_colWidths.size(); i++ )
|
|
||||||
{
|
|
||||||
int min = GetColumnMinWidth(i);
|
|
||||||
if ( m_colWidths[i] <= min )
|
|
||||||
{
|
|
||||||
m_colWidths[i] = min;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Always reduce the last column that is larger than minimum size
|
|
||||||
// (looks nicer, even with auto-centering enabled).
|
|
||||||
reduceCol = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int colsWidth = pg->GetMarginWidth();
|
int colsWidth = pg->GetMarginWidth();
|
||||||
for ( i=0; i<m_colWidths.size(); i++ )
|
for ( i=0; i<m_colWidths.size(); i++ )
|
||||||
@@ -1049,31 +1028,37 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
|
|||||||
// Then mode-based requirement
|
// Then mode-based requirement
|
||||||
if ( !pg->HasVirtualWidth() )
|
if ( !pg->HasVirtualWidth() )
|
||||||
{
|
{
|
||||||
int widthHigher = width - colsWidth;
|
int widthHigher = m_width - colsWidth;
|
||||||
|
|
||||||
// Adapt colsWidth to width
|
// Adapt colsWidth to width
|
||||||
if ( colsWidth < width )
|
if ( colsWidth < m_width )
|
||||||
{
|
{
|
||||||
// Increase column
|
// Increase column
|
||||||
wxLogTrace("propgrid",
|
wxLogTrace("propgrid",
|
||||||
wxS(" Adjust last column to %i"),
|
wxS(" Adjust last column to %i"),
|
||||||
m_colWidths[lastColumn] + widthHigher);
|
m_colWidths[lastColumn] + widthHigher);
|
||||||
m_colWidths[lastColumn] = m_colWidths[lastColumn] + widthHigher;
|
m_colWidths[lastColumn] += widthHigher;
|
||||||
}
|
}
|
||||||
else if ( colsWidth > width )
|
else if ( colsWidth > m_width )
|
||||||
{
|
{
|
||||||
// Reduce column
|
widthHigher = -widthHigher;
|
||||||
if ( reduceCol != -1 )
|
// Always reduce the last column that is larger than minimum size
|
||||||
|
// (looks nicer, even with auto-centering enabled).
|
||||||
|
for (int reduceCol = (int)lastColumn; reduceCol >= 0 && widthHigher > 0; reduceCol--)
|
||||||
{
|
{
|
||||||
wxLogTrace("propgrid",
|
// Reduce column, if possible.
|
||||||
wxS(" Reduce column %i (by %i)"),
|
if ( m_colWidths[reduceCol] > GetColumnMinWidth(reduceCol) )
|
||||||
reduceCol, -widthHigher);
|
{
|
||||||
|
int d = wxMin(m_colWidths[reduceCol] - GetColumnMinWidth(reduceCol), widthHigher);
|
||||||
|
wxLogTrace("propgrid", wxS(" Reduce column %i (by %i)"), reduceCol, d);
|
||||||
|
|
||||||
// Reduce widest column, and recheck
|
m_colWidths[reduceCol] -= d;
|
||||||
m_colWidths[reduceCol] = m_colWidths[reduceCol] + widthHigher;
|
colsWidth -= d;
|
||||||
CheckColumnWidths();
|
widthHigher -= d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_width = colsWidth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user