Implement wxGridCellNumberRenderer::GetMaxBestSize()

This allows to make computing the best width of numeric columns an O(1)
operation instead of O(number-of-rows), which can make a huge difference
for big grids.
This commit is contained in:
Vadim Zeitlin
2020-06-13 16:31:33 +02:00
parent 96de24d1bb
commit d2a403408f
2 changed files with 46 additions and 1 deletions

View File

@@ -748,6 +748,34 @@ wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid,
return DoGetBestSize(attr, dc, GetString(grid, row, col));
}
wxSize wxGridCellNumberRenderer::GetMaxBestSize(wxGrid& WXUNUSED(grid),
wxGridCellAttr& attr,
wxDC& dc)
{
// In theory, it's possible that there is a value in min..max range which
// is longer than both min and max, e.g. we could conceivably have "88" be
// wider than both "87" and "91" with some fonts, but it seems something
// too exotic to worry about in practice.
wxSize size = DoGetBestSize(attr, dc, wxString::Format("%ld", m_minValue));
size.IncTo(DoGetBestSize(attr, dc, wxString::Format("%ld", m_maxValue)));
return size;
}
void wxGridCellNumberRenderer::SetParameters(const wxString& params)
{
if ( params.empty() )
return;
wxString maxStr;
const wxString minStr = params.BeforeFirst(',', &maxStr);
if ( !minStr.ToLong(&m_minValue) || !maxStr.ToLong(&m_maxValue) )
{
wxLogDebug("Invalid wxGridCellNumberRenderer parameters \"%s\"", params);
}
}
// ----------------------------------------------------------------------------
// wxGridCellFloatRenderer
// ----------------------------------------------------------------------------